company.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. from __future__ import annotations
  2. import collections
  3. import concurrent.futures
  4. import sys
  5. import typing
  6. import cache
  7. import integration
  8. import roi
  9. def main() -> None:
  10. code = sys.argv[1]
  11. company: Company = cache.get('https://rest.fnar.net/company/code/' + code)
  12. cogc_planets: dict[str, list[str]] = collections.defaultdict(list)
  13. with concurrent.futures.ThreadPoolExecutor(max_workers=4) as executor:
  14. futures: list[concurrent.futures.Future[Planet]] = [
  15. executor.submit(cache.get, 'https://rest.fnar.net/planet/' + planet['PlanetNaturalId'])
  16. for planet in company['Planets']]
  17. for future in futures:
  18. planet = future.result()
  19. cogc = None
  20. cogcs = planet['COGCPrograms']
  21. if len(cogcs) > 1:
  22. cogcs.sort(key=lambda c: c['StartEpochMs'], reverse=True)
  23. cogc = cogcs[1]['ProgramType']
  24. if cogc is not None:
  25. cogc = cogc.removeprefix('ADVERTISING_')
  26. print(planet['PlanetName'], cogc)
  27. if cogc is not None:
  28. cogc_planets[cogc].append(planet['PlanetName'])
  29. buildings: typing.Sequence[Building] = cache.get('https://rest.fnar.net/building/allbuildings')
  30. experts: dict[str, str] = {}
  31. for building in buildings:
  32. for recipe in building['Recipes']:
  33. for output in recipe['Outputs']:
  34. experts[output['CommodityTicker']] = building['Expertise']
  35. print()
  36. company_report = integration.pmmg_monthly_report()[company['CompanyId']]
  37. for mat, data in company_report.items():
  38. expertise = experts.get(mat)
  39. print(mat, expertise, ', '.join(cogc_planets.get(expertise, []))) # pyright: ignore[reportArgumentType, reportCallIssue]
  40. class Company(typing.TypedDict):
  41. CompanyId: str
  42. Planets: typing.Sequence[CompanyPlanet]
  43. class CompanyPlanet(typing.TypedDict):
  44. PlanetNaturalId: str
  45. class Planet(typing.TypedDict):
  46. COGCPrograms: list[PlanetCOGC]
  47. PlanetName: str
  48. class PlanetCOGC(typing.TypedDict):
  49. ProgramType: str | None
  50. StartEpochMs: float
  51. class Building(typing.TypedDict):
  52. Recipes: typing.Sequence[BuildingRecipe]
  53. Expertise: str
  54. class BuildingRecipe(typing.TypedDict):
  55. Outputs: typing.Sequence[roi.BuildingMat]
  56. if __name__ == '__main__':
  57. main()