|
|
@@ -12,18 +12,25 @@ def main() -> None:
|
|
|
|
|
|
inventory = {item['MaterialTicker']: item['MaterialAmount'] for item in burn['Inventory']}
|
|
|
materials = {mat['Ticker']: mat for mat in raw_materials}
|
|
|
- producing = frozenset(item['MaterialTicker'] for item in burn['OrderProduction'])
|
|
|
- consumables = [c for c in burn['OrderConsumption'] + burn['WorkforceConsumption']
|
|
|
- if c['MaterialTicker'] not in producing]
|
|
|
+ producing = {item['MaterialTicker']: item for item in burn['OrderProduction']}
|
|
|
+ net_consumption = []
|
|
|
+ for c in burn['OrderConsumption'] + burn['WorkforceConsumption']:
|
|
|
+ net = c['DailyAmount']
|
|
|
+ if production := producing.get(c['MaterialTicker']):
|
|
|
+ net -= production['DailyAmount']
|
|
|
+ if net < 0:
|
|
|
+ continue
|
|
|
+ c['net_consumption'] = net
|
|
|
+ net_consumption.append(c)
|
|
|
|
|
|
vol_per_day = 0.0
|
|
|
weight_per_day = 0.0
|
|
|
target_days = float('inf')
|
|
|
- for consumption in consumables:
|
|
|
+ for consumption in net_consumption:
|
|
|
ticker = consumption['MaterialTicker']
|
|
|
- vol_per_day += materials[ticker]['Volume'] * consumption['DailyAmount']
|
|
|
- weight_per_day += materials[ticker]['Weight'] * consumption['DailyAmount']
|
|
|
- days = inventory.get(ticker, 0) / consumption['DailyAmount']
|
|
|
+ vol_per_day += materials[ticker]['Volume'] * consumption['net_consumption']
|
|
|
+ weight_per_day += materials[ticker]['Weight'] * consumption['net_consumption']
|
|
|
+ days = inventory.get(ticker, 0) / consumption['net_consumption']
|
|
|
if days < target_days:
|
|
|
target_days = days
|
|
|
|
|
|
@@ -37,10 +44,10 @@ def main() -> None:
|
|
|
while True:
|
|
|
space_used = 0
|
|
|
buy: dict[str, float] = {}
|
|
|
- for consumption in consumables:
|
|
|
+ for consumption in net_consumption:
|
|
|
ticker = consumption['MaterialTicker']
|
|
|
avail = inventory.get(ticker, 0)
|
|
|
- daily_consumption = consumption['DailyAmount']
|
|
|
+ daily_consumption = consumption['net_consumption']
|
|
|
days = avail / daily_consumption
|
|
|
if days < target_days:
|
|
|
buy[ticker] = (target_days - days) * daily_consumption
|
|
|
@@ -52,10 +59,10 @@ def main() -> None:
|
|
|
target_days += 0.1
|
|
|
print('supply for', round(target_days, 1), 'days')
|
|
|
|
|
|
- for consumption in consumables:
|
|
|
+ for consumption in net_consumption:
|
|
|
ticker = consumption['MaterialTicker']
|
|
|
avail = inventory.get(ticker, 0)
|
|
|
- daily_consumption = consumption['DailyAmount']
|
|
|
+ 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='')
|
|
|
if need := optimal.get(ticker): # pyright: ignore[reportPossiblyUnboundVariable]
|
|
|
@@ -91,6 +98,7 @@ class PlanetData(typing.TypedDict):
|
|
|
class Amount(typing.TypedDict):
|
|
|
MaterialTicker: str
|
|
|
DailyAmount: float
|
|
|
+ net_consumption: float
|
|
|
|
|
|
class Inventory(typing.TypedDict):
|
|
|
MaterialTicker: str
|