tradingSystem/research/heat_recurrence_20261029/build_dashboard.py

20 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""把分组结果分块嵌入独立HTML;浏览器只解压当前筛选,无联网请求。"""
import base64,gzip,json,sys
import pandas as pd
from common import ROOT,dump,digest,offline
COLUMNS=['mean_gross','mean_net30','mean_net60','win30','active_days','completed','mean_selected','filled','unresolved','delayed','delta_k0_net30','delta_current_net30','delta_universe_net30','excess_csi300','excess_csi500','excess_csi1000','excess_csi2000']
def main():
sys.addaudithook(offline);g=pd.read_csv(ROOT/'grid.csv.gz');payload={}
for key,z in g.groupby(['score','period','phase_index','stage']):
z=z.sort_values(['config','hold']);assert len(z)==3440
raw=z[COLUMNS].to_json(orient='values',double_precision=10).encode();payload['|'.join(map(str,key))]=base64.b64encode(gzip.compress(raw,mtime=0)).decode()
chart=(ROOT/'vendor/chart.umd.js').read_text();expected='jb8JQMbMoBUzgWatfe6COACi2ljcDdZQ2OxczGA3bGNeWe+6DChMTBJemed7ZnvJ'
import hashlib
assert base64.b64encode(hashlib.sha384(chart.encode()).digest()).decode()==expected
html=(ROOT/'dashboard.html.tpl').read_text().replace('/*__CHARTJS__*/',chart).replace('/*__PAYLOAD__*/',json.dumps(payload,separators=(',',':')))
assert '<script src=' not in html
dest=ROOT/'热度反复活跃矩阵浏览器.html';dest.write_text(html)
dump(ROOT/'dashboard_manifest.json',{'chunks':len(payload),'rows_per_chunk':3440,'columns':COLUMNS,'html_bytes':dest.stat().st_size,'html_sha256':digest(dest),'chartjs_version':'4.5.1','chartjs_sha384':expected,'external_runtime_requests':0,'data_source':'grid.csv.gz','data_source_sha256':digest(ROOT/'grid.csv.gz'),'default':'热度>=0.8,历史频次,当时可查口径,全区间,30基点,全部阶段'})
print('独立矩阵浏览器',dest.stat().st_size,'字节;',len(payload),'个按需本地分块')
if __name__=='__main__':main()