#!/usr/bin/env python3
"""Reproduce published arithmetic and cross-check separate final/provisional counts.
Download this file with data.json, named-conflicts.json, provisional-conflicts.json,
and snapshot-methods.json into one folder; run python3 reproduce-snapshot.py.
No network calls. This does not independently reconstruct source datasets or models.
"""
import json
from decimal import Decimal
from pathlib import Path
root = Path(__file__).resolve().parent
load = lambda name: json.loads((root / name).read_text())
data = load('data.json')
rows = {r['id']: r for r in data['plotted_data']['forces']}
calc = data['plotted_data']['source_definitions']['debt']['calculation']
ratio = Decimal(str(calc['outlays_percent_gdp'])) - Decimal(str(calc['receipts_percent_gdp']))
assert ratio == Decimal(str(rows['debt']['value']))
interest = next(r for r in data['supporting_observations'] if r['id'] == 'us_federal_net_interest_revenue_share')
share = interest['inputs']['net_interest_million_usd'] / interest['inputs']['total_receipts_million_usd'] * 100
assert round(share, 1) == 19.5
annual = load('named-conflicts.json')['datasets'][1]['years']
assert len(annual) == 80 and annual[0]['year'] == 1946 and annual[-1]['year'] == 2025
assert all(y['count'] == len({c['id'] for c in y['conflicts']}) for y in annual)
assert max(y['count'] for y in annual) == rows['external']['context']['observedRange']['max'] == 8
assert annual[-1]['count'] == rows['external']['finalAnnual']['value']
provisional = load('provisional-conflicts.json')
assert provisional['count'] == rows['external']['value'] == rows['external']['provisionalEstimate']['value'] == len(provisional['conflicts'])
assert provisional['coverage']['end'] == '2026-09-30'
climate = data['plotted_data']['source_definitions']['nature']['methods']
assert all(round(v, 1) == rows['nature']['previousEstimate']['value'] for v in climate.values())
assert data['plotted_data']['source_definitions']['nature']['current_2026']['value'] == rows['nature']['value'] == 1.44
assert rows['nature']['observation']['kind'] == 'published_estimate'
print(f'Rounded Treasury shares: {ratio}% GDP. Not a precise ratio from nominal GDP.')
print(f'Net interest / receipts: {share:.4f}% (display 19.5%).')
print('UCDP finalized annual 2025: 8; full 1946–2025 range: 0–8.')
print(f"Separate {rows['external']['provisionalEstimate']['period']} analyst-derived provisional count: {provisional['count']}; no annual decline inferred.")
print('Current long-term climate estimate: 1.44°C, published 29 Oct 2026. Earlier end-2025 methods round to 1.4°C; no independent model reconstruction or confidence interval.')
