Ver Fonte

mat_competitors

raylu há 1 semana atrás
pai
commit
967b582539
3 ficheiros alterados com 69 adições e 1 exclusões
  1. 2 1
      company.py
  2. 66 0
      mat_competitors.py
  3. 1 0
      planet_bases.py

+ 2 - 1
company.py

@@ -51,8 +51,9 @@ class CompanyPlanet(typing.TypedDict):
 	PlanetNaturalId: str
 
 class Planet(typing.TypedDict):
-	COGCPrograms: list[PlanetCOGC]
+	PlanetId: str
 	PlanetName: str
+	COGCPrograms: list[PlanetCOGC]
 
 class PlanetCOGC(typing.TypedDict):
 	ProgramType: str | None

+ 66 - 0
mat_competitors.py

@@ -0,0 +1,66 @@
+from __future__ import annotations
+
+import collections
+import json
+import sys
+import typing
+
+import cache
+import company
+import integration
+import planet_bases
+
+def main() -> None:
+	cx, ticker = sys.argv[1:]
+
+	(expertise,) = iter_expertise(ticker)
+
+	with open('www/closest.json') as f:
+		planet_ids = {planet_id for planet_id, closest_cx in json.load(f).items() if closest_cx == cx}
+
+	all_planets: typing.Collection[company.Planet] = cache.get('https://universemap.taiyibureau.de/planet_data.json')
+	planets = []
+	for planet in all_planets:
+		if planet['PlanetId'] not in planet_ids:
+			continue
+		if len(cogcs := planet['COGCPrograms']) > 1:
+			cogcs.sort(key=lambda c: c['StartEpochMs'], reverse=True)
+			cogc = cogcs[1]['ProgramType']
+			if cogc is not None and cogc.removeprefix('ADVERTISING_') == expertise:
+				planets.append(planet['PlanetName'])
+	print(len(planets), expertise, 'planets near', cx)
+
+	coid_code: dict[str, str] = {}
+	coid_bases = collections.defaultdict(list)
+	for planet in planets:
+		print('\t' + planet)
+		bases = planet_bases.get_bases(planet)
+		for base in bases:
+			if (code := base['OwnerCode']) is None:
+				continue
+			coid_code[base['OwnerId']] = code
+			coid_bases[base['OwnerId']].append(planet)
+
+	coid_users: dict[str, str] = {company_id: d['Username']
+		for company_id, d in cache.get('https://pmmg-products.github.io/reports/data/knownCompanies.json').items()}
+
+	for company_id, co_production in integration.pmmg_monthly_report().items():
+		if (mat_production := co_production.get(ticker)) is None:
+			continue
+		if bases := coid_bases.get(company_id):
+			code = coid_code[company_id]
+			username = coid_users[company_id]
+			print(f'{code}\t{username}')
+			print(f'{mat_production["amount"]:10.1f}', ', '.join(bases))
+
+def iter_expertise(ticker: str) -> typing.Iterator[str]:
+	buildings: typing.Sequence[company.Building] = cache.get('https://rest.fnar.net/building/allbuildings')
+	for building in buildings:
+		for recipe in building['Recipes']:
+			for output in recipe['Outputs']:
+				if output['CommodityTicker'] == ticker:
+					print(ticker, 'requires', building['Expertise'])
+					yield building['Expertise']
+
+if __name__ == '__main__':
+	main()

+ 1 - 0
planet_bases.py

@@ -78,6 +78,7 @@ class Planet(typing.TypedDict):
 	SystemId: str
 
 class Site(typing.TypedDict):
+	OwnerId: str
 	OwnerName: int
 	OwnerCode: str | None