| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- 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()
|