"""Check the presentation repair and unchanged values of numberdb.org/T484.

Run with SageMath: sage -python repair_checks.py
Place T484-live.json, T484-proposed.json, generate.py, checks.py and
source-data.json beside this script. No network or credentials are required.
The existing full numerical checks are repeated against the proposed rows;
these check source transcription and conventions, not certified asymptotics.
"""
import json
from pathlib import Path
import numberdb.sage as numberdb
from generate import AnimalGrowth
from checks import run, records_from_document

root = Path(__file__).resolve().parent
before = json.loads((root/'T484-live.json').read_text())
after = json.loads((root/'T484-proposed.json').read_text())
assert list(before) == list(after)
assert list(before['Parameters']) == list(after['Parameters'])
for key in before['Parameters']:
    assert list(before['Parameters'][key].get('values',{})) == list(after['Parameters'][key].get('values',{}))
assert records_from_document(before) == records_from_document(after)
assert after['Parameters']['size']['values'] == {'cells':'cells','edges':'edges'}
for prior, revised in zip(before['Similar tables'], after['Similar tables']):
    assert prior['relation'] == revised['relation']
    assert revised['table'].startswith(prior['table']+'[')
generator = AnimalGrowth()
for params in generator.enumerate():
    row=after['Numbers']
    for k in generator.parameters:
        row=row[params[k]]
    assert row == generator.value(params,generator.digits)
print('REPAIR: same four entry identities, values, uncertainty intervals and generator output; labels/captions/comments consistent', flush=True)
run(records_from_document(after))
