from fractions import Fraction as Q from collections import defaultdict,Counter def run(load,check): menus={'cumulative':load('C365_DATA.json')['cumulative_register'],'regular':load('C286_DATA.json')['target_register']};out=[] for field,records in menus.items(): at=defaultdict(list);piv=defaultdict(list) for j,r in enumerate(records): v=r['coordinate'] if field=='cumulative' else r['center'];at[v].append(j) if r['role'].startswith('Flood'):piv[v].append(j) hits=[];candidates=[];counter=Counter();scales=Counter() for A in sorted(piv): for B in sorted(piv): if A==B:continue counter['ordered_distinct_pivot_pairs']+=1;D=B-A;x=Q(A)+Q(13,10)*D;y=Q(A)+Q(30,23)*D if x.denominator!=1 or y.denominator!=1: counter['noninteger_intersection']+=1;continue x=int(x);y=int(y);m=Q(D,230);assert m.denominator==1 item={'J_pivot':A,'P_pivot':B,'pivot_difference':D,'signed_scale':int(m),'input':x,'output':y,'J_pivot_record_indices':piv[A],'P_pivot_record_indices':piv[B],'input_record_indices':at.get(x,[]),'output_record_indices':at.get(y,[])} candidates.append(item);scales[int(m)]+=1 if item['input_record_indices'] and item['output_record_indices']: hits.append(item);counter['source_supported_coordinate_quadruples']+=1 else:counter['integer_intersection_without_both_source_endpoints']+=1 check('complete pair accounting '+field,counter['ordered_distinct_pivot_pairs']==len(piv)*(len(piv)-1)==counter['noninteger_intersection']+len(candidates)) check('integer candidate accounting '+field,len(candidates)==counter['source_supported_coordinate_quadruples']+counter['integer_intersection_without_both_source_endpoints']) for h in hits: A=h['J_pivot'];B=h['P_pivot'];x=h['input'];y=h['output'];m=h['signed_scale'] check('source common image '+str((field,A,B)),299*(y-A)==300*(x-A) and 69*(y-B)==70*(x-B) and y-x==m and x-A==299*m and x-B==69*m) out.append({'field':field,'records':len(records),'distinct_source_coordinates':len(at),'Flood_source_records':sum(len(v) for v in piv.values()),'distinct_Flood_coordinates':len(piv),'counts':dict(counter),'integer_candidate_scales':dict(sorted(scales.items())),'integer_candidates':candidates,'hits':hits,'source_supported_scales':dict(sorted(Counter(h['signed_scale'] for h in hits).items()))}) return {'step':'C378','menus':menus,'fields':out,'scope':'All ordered distinct-coordinate Flood-pivot pairs in each existing menu; no cross-field pivot mixing. Whole-year source coordinates only. A hit preserves all source identities for later context qualification, and is not automatic permission to combine their contexts. Scale sign records coordinate orientation, not a new expansion ratio.'}