-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathrender.py
138 lines (125 loc) · 4.37 KB
/
render.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import json
import shutil
from pathlib import Path
import pandas as pd
from dominate.tags import pre
from watermark import watermark
def render_df(df_path: Path) -> dict:
df = pd.read_csv(str(df_path))
unique_datasets = list(df["dataset"].unique())
measures = list(df.columns)[4:]
res = {
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"values": df.to_dict(orient="records")
# "url": f"benchmarks/{df_path.name}"
},
"params": [
{
"name": "models",
"select": {"type": "point", "fields": ["model"]},
"bind": "legend",
},
{
"name": "Dataset",
"value": unique_datasets[0],
"bind": {"input": "select", "options": unique_datasets},
},
{"name": "grid", "select": "interval", "bind": "scales"},
],
"transform": [
{"filter": {"field": "dataset", "equal": {"expr": "Dataset"}}}
],
"repeat": {"row": measures},
"spec": {
"width": "container",
# "height": "container",
"mark": "line",
"encoding": {
"x": {
"field": "step",
"type": "quantitative",
"axis": {
"titleFontSize": 18,
"labelFontSize": 18,
"title": "Instance",
},
},
"y": {
"field": {"repeat": "row"},
"type": "quantitative",
"axis": {"titleFontSize": 18, "labelFontSize": 18},
},
"color": {
"field": "model",
"type": "ordinal",
"scale": {"scheme": "category20b"},
"title": "Models",
"legend": {
"titleFontSize": 18,
"labelFontSize": 18,
"labelLimit": 500,
},
},
"opacity": {
"condition": {"param": "models", "value": 1},
"value": 0.2,
},
},
},
}
return res
if __name__ == "__main__":
if Path("details.json").exists():
if Path("../docs/benchmarks/details.json").exists():
Path("../docs/benchmarks/details.json").unlink()
shutil.move("details.json", "../docs/benchmarks/details.json")
details = json.load(open("../docs/benchmarks/details.json"))
with open("../docs/benchmarks/index.md", "w", encoding="utf-8") as f:
print_ = lambda x: print(x, file=f, end="\n\n")
print_(
"""---
hide:
- navigation
---
"""
)
print_("# Benchmark")
for track_name, track_details in details.items():
print_(f"## {track_name}")
csv_name = track_name.replace(" ", "_").lower()
if Path(f"{csv_name}.csv").exists():
if Path(f"../docs/benchmarks/{csv_name}.csv").exists():
Path(f"../docs/benchmarks/{csv_name}.csv").unlink()
shutil.move(
f"{csv_name}.csv",
"../docs/benchmarks/",
)
df_path = Path(f"../docs/benchmarks/{csv_name}.csv")
print_("```vegalite")
print_(json.dumps(render_df(df_path), indent=2))
print_("```")
print_("### Datasets")
for dataset_name, dataset_details in track_details[
"Dataset"
].items():
print_(f"<details>")
print_(f"<summary>{dataset_name}</summary>")
print_(pre(dataset_details))
print_(f"</details>")
print_("### Models")
for model_name, model_details in track_details["Model"].items():
print_(f"<details>")
print_(f"<summary>{model_name}</summary>")
print_(pre(model_details))
print_(f"</details>")
print_("# Environment")
print_(
pre(
watermark(
python=True,
packages="river,numpy,scikit-learn,pandas,scipy",
machine=True,
)
)
)