|
|
@@ -45,11 +45,10 @@ def main() -> None:
|
|
|
target_days = float('inf')
|
|
|
for planet in planets:
|
|
|
vol_per_day = weight_per_day = 0
|
|
|
- for consumption in planet.net_consumption:
|
|
|
- ticker = consumption['MaterialTicker']
|
|
|
- vol_per_day += materials[ticker]['Volume'] * consumption['net_consumption']
|
|
|
- weight_per_day += materials[ticker]['Weight'] * consumption['net_consumption']
|
|
|
- days = planet.inventory.get(ticker, 0) / consumption['net_consumption']
|
|
|
+ for ticker, consumption in planet.net_consumption.items():
|
|
|
+ vol_per_day += materials[ticker]['Volume'] * consumption
|
|
|
+ weight_per_day += materials[ticker]['Weight'] * consumption
|
|
|
+ days = planet.inventory.get(ticker, 0) / consumption
|
|
|
if days < target_days:
|
|
|
target_days = days
|
|
|
|
|
|
@@ -90,12 +89,10 @@ def main() -> None:
|
|
|
print('\n' + cyan(planet.name))
|
|
|
supply_config = config.supply_config(planet.name)
|
|
|
planet_buy = optimal[planet.name]
|
|
|
- for consumption in planet.net_consumption:
|
|
|
- ticker = consumption['MaterialTicker']
|
|
|
+ for ticker, consumption in planet.net_consumption.items():
|
|
|
avail = planet.inventory.get(ticker, 0)
|
|
|
- daily_consumption = consumption['net_consumption']
|
|
|
- days = avail / daily_consumption
|
|
|
- print(f'{ticker:>3}: {avail:5d} ({daily_consumption:8.2f}/d) {days:4.1f} d', end='')
|
|
|
+ days = avail / consumption
|
|
|
+ print(f'{ticker:>3}: {avail:5d} ({consumption:8.2f}/d) {days:4.1f} d', end='')
|
|
|
if need := planet_buy.get(ticker): # pyright: ignore[reportOptionalMemberAccess]
|
|
|
if ticker in supply_config.ignore_materials:
|
|
|
print(f' | {need:5.0f} (ignored)')
|
|
|
@@ -189,11 +186,15 @@ class FIOBurn(typing.TypedDict):
|
|
|
Inventory: list[market.StorageItem]
|
|
|
OrderProduction: list[Amount]
|
|
|
|
|
|
+class Amount(typing.TypedDict):
|
|
|
+ MaterialTicker: str
|
|
|
+ DailyAmount: float
|
|
|
+
|
|
|
@dataclasses.dataclass(init=False, eq=False, slots=True)
|
|
|
class Planet:
|
|
|
name: str
|
|
|
inventory: dict[str, int]
|
|
|
- net_consumption: typing.Sequence[Amount]
|
|
|
+ net_consumption: dict[str, float]
|
|
|
exporting: typing.Set[str]
|
|
|
|
|
|
def __init__(self, fio_burn: FIOBurn) -> None:
|
|
|
@@ -201,40 +202,33 @@ class Planet:
|
|
|
self.inventory = {item['MaterialTicker']: item['MaterialAmount'] for item in fio_burn['Inventory']}
|
|
|
|
|
|
# producing any amount (including less than consumption)
|
|
|
- producing = {item['MaterialTicker']: item for item in fio_burn['OrderProduction']}
|
|
|
- self.net_consumption = []
|
|
|
+ self.net_consumption = {}
|
|
|
for c in fio_burn['OrderConsumption'] + fio_burn['WorkforceConsumption']:
|
|
|
- net = c['DailyAmount']
|
|
|
- if production := producing.get(c['MaterialTicker']):
|
|
|
- net -= production['DailyAmount']
|
|
|
- if net < 0:
|
|
|
- continue
|
|
|
- c['net_consumption'] = net
|
|
|
- self.net_consumption.append(c)
|
|
|
-
|
|
|
- consuming = {item['MaterialTicker'] for item in self.net_consumption}
|
|
|
+ ticker = c['MaterialTicker']
|
|
|
+ self.net_consumption[ticker] = self.net_consumption.get(ticker, 0) + c['DailyAmount']
|
|
|
+ for item in fio_burn['OrderProduction']:
|
|
|
+ if consumption := self.net_consumption.get(item['MaterialTicker']):
|
|
|
+ consumption -= item['DailyAmount']
|
|
|
+ if consumption <= 0:
|
|
|
+ del self.net_consumption[item['MaterialTicker']]
|
|
|
+ else:
|
|
|
+ self.net_consumption[item['MaterialTicker']] = consumption
|
|
|
+
|
|
|
# producing more than consumption
|
|
|
self.exporting = set()
|
|
|
for item in fio_burn['OrderProduction']:
|
|
|
- if item['MaterialTicker'] not in consuming:
|
|
|
+ if item['MaterialTicker'] not in self.net_consumption:
|
|
|
self.exporting.add(item['MaterialTicker'])
|
|
|
|
|
|
def supply_for_days(self, target_days: float) -> dict[str, int]:
|
|
|
buy: dict[str, int] = {}
|
|
|
- for consumption in self.net_consumption:
|
|
|
- ticker = consumption['MaterialTicker']
|
|
|
+ for ticker, consumption in self.net_consumption.items():
|
|
|
avail = self.inventory.get(ticker, 0)
|
|
|
- daily_consumption = consumption['net_consumption']
|
|
|
- days = avail / daily_consumption
|
|
|
+ days = avail / consumption
|
|
|
if days < target_days:
|
|
|
- buy[ticker] = math.ceil((target_days - days) * daily_consumption)
|
|
|
+ buy[ticker] = math.ceil((target_days - days) * consumption)
|
|
|
return buy
|
|
|
|
|
|
-class Amount(typing.TypedDict):
|
|
|
- MaterialTicker: str
|
|
|
- DailyAmount: float
|
|
|
- net_consumption: float
|
|
|
-
|
|
|
class Material(typing.TypedDict):
|
|
|
Ticker: str
|
|
|
Weight: float
|