Răsfoiți Sursa

supply: redo ignore_materials

ignore_materials is now per-planet

ignore_materials are only not purchased in the first XIT ACT
they will be unloaded in the unload XIT ACTs
raylu 2 zile în urmă
părinte
comite
cb1c042e2f
3 a modificat fișierele cu 34 adăugiri și 24 ștergeri
  1. 22 16
      config.py
  2. 1 1
      readme.md
  3. 11 7
      supply.py

+ 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()

+ 1 - 1
readme.md

@@ -10,7 +10,7 @@ fio_api_key = 'uuid_here'
 [market]
 ignore_warehouses = ['HRT']
 
-[supply]
+[supply.promitor]
 ignore_materials = ['RAT']
 ```
 

+ 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]: