"""Run: python3 verify_research.py (keep notes.json beside this file)."""
import json
from decimal import Decimal as D
from pathlib import Path

def calculate(data):
    x = data['inputs']
    result = {}
    for country in ('asia', 'china', 'indonesia'):
        v = x[country + '_2026_forecasts']
        result[country + '_revision_pp'] = D(v['oct2026']) - D(v['oct2025'])
    ranges = x['singapore_2026_ranges']
    for date, bounds in ranges.items():
        low, high = map(D, bounds)
        assert low <= high
        result[date + '_midpoint'] = (low + high) / 2
        result[date + '_width'] = high - low
    result['sg_midpoint_revision_pp'] = result['aug2026_midpoint'] - result['feb2026_midpoint']
    result['sg_width_revision_pp'] = result['aug2026_width'] - result['feb2026_width']
    return result

if __name__ == '__main__':
    data = json.loads(Path(__file__).with_name('notes.json').read_text())
    r = calculate(data)
    assert r['asia_revision_pp'] == D('0.7')
    assert r['china_revision_pp'] == D('0.3')
    assert r['indonesia_revision_pp'] == D('0.2')
    assert r['sg_midpoint_revision_pp'] == D('2.0')
    assert r['sg_width_revision_pp'] == D('-1.0')
    print(json.dumps({k: str(v) for k, v in r.items()}, indent=2))
