"""One extra saved row: exact sensitivity, not new transaction observations.""" import argparse,hashlib,json from decimal import Decimal,localcontext,ROUND_HALF_UP from fractions import Fraction from pathlib import Path def display(value): with localcontext() as ctx: ctx.prec=80 return str((Decimal(value.numerator)/Decimal(value.denominator)).quantize(Decimal('.01'),rounding=ROUND_HALF_UP)) def ratio(value):return {'numerator':value.numerator,'denominator':value.denominator,'rounded_2dp':display(value)} def calculate(raw): data=json.loads(raw);located=[] for snap in data['snapshots']: for number,row in enumerate(snap['records'],1): assert isinstance(row['amount'],int) and row['amount']>0 located.append({'snapshot_month':snap['contract_month'],'saved_at_kst':snap['saved_at_kst'],'source_row_number':number,'amount_manwon':row['amount'],'row':row}) assert located count=len(located);total=sum(x['amount_manwon']for x in located);mean=Fraction(total,count) cases=[] for record in located: new_mean=Fraction(total+record['amount_manwon'],count+1) delta=new_mean-mean assert delta==(Fraction(record['amount_manwon'])-mean)/(count+1) cases.append(dict(record,count=count+1,total_manwon=total+record['amount_manwon'],mean=ratio(new_mean),change=ratio(delta))) minimum=min(cases,key=lambda x:x['amount_manwon']);maximum=max(cases,key=lambda x:x['amount_manwon']) return {'kind':'one_extra_saved_row_sensitivity_not_actual_transaction_duplicates','calculated_on':'2026-11-02','source_sha256':hashlib.sha256(raw).hexdigest(),'source':'jongno-202608-202609.json','original':{'count':count,'total_manwon':total,'mean':ratio(mean)},'all_rows_copied_once':{'count':count*2,'total_manwon':total*2,'mean':ratio(Fraction(total*2,count*2))},'single_extra_row_cases':cases,'extreme_case_locators':{'lowest':{k:minimum[k]for k in ['snapshot_month','source_row_number','amount_manwon']},'highest':{k:maximum[k]for k in ['snapshot_month','source_row_number','amount_manwon']}},'bounds_scope':'Only one extra row chosen from these saved rows. Not arbitrary amounts, multiple extra rows, new reports, correction/cancellation handling or real market price bounds. Row numbers locate this immutable snapshot; they are not legal transaction identifiers.'} if __name__=='__main__': p=argparse.ArgumentParser();p.add_argument('input',type=Path);args=p.parse_args();print(json.dumps(calculate(args.input.read_bytes()),ensure_ascii=False,indent=2))