Bläddra i källkod

company production info

raylu 1 månad sedan
förälder
incheckning
36004e1fe0
1 ändrade filer med 70 tillägg och 0 borttagningar
  1. 70 0
      company.py

+ 70 - 0
company.py

@@ -0,0 +1,70 @@
+from __future__ import annotations
+
+import collections
+import concurrent.futures
+import sys
+import typing
+
+import cache
+import integration
+import roi
+
+def main() -> None:
+	code = sys.argv[1]
+	company: Company = cache.get('https://rest.fnar.net/company/code/' + code)
+
+	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)
+			if cogc is not None:
+				cogc_planets[cogc].append(planet['PlanetName'])
+
+	buildings: typing.Sequence[Building] = cache.get('https://rest.fnar.net/building/allbuildings')
+	experts: dict[str, str] = {}
+	for building in buildings:
+		for recipe in building['Recipes']:
+			for output in recipe['Outputs']:
+				experts[output['CommodityTicker']] = building['Expertise']
+	print()
+
+	company_report = integration.pmmg_monthly_report()[company['CompanyId']]
+	for mat, data in company_report.items():
+		expertise = experts.get(mat)
+		print(mat, expertise, ', '.join(cogc_planets.get(expertise, []))) # pyright: ignore[reportArgumentType, reportCallIssue]
+
+class Company(typing.TypedDict):
+	CompanyId: str
+	Planets: typing.Sequence[CompanyPlanet]
+
+class CompanyPlanet(typing.TypedDict):
+	PlanetNaturalId: str
+
+class Planet(typing.TypedDict):
+	COGCPrograms: list[PlanetCOGC]
+	PlanetName: str
+
+class PlanetCOGC(typing.TypedDict):
+	ProgramType: str | None
+	StartEpochMs: float
+
+class Building(typing.TypedDict):
+	Recipes: typing.Sequence[BuildingRecipe]
+	Expertise: str
+
+class BuildingRecipe(typing.TypedDict):
+	Outputs: typing.Sequence[roi.BuildingMat]
+
+if __name__ == '__main__':
+	main()