raylu 1 month ago
parent
commit
887fb6421b
2 changed files with 60 additions and 0 deletions
  1. 54 0
      py/gateways.py
  2. 6 0
      pyproject.toml

+ 54 - 0
py/gateways.py

@@ -0,0 +1,54 @@
+from __future__ import annotations
+
+import collections
+import json
+import typing
+
+def main() -> None:
+	gateway_mats = [
+		'GWS', 'SST', 'PFG', 'SDM', 'TOR', 'TRS',
+		'VOE', 'VOR', 'HAM', 'BSU', 'CPU', 'VFT',
+		'SPT', 'ALR', 'WRH', 'PSH', 'TSH', 'RSH', 'LIT',
+	]
+	companies: dict[str, collections.Counter] = collections.defaultdict(collections.Counter)
+	mats: dict[str, collections.Counter] = collections.defaultdict(collections.Counter)
+	for company_data in iter_months():
+		for co_id, production in company_data.items():
+			for mat in gateway_mats:
+				if mat_prod := production.get(mat):
+					companies[co_id][mat] += mat_prod['amount']
+					mats[mat][co_id] += mat_prod['amount']
+
+	with open('www/data/knownCompanies.json', 'r') as f:
+		known_companies = json.load(f)
+
+	for co_id, produced in companies.items():
+		try:
+			print(known_companies[co_id]['Username'])
+		except KeyError:
+			print('unknown user', co_id)
+		for mat, amount in produced.items():
+			print(f'\t{mat:3}: {amount * 30:8,.1f}')
+
+	print()
+	for mat, produced in mats.items():
+		print(mat)
+		for co_id, amount in produced.most_common(10):
+			try:
+				username = known_companies[co_id]['Username']
+			except KeyError:
+				username = 'unknown user ' + co_id
+			print(f'\t{username:20}: {amount * 30:8,.1f}')
+
+def iter_months() -> typing.Iterator[dict[str, dict[str, dict[str, float]]]]:
+	for year in ['25', '26']:
+		for month in ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec']:
+			try:
+				with open(f'www/data/company-data-{month}{year}.json', 'r') as f:
+					print(month + year)
+					yield json.load(f)['individual']
+			except FileNotFoundError:
+				print(month + year, "doesn't exist")
+
+if __name__ == '__main__':
+	main()

+ 6 - 0
pyproject.toml

@@ -5,3 +5,9 @@ requires-python = '>=3.13'
 dependencies = [
     'httpx',
 ]
+
+[tool.ruff.lint]
+ignore = [
+	'I001', # unsorted-imports
+	'TRY002', # raise-vanilla-class
+]