"""本主题专属离线算法，仅读取同目录合成JSON，不联网、不控制设备。"""
import csv, json, math, re, struct
from pathlib import Path
from fractions import Fraction
BASE=Path(__file__).resolve().parent
data=json.loads((BASE/'input.json').read_text(encoding='utf-8'))['data']
rows=[]
for t in data['timetags']:
 raw=struct.pack('>Q',t);hi,lo=struct.unpack('>II',raw)
 rows.append({'raw_64':t,'hex':raw.hex(),'meaning':'immediate' if t==1 else 'NTP_epoch_fixed_point','seconds_integer':None if t==1 else hi,'fraction_exact':None if t==1 else str(Fraction(lo,2**32))})
assert rows[0]['meaning']=='immediate' and rows[1]['fraction_exact']=='1/2'
result={'timetags':rows,'clock_synchronization_tested':False}
(BASE/'result.json').write_text(json.dumps(result,ensure_ascii=False,indent=2)+'\n',encoding='utf-8')
print(json.dumps(result,ensure_ascii=False))
