"""本主题专属离线算法，仅读取同目录合成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 bits in data['rgb_bits_per_channel']:
 bpp=3*bits;rate=data['width']*data['height']*data['fps']*bpp
 rows.append({'bits_per_channel':bits,'bits_per_pixel':bpp,'active_bits_per_second':rate,'active_Gbps_decimal':rate/1000000000,'bytes_per_second':rate//8})
assert rows[0]['active_bits_per_second']==5971968000 and rows[1]['active_bits_per_second']==7464960000
assert Fraction(rows[1]['active_bits_per_second'],rows[0]['active_bits_per_second'])==Fraction(5,4)
result={'cases':rows,'fps_used':data['fps'],'pwm_refresh_used_as_video_fps':False,'excluded':['消隐时序','链路编码开销','链路模式','压缩或子采样'],'actual_link_capability':None}
(BASE/'result.json').write_text(json.dumps(result,ensure_ascii=False,indent=2)+'\n',encoding='utf-8')
print(json.dumps(result,ensure_ascii=False))
