1
0

2 Коммиты 8fa41d1e39 ... 28f7da681a

Автор SHA1 Сообщение Дата
  raylu 28f7da681a company: get one expertise per mat 6 дней назад
  raylu d8589f6cac company: group output by expertise 6 дней назад
1 измененных файлов с 35 добавлено и 9 удалено
  1. 35 9
      company.py

+ 35 - 9
company.py

@@ -18,20 +18,22 @@ def main() -> None:
 			print(planet['PlanetName'], cogc, sep='\t\t')
 			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', expiry=cache.ONE_DAY)
-	experts: dict[str, str] = {}
-	for building in buildings:
-		for recipe in building['Recipes']:
-			for output in recipe['Outputs']:
-				experts[output['CommodityTicker']] = building['Expertise']
 	print()
 	print()
 
 
+	experts = mat_expertise()
 	company_report = integration.pmmg_monthly_report()[company['CompanyId']]
 	company_report = integration.pmmg_monthly_report()[company['CompanyId']]
+	report_by_expertise: dict[str | None, dict[str, int]] = collections.defaultdict(dict)
 	for mat, production in company_report.items():
 	for mat, production in company_report.items():
 		expertise = experts.get(mat)
 		expertise = experts.get(mat)
-		print(f'{mat:3} {production["amount"]:8,.0f} {expertise or '':19}',
-				', '.join(cogc_planets.get(expertise, []))) # pyright: ignore[reportArgumentType, reportCallIssue]
+		report_by_expertise[expertise][mat] = production['amount']
+
+	for expertise, sub_report in report_by_expertise.items():
+		print(expertise, end=' ')
+		if expertise is not None:
+			print(', '.join(cogc_planets.get(expertise, [])), end='')
+		print()
+		for mat, amount in sub_report.items():
+			print(f'\t{mat:3} {amount:9,.1f}')
 
 
 def iter_planet_cogc() -> typing.Iterator[tuple[Planet, Expertise | None]]:
 def iter_planet_cogc() -> typing.Iterator[tuple[Planet, Expertise | None]]:
 	all_planets: typing.Collection[Planet] = cache.get('https://universemap.taiyibureau.de/planet_data.json',
 	all_planets: typing.Collection[Planet] = cache.get('https://universemap.taiyibureau.de/planet_data.json',
@@ -45,6 +47,26 @@ def iter_planet_cogc() -> typing.Iterator[tuple[Planet, Expertise | None]]:
 				cogc = cogc.removeprefix('ADVERTISING_')
 				cogc = cogc.removeprefix('ADVERTISING_')
 		yield planet, typing.cast(Expertise | None, cogc)
 		yield planet, typing.cast(Expertise | None, cogc)
 
 
+def mat_expertise() -> dict[str, Expertise]:
+	expertise: dict[str, Expertise] = {
+		'AL': 'METALLURGY',
+		'DRF': 'ELECTRONICS',
+		'FE': 'METALLURGY',
+	}
+
+	materials: typing.Sequence[Material] = cache.get('https://rest.fnar.net/material/allmaterials', expiry=cache.ONE_DAY)
+	for material in materials:
+		if material['CategoryName'] in ('ores', 'minerals', 'liquids', 'gases'):
+			expertise[material['Ticker']] = 'RESOURCE_EXTRACTION'
+
+	buildings: typing.Sequence[Building] = cache.get('https://rest.fnar.net/building/allbuildings', expiry=cache.ONE_DAY)
+	for building in buildings:
+		for recipe in building['Recipes']:
+			for output in recipe['Outputs']:
+				expertise.setdefault(output['CommodityTicker'], building['Expertise'])
+
+	return expertise
+
 Expertise = typing.Literal['AGRICULTURE', 'CHEMISTRY', 'CONSTRUCTION', 'ELECTRONICS', 'FOOD_INDUSTRIES',
 Expertise = typing.Literal['AGRICULTURE', 'CHEMISTRY', 'CONSTRUCTION', 'ELECTRONICS', 'FOOD_INDUSTRIES',
 	'FUEL_REFINING', 'MANUFACTURING', 'METALLURGY', 'RESOURCE_EXTRACTION']
 	'FUEL_REFINING', 'MANUFACTURING', 'METALLURGY', 'RESOURCE_EXTRACTION']
 
 
@@ -76,5 +98,9 @@ class BuildingMat(typing.TypedDict):
 	CommodityTicker: str
 	CommodityTicker: str
 	Amount: int
 	Amount: int
 
 
+class Material(typing.TypedDict):
+	Ticker: str
+	CategoryName: str
+
 if __name__ == '__main__':
 if __name__ == '__main__':
 	main()
 	main()