-
-
Notifications
You must be signed in to change notification settings - Fork 556
/
Copy pathrender.py
141 lines (118 loc) Β· 4.44 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
139
140
141
from __future__ import annotations
import json
import shutil
import textwrap
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__":
with open("details.json") as f:
details = json.load(f)
for track_name, track_details in details.items():
track_dir = Path(f"../docs/benchmarks/{track_name}")
track_dir.mkdir(exist_ok=True)
with open(f"../docs/benchmarks/{track_name}/index.md", "w", encoding="utf-8") as f:
def print_(x):
return print(x, file=f, end="\n\n")
print_(f"# {track_name}")
# Move the dataset from the benchmarks folder to the docs folder
csv_name = track_name.replace(" ", "_").lower()
shutil.copy(f"{csv_name}.csv", f"../docs/benchmarks/{track_name}/{csv_name}.csv")
df_path = Path(f"../docs/benchmarks/{track_name}/{csv_name}.csv")
df_md = (
pd.read_csv(str(df_path))
.groupby(["model", "dataset"])
.last()
.drop(columns=["track", "step"])
.reset_index()
.rename(columns={"model": "Model", "dataset": "Dataset"})
.to_markdown(index=False)
)
print_(
f"""
=== "Table"
{textwrap.indent(df_md, ' ')}
=== "Chart"
*Try reloading the page if something is buggy*
```vegalite
{textwrap.indent(json.dumps(render_df(df_path), indent=2), ' ')}
```
"""
)
print_("## Datasets")
for dataset_name, dataset_details in track_details["Dataset"].items():
print_(f'???- abstract "{dataset_name}"')
print_(textwrap.indent(dataset_details, " "))
print_("<span />")
print_("## Models")
for model_name, model_details in track_details["Model"].items():
print_(f'???- example "{model_name}"')
print_(
f" <pre>{textwrap.indent(model_details, ' ').replace(' ', '', 1)}</pre>"
)
print_("<span />")
print_("## Environment")
print_(
pre(
watermark(
python=True, packages="river,numpy,scikit-learn,pandas,scipy", machine=True
)
)
)