integration.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. from __future__ import annotations
  2. import sys
  3. import typing
  4. import cache
  5. def main() -> None:
  6. mat = sys.argv[1]
  7. recipes: list[Recipe] = cache.get('https://api.prunplanner.org/data/recipes')
  8. companies: dict[str, dict[str, CompanyOutput]] = cache.get(
  9. 'https://pmmg-products.github.io/reports/data/company-data-oct25.json')['individual']
  10. print(mat, '→')
  11. wrought = (recipe for recipe in recipes if mat in (i['Ticker'] for i in recipe['Inputs']))
  12. output_mats = {}
  13. for recipe in wrought:
  14. if len(recipe['Outputs']) != 1:
  15. continue
  16. (output,) = recipe['Outputs']
  17. (input,) = (i for i in recipe['Inputs'] if i['Ticker'] == mat)
  18. ratio = input['Amount'] / output['Amount']
  19. output_mats[output['Ticker']] = ratio
  20. print(f'\t{output["Ticker"]}:', ratio)
  21. companies_produced = companies_consumed = companies_consumed_80 = 0
  22. into = dict.fromkeys(output_mats.keys(), 0)
  23. for company in companies.values():
  24. if (co_production := company.get(mat)) is None:
  25. continue
  26. companies_produced += 1
  27. consumed = 0
  28. for output_mat, per_run_consumption in output_mats.items():
  29. if co_consumption := company.get(output_mat):
  30. total_consumption = co_consumption['amount'] * per_run_consumption
  31. consumed += total_consumption
  32. into[output_mat] += total_consumption
  33. if consumed > 0:
  34. companies_consumed += 1
  35. if consumed > 0.8 * co_production['amount']:
  36. companies_consumed_80 += 1
  37. print(f'{companies_produced} companies producing')
  38. print(f'{companies_consumed} companies consuming their own production')
  39. print(f'{companies_consumed_80} companies consuming 80%+ of their own production')
  40. for output_mat, total in into.items():
  41. print(f'{output_mat}:', total)
  42. class CompanyOutput(typing.TypedDict):
  43. amount: int
  44. class Recipe(typing.TypedDict):
  45. RecipeName: str
  46. BuildingTicker: str
  47. Inputs: list[RecipeMat]
  48. Outputs: list[RecipeMat]
  49. TimeMs: int
  50. class RecipeMat(typing.TypedDict):
  51. Ticker: str
  52. Amount: int
  53. if __name__ == '__main__':
  54. main()