"""Reproduce the anchored findings from the extracted AMR data bundle.""" from pathlib import Path from decimal import Decimal as D import csv import json ROOT=Path(__file__).resolve().parent DATA=ROOT/'data' if (ROOT/'data').is_dir() else ROOT def rows(name): with (DATA/(name+'.csv')).open(newline='') as file: return list(csv.reader(file))[1:] def row(name, label): return next(r for r in rows(name) if r[0]==label) def pct(a,b): return f'{D(a)*100/D(b):.4f}' def main(): intermediate={r[0]:r for r in rows('aluminum-bauxite-and-alumina-by-country')} smelters={r[0]:r for r in rows('aluminum-world-smelting-and-capacity')} stages=rows('aluminum-stage-concentration') world='World total (rounded)' inputs=[(intermediate['China'][4],intermediate[world][4]),(intermediate['China'][2],intermediate[world][2]),(smelters['China'][2],smelters[world][2])] shares=[pct(a,b) for a,b in inputs] for record,(a,b),share in zip(stages,inputs,shares): assert record[5]==a and record[3]==b and record[6]==share assert shares==['19.7727','62.0000','60.8108'] current=row('aluminum-us-primary-and-recycling','2025 estimate') scrap=D(current[2])+D(current[3]) share=pct(current[2],current[5]) assert scrap==D(current[4])==3600 and share==current[8]=='28.0702' records=rows('aluminum-us-stage-import-origins') tops={stage:max((x for x in records if x[0]==stage),key=lambda x:int(x[2]))[1:] for stage in ('Bauxite','Alumina','Aluminum')} assert tops=={'Bauxite':['Jamaica','60'],'Alumina':['Brazil','71'],'Aluminum':['Canada','56']} print(json.dumps({'China_2025_stage_shares_percent':dict(zip(('bauxite','alumina','primary_aluminum'),shares)), '2025_US_recovered_scrap_kt':str(scrap),'2025_US_old_scrap_to_apparent_use_percent':share,'US_pooled_origins':tops})) if __name__=='__main__': main()