|
@@ -1,37 +1,48 @@
|
|
|
from __future__ import annotations
|
|
from __future__ import annotations
|
|
|
import collections
|
|
import collections
|
|
|
import dataclasses
|
|
import dataclasses
|
|
|
-import sys
|
|
|
|
|
import typing
|
|
import typing
|
|
|
|
|
|
|
|
import httpx
|
|
import httpx
|
|
|
|
|
+import tap
|
|
|
|
|
|
|
|
from config import config
|
|
from config import config
|
|
|
|
|
|
|
|
|
|
+class Args(tap.Tap):
|
|
|
|
|
+ planet: str | None = None
|
|
|
|
|
+ usernames: tuple[str, ...] = ()
|
|
|
|
|
+
|
|
|
def main():
|
|
def main():
|
|
|
- (username,) = sys.argv[1:]
|
|
|
|
|
- prod = httpx.get('https://api.punoted.net/v1/production/user?username=' + username,
|
|
|
|
|
|
|
+ args = Args().parse_args()
|
|
|
|
|
+ params = {}
|
|
|
|
|
+ if args.usernames:
|
|
|
|
|
+ params['usernames'] = ','.join(args.usernames)
|
|
|
|
|
+ elif args.planet:
|
|
|
|
|
+ params['location'] = args.planet
|
|
|
|
|
+ users: typing.Sequence[ProductionUser] = httpx.get('https://api.punoted.net/v1/production/', params=params,
|
|
|
headers={'X-Data-Token': config.punoted_api_key}).raise_for_status().json()
|
|
headers={'X-Data-Token': config.punoted_api_key}).raise_for_status().json()
|
|
|
ms_in_day = 24 * 60 * 60 * 1000
|
|
ms_in_day = 24 * 60 * 60 * 1000
|
|
|
- for line in prod:
|
|
|
|
|
- print(line['PlanetName'], f'{line["Capacity"]}×{line["Type"]}', line['Efficiency'], line['Condition'])
|
|
|
|
|
- production: dict[str, Production] = {}
|
|
|
|
|
- for order in line['Orders']:
|
|
|
|
|
- if order['CompletedPercentage'] is not None:
|
|
|
|
|
- continue
|
|
|
|
|
- for output in order['Outputs']:
|
|
|
|
|
- production[output['ProductionLineOutputId']] = Production(
|
|
|
|
|
- ticker=output['MaterialTicker'],
|
|
|
|
|
- amount=output['MaterialAmount'],
|
|
|
|
|
- duration_ms=order['DurationMs']
|
|
|
|
|
- )
|
|
|
|
|
- line_queued_time = sum(p.duration_ms for p in production.values())
|
|
|
|
|
- line_outputs: dict[str, float] = collections.defaultdict(float)
|
|
|
|
|
- for p in production.values():
|
|
|
|
|
- amount = p.amount * ms_in_day / line_queued_time * line['Capacity']
|
|
|
|
|
- line_outputs[p.ticker] += amount
|
|
|
|
|
- for ticker, amount in line_outputs.items():
|
|
|
|
|
- print(f'\t{amount}×{ticker}')
|
|
|
|
|
|
|
+ for user in users:
|
|
|
|
|
+ print(user['Username'])
|
|
|
|
|
+ for line in user['Production']:
|
|
|
|
|
+ print(' ' + line['PlanetName'], f'{line["Capacity"]}×{line["Type"]}', line['Efficiency'], line['Condition'])
|
|
|
|
|
+ production: dict[str, Production] = {}
|
|
|
|
|
+ for order in line['Orders']:
|
|
|
|
|
+ if order['CompletedPercentage'] is not None:
|
|
|
|
|
+ continue
|
|
|
|
|
+ for output in order['Outputs']:
|
|
|
|
|
+ production[output['ProductionLineOutputId']] = Production(
|
|
|
|
|
+ ticker=output['MaterialTicker'],
|
|
|
|
|
+ amount=output['MaterialAmount'],
|
|
|
|
|
+ duration_ms=order['DurationMs']
|
|
|
|
|
+ )
|
|
|
|
|
+ line_queued_time = sum(p.duration_ms for p in production.values())
|
|
|
|
|
+ line_outputs: dict[str, float] = collections.defaultdict(float)
|
|
|
|
|
+ for p in production.values():
|
|
|
|
|
+ amount = p.amount * ms_in_day / line_queued_time * line['Capacity']
|
|
|
|
|
+ line_outputs[p.ticker] += amount
|
|
|
|
|
+ for ticker, amount in line_outputs.items():
|
|
|
|
|
+ print(f' {amount}×{ticker}')
|
|
|
|
|
|
|
|
@dataclasses.dataclass
|
|
@dataclasses.dataclass
|
|
|
class Production:
|
|
class Production:
|
|
@@ -39,6 +50,10 @@ class Production:
|
|
|
amount: float
|
|
amount: float
|
|
|
duration_ms: int
|
|
duration_ms: int
|
|
|
|
|
|
|
|
|
|
+class ProductionUser(typing.TypedDict):
|
|
|
|
|
+ Username: str
|
|
|
|
|
+ Production: typing.Sequence[ProductionLine]
|
|
|
|
|
+
|
|
|
class ProductionLine(typing.TypedDict):
|
|
class ProductionLine(typing.TypedDict):
|
|
|
PlanetName: str
|
|
PlanetName: str
|
|
|
Type: str
|
|
Type: str
|