#!/usr/bin/env python3
"""Reproduce statutory allocation arithmetic. No network, dependencies or estimated cash flows."""
from pathlib import Path
from decimal import Decimal
import csv,json
p=Path(__file__).parent
rows=list(csv.DictReader((p/'allocation-source-data.csv').open()))
assert len(rows)==2
for r in rows:
 assert Decimal(r['epf_percent'])+Decimal(r['eu_budget_percent'])==100
old,new=rows
out={'data_kind':'Enacted percentage allocation, not observed disbursements','observations':2,'epf_percentage_point_change':str(Decimal(new['epf_percent'])-Decimal(old['epf_percent'])),'eu_budget_percentage_point_change':str(Decimal(new['eu_budget_percent'])-Decimal(old['eu_budget_percent'])),'eu_budget_share_ratio':str(Decimal(new['eu_budget_percent'])/Decimal(old['eu_budget_percent'])),'epf_share_ratio':str(Decimal(new['epf_percent'])/Decimal(old['epf_percent'])),'denominator':'Financial contribution paid to the Union under the cited framework, not gross interest, immobilised principal, all CSD profit or loan principal','application':'Revised allocation applies from the second biannual payment in 2025 onward, per Decision 2024/2760 Article 2.'}
print(json.dumps(out,indent=2))
