|
@@ -1,7 +1,7 @@
|
|
|
from __future__ import annotations
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
import collections
|
|
import collections
|
|
|
-import concurrent.futures
|
|
|
|
|
|
|
+import datetime
|
|
|
import sys
|
|
import sys
|
|
|
import typing
|
|
import typing
|
|
|
|
|
|
|
@@ -11,26 +11,16 @@ import integration
|
|
|
def main() -> None:
|
|
def main() -> None:
|
|
|
code = sys.argv[1]
|
|
code = sys.argv[1]
|
|
|
company: Company = cache.get('https://rest.fnar.net/company/code/' + code)
|
|
company: Company = cache.get('https://rest.fnar.net/company/code/' + code)
|
|
|
|
|
+ planets = {cp['PlanetName'] for cp in company['Planets']}
|
|
|
|
|
|
|
|
cogc_planets: dict[str, list[str]] = collections.defaultdict(list)
|
|
cogc_planets: dict[str, list[str]] = collections.defaultdict(list)
|
|
|
- with concurrent.futures.ThreadPoolExecutor(max_workers=4) as executor:
|
|
|
|
|
- futures: list[concurrent.futures.Future[Planet]] = [
|
|
|
|
|
- executor.submit(cache.get, 'https://rest.fnar.net/planet/' + planet['PlanetNaturalId'])
|
|
|
|
|
- for planet in company['Planets']]
|
|
|
|
|
- for future in futures:
|
|
|
|
|
- planet = future.result()
|
|
|
|
|
- cogc = None
|
|
|
|
|
- cogcs = planet['COGCPrograms']
|
|
|
|
|
- if len(cogcs) > 1:
|
|
|
|
|
- cogcs.sort(key=lambda c: c['StartEpochMs'], reverse=True)
|
|
|
|
|
- cogc = cogcs[1]['ProgramType']
|
|
|
|
|
- if cogc is not None:
|
|
|
|
|
- cogc = cogc.removeprefix('ADVERTISING_')
|
|
|
|
|
- print(planet['PlanetName'], cogc)
|
|
|
|
|
|
|
+ for planet, cogc in iter_planet_cogc():
|
|
|
|
|
+ if planet['PlanetName'] in planets:
|
|
|
|
|
+ print(planet['PlanetName'], cogc, sep='\t\t')
|
|
|
if cogc is not None:
|
|
if cogc is not None:
|
|
|
cogc_planets[cogc].append(planet['PlanetName'])
|
|
cogc_planets[cogc].append(planet['PlanetName'])
|
|
|
|
|
|
|
|
- buildings: typing.Sequence[Building] = cache.get('https://rest.fnar.net/building/allbuildings')
|
|
|
|
|
|
|
+ buildings: typing.Sequence[Building] = cache.get('https://rest.fnar.net/building/allbuildings', expiry=cache.ONE_DAY)
|
|
|
experts: dict[str, str] = {}
|
|
experts: dict[str, str] = {}
|
|
|
for building in buildings:
|
|
for building in buildings:
|
|
|
for recipe in building['Recipes']:
|
|
for recipe in building['Recipes']:
|
|
@@ -39,9 +29,25 @@ def main() -> None:
|
|
|
print()
|
|
print()
|
|
|
|
|
|
|
|
company_report = integration.pmmg_monthly_report()[company['CompanyId']]
|
|
company_report = integration.pmmg_monthly_report()[company['CompanyId']]
|
|
|
- for mat in company_report.keys():
|
|
|
|
|
|
|
+ for mat, production in company_report.items():
|
|
|
expertise = experts.get(mat)
|
|
expertise = experts.get(mat)
|
|
|
- print(mat, expertise, ', '.join(cogc_planets.get(expertise, []))) # pyright: ignore[reportArgumentType, reportCallIssue]
|
|
|
|
|
|
|
+ print(f'{mat:3} {production["amount"]:8,.0f} {expertise or '':19}',
|
|
|
|
|
+ ', '.join(cogc_planets.get(expertise, []))) # pyright: ignore[reportArgumentType, reportCallIssue]
|
|
|
|
|
+
|
|
|
|
|
+def iter_planet_cogc() -> typing.Iterator[tuple[Planet, Expertise | None]]:
|
|
|
|
|
+ all_planets: typing.Collection[Planet] = cache.get('https://universemap.taiyibureau.de/planet_data.json',
|
|
|
|
|
+ expiry=cache.ONE_DAY)
|
|
|
|
|
+ for planet in all_planets:
|
|
|
|
|
+ cogc = None
|
|
|
|
|
+ if len(cogcs := planet['COGCPrograms']) > 1:
|
|
|
|
|
+ cogcs.sort(key=lambda c: c['StartEpochMs'], reverse=True)
|
|
|
|
|
+ cogc = cogcs[1]['ProgramType']
|
|
|
|
|
+ if cogc is not None:
|
|
|
|
|
+ cogc = cogc.removeprefix('ADVERTISING_')
|
|
|
|
|
+ yield planet, typing.cast(Expertise | None, cogc)
|
|
|
|
|
+
|
|
|
|
|
+Expertise = typing.Literal['AGRICULTURE', 'CHEMISTRY', 'CONSTRUCTION', 'ELECTRONICS', 'FOOD_INDUSTRIES',
|
|
|
|
|
+ 'FUEL_REFINING', 'MANUFACTURING', 'METALLURGY', 'RESOURCE_EXTRACTION']
|
|
|
|
|
|
|
|
class Company(typing.TypedDict):
|
|
class Company(typing.TypedDict):
|
|
|
CompanyId: str
|
|
CompanyId: str
|
|
@@ -49,6 +55,7 @@ class Company(typing.TypedDict):
|
|
|
|
|
|
|
|
class CompanyPlanet(typing.TypedDict):
|
|
class CompanyPlanet(typing.TypedDict):
|
|
|
PlanetNaturalId: str
|
|
PlanetNaturalId: str
|
|
|
|
|
+ PlanetName: str
|
|
|
|
|
|
|
|
class Planet(typing.TypedDict):
|
|
class Planet(typing.TypedDict):
|
|
|
PlanetId: str
|
|
PlanetId: str
|