#!/usr/bin/env python3
"""Независимый интервальный эталон: не импортирует реконструктор."""
import json,sys
from pathlib import Path
from fractions import Fraction
p=Path(__file__).resolve().parent
r=json.loads((Path(sys.argv[1]) if len(sys.argv)>1 else p/'result.json').read_text(encoding='utf-8'))
assert r['exact_duplicate_rows_removed']==1
# Другой расчёт: длительности интервалов, а не повторный event replay.
for stamp,p4days,pdays,cdays,percentage in [('2026-04-01',16,99,119,'31.31'),('2026-04-03',19,102,122,'30.39')]:
    s=r['snapshots'][stamp]
    assert s['unique_people_in_period']==4
    person_days=31+10+11+31+p4days
    contract_days=person_days+20
    assert person_days==pdays and contract_days==cdays
    assert s['person_days']==person_days and s['contract_days']==contract_days
    assert len(s['person_departures'])==1 and s['person_departures'][0]['person']=='P2'
    assert s['future_hires_excluded']==['P5']
    assert s['turnover_percent']==percentage
    assert s['department_person_days']=={'Sales':67,'Ops':16+p4days}
    for row in s['daily']:
        d=int(row['date'][-2:])
        expected_people=2+(d<=10 or d>=21)+(d>=(16 if stamp=='2026-04-01' else 13))
        expected_contracts=expected_people+(6<=d<=25)
        assert row['people']==expected_people and row['contracts']==expected_contracts
        assert sum(row['departments'].values())==row['people']
    assert s['daily'][0]['people']==3 and s['daily'][-1]['people']==4
assert r['snapshots']['2026-04-03']['person_days']-r['snapshots']['2026-04-01']['person_days']==3
assert Fraction(102,31)!=Fraction(3+4,2)
print('PASS: 62 daily rows, intervals, contracts vs people, late correction, department bridge, departures, future event, duplicate.')
