16 lines
923 B
Python
16 lines
923 B
Python
#!/usr/bin/env python3
|
|
"""Safe inject: uses regex to replace var D=...}; only"""
|
|
import json, re
|
|
P1="/Users/mac/scripts/terminal-bench/aggregate.json"
|
|
P2="/Users/mac/scripts/terminal-bench/dashboard.html"
|
|
with open(P1) as f:data=json.load(f)
|
|
for m in data.values():
|
|
if isinstance(m.get("speed"),dict):
|
|
s=[v for v in m["speed"].values() if isinstance(v,(int,float)) and v>0]
|
|
m["speed"]={"平均":round(sum(s)/len(s),1)} if s else {}
|
|
for t in ["code_generation","debugging","math_reasoning","instruction_follow","system_design","long_context","code_review","tool_calling","multi_step"]:
|
|
if t not in m.get("tasks",{}):m["tasks"]=m.get("tasks",{});m["tasks"][t]=0
|
|
with open(P2) as f:html=f.read()
|
|
html=re.sub(r'var D=\{.*?\};',f'var D={json.dumps(data,ensure_ascii=False,separators=(",",":"))};',html,count=1,flags=re.DOTALL)
|
|
with open(P2,"w") as f:f.write(html)
|
|
print(f"✅ {len(data)} models") |