1
0

3 Коміти 5138ec0d4f ... efd06285ef

Автор SHA1 Опис Дата
  raylu efd06285ef roi webpage 4 днів тому
  raylu 819f6990ca supply: redo ignore_materials 3 днів тому
  raylu 5138ec0d4f roi webpage 4 днів тому
4 змінених файлів з 64 додано та 71 видалено
  1. 22 16
      config.py
  2. 11 7
      supply.py
  3. 16 16
      www/index.html
  4. 15 32
      www/style.css

+ 22 - 16
config.py

@@ -6,28 +6,34 @@ import typing
 
 @dataclasses.dataclass(eq=False, frozen=True, slots=True)
 class Config:
-    username: str
-    fio_api_key: str
-    market: MarketConfig
-    supply: SupplyConfig
+	username: str
+	fio_api_key: str
+	market: MarketConfig
+	supply: dict[str, SupplyConfig]
 
-    def __init__(self) -> None:
-        with open('config.toml', 'rb') as f:
-            config = tomllib.load(f)
-        for k, v in config.items():
-            match k:
-                case 'market':
-                    v = MarketConfig(**v)
-                case 'supply':
-                    v = SupplyConfig(**v)
-            object.__setattr__(self, k, v)
+	def __init__(self) -> None:
+		with open('config.toml', 'rb') as f:
+			config = tomllib.load(f)
+		for k, v in config.items():
+			match k:
+				case 'market':
+					v = MarketConfig(**v)
+				case 'supply':
+					v = {planet_name: SupplyConfig(**planet_config) for planet_name, planet_config in v.items()}
+			object.__setattr__(self, k, v)
+
+	def supply_config(self, planet_name: str) -> SupplyConfig:
+		if (planet_config := self.supply.get(planet_name.lower())) is not None:
+			return planet_config
+		else:
+			return SupplyConfig()
 
 @dataclasses.dataclass(eq=False, frozen=True, slots=True)
 class MarketConfig:
-    ignore_warehouses: typing.Sequence[str]
+	ignore_warehouses: typing.Sequence[str]
 
 @dataclasses.dataclass(eq=False, frozen=True, slots=True)
 class SupplyConfig:
-    ignore_materials: typing.Sequence[str]
+	ignore_materials: typing.Sequence[str] = dataclasses.field(default_factory=list)
 
 config = Config()

+ 11 - 7
supply.py

@@ -86,6 +86,7 @@ def main() -> None:
 	total_cost = 0
 	for planet in planets:
 		print('\n' + cyan(planet.name))
+		supply_config = config.supply_config(planet.name)
 		for consumption in planet.net_consumption:
 			ticker = consumption['MaterialTicker']
 			avail = planet.inventory.get(ticker, 0)
@@ -93,17 +94,22 @@ def main() -> None:
 			days = avail / daily_consumption
 			print(f'{ticker:>3}: {avail:5d} ({daily_consumption:8.2f}/d) {days:4.1f} d', end='')
 			if need := optimal[planet.name].get(ticker): # pyright: ignore[reportOptionalMemberAccess]
-				cost = raw_prices[ticker]['Ask'] * need
-				total_cost += cost
-				print(f' | {need:6.1f} (${cost:6.0f})')
+				if ticker in supply_config.ignore_materials:
+					print(f' | {need:5.0f} (ignored)')
+				else:
+					cost = raw_prices[ticker]['Ask'] * need
+					total_cost += cost
+					print(f' | {need:5.0f} (${cost:6.0f})')
 			else:
 				print()
 	print(f'\ntotal cost: {total_cost:,}')
 
 	combined_buy: dict[str, int] = collections.defaultdict(int)
-	for buy in optimal.values():
+	for planet_name, buy in optimal.items():
+		supply_config = config.supply_config(planet_name)
 		for ticker, amount in buy.items():
-			combined_buy[ticker] += amount
+			if ticker not in supply_config.ignore_materials:
+				combined_buy[ticker] += amount
 	print(cyan('\nbuy:\n') + json.dumps({
 		'actions': [
 			{'name': 'BuyItems', 'type': 'CX Buy', 'group': 'A1', 'exchange': 'IC1',
@@ -179,8 +185,6 @@ class Planet:
 				if net < 0:
 					continue
 			c['net_consumption'] = net
-			if c['MaterialTicker'] in config.supply.ignore_materials:
-				continue
 			self.net_consumption.append(c)
 
 	def buy_for_target(self, target_days: float) -> dict[str, int]:

+ 16 - 16
www/index.html

@@ -9,21 +9,21 @@
 	<meta name="theme-color" content="#222">
 </head>
 <body>
-    <main>
-        <table>
-            <thead>
-                <tr>
-                    <th>wrought product</th>
-                    <th>expertise</th>
-                    <th>daily profit/area</th>
-                    <th>capex</th>
-                    <th>daily opex</th>
-                    <th>logistics</th>
-                </tr>
-            </thead>
-            <tbody></tbody>
-        </table>
-    </main>
-    <script src="roi.js"></script>
+	<main>
+		<table>
+			<thead>
+				<tr>
+					<th>wrought product</th>
+					<th>expertise</th>
+					<th>daily profit/area</th>
+					<th>capex</th>
+					<th>daily opex</th>
+					<th>logistics</th>
+				</tr>
+			</thead>
+			<tbody></tbody>
+		</table>
+	</main>
+	<script src="roi.js"></script>
 </body>
 </html>

+ 15 - 32
www/style.css

@@ -30,37 +30,20 @@ main {
 	background-color: #111;
 	box-shadow: 0 0 5px #222;
 
-    table {
-        td, th {
-            padding: 0.25em 0.5em;
-        }
-        tbody {
-            td:nth-child(1),
-            td:nth-child(2) {
-                font-family: inherit;
-                text-align: inherit;
-            }
-            td {
-                font-family: monospace;
-                text-align: right;
-            }
-        }
-    }
-}
-
-@media (prefers-color-scheme: light) {
-	body {
-		background-color: #fff;
-		color: #555;
-	}
-	a:link, a:visited, a:active {
-		color: #358;
-	}
-	a:hover {
-		color: #38b;
-	}
-	main {
-		background-color: #eee;
-		box-shadow: 0 0 5px #ddd;
+	table {
+		td, th {
+			padding: 0.25em 0.5em;
+		}
+		tbody {
+			td:nth-child(1),
+			td:nth-child(2) {
+				font-family: inherit;
+				text-align: inherit;
+			}
+			td {
+				font-family: monospace;
+				text-align: right;
+			}
+		}
 	}
 }