"""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(): morocco=row('phosphate-reserve-versus-production-share','Morocco') world='World total (rounded)' assert morocco[1:3]==[row('phosphate-world-rock-output','Morocco')[2],row('phosphate-world-rock-output',world)[2]] assert morocco[4:6]==[row('phosphate-world-reserves','Morocco')[1],row('phosphate-world-reserves',world)[1]] mine,reserve=pct(morocco[1],morocco[2]),pct(morocco[4],morocco[5]) assert (mine,reserve)==(morocco[3],morocco[6])==('14.4000','68.4932') us=row('phosphate-us-rock-balance','2025 estimate') gross=pct(us[3],us[4]) assert us[6]=='16' and gross==us[8]=='16.1905' origins=rows('phosphate-us-rock-import-origins') origin=next(r[3] for r in origins if r[:3]==['2021','2024','Peru']) assert origin=='>99' d=row('phosphate-2025-2029-nutrient-projections','Fertilizer nutrient consumption') a,b=map(D,d[1:3]) inputs={r[0]:D(r[2]) for r in rows('phosphate-nutrient-use-and-capacity') if r[1]=='Fertilizer nutrient consumption'} assert (a,b)==(inputs['2025 estimate'],inputs['2029 projection']) assert b-a==D(d[3])==D('3.7') and pct(b-a,a)==d[4]=='7.7406' print(json.dumps({'Morocco_2025_mine_share_percent':mine,'Morocco_reserve_share_percent':reserve, '2025_US_stock_adjusted_reliance_percent':us[6],'2021_to_2024_Peru_share_of_US_imports_percent':origin, '2025_to_2029_projected_P2O5_increase_million_tons':str(b-a),'projected_growth_percent':d[4]})) if __name__=='__main__': main()