import os
import json
import pandas as pd
import altair as alt
import pathlib
HERE = pathlib.Path(__file__).parent
PLOTS = HERE / "plots"
PLOTS.mkdir(exist_ok=True)
directory = HERE / "results"
dataframes = []
for filepath in directory.glob("*.json"):
print(f"Processing {filepath.name}...")
data = json.loads(filepath.read_text())
bench_group, git_hash = filepath.name[:-5].split("_")
benchmark_times = [result["mean"] for result in data["results"]]
commands = [result["command"] for result in data["results"]]
df = pd.DataFrame({"Command": commands, "Time (s)": benchmark_times})
df["Git Hash"] = git_hash
df["Bench Group"] = bench_group
dataframes.append(df)
combined_df = pd.concat(dataframes)
charts = []
for bench_group, df in combined_df.groupby("Bench Group"):
if df["Git Hash"].nunique() == 1:
chart = (
alt.Chart(df)
.mark_bar()
.encode(
x="Command",
y="Time (s)",
)
.properties(width=200, height=200, title=bench_group)
)
else:
chart = (
alt.Chart(df)
.mark_line()
.encode(
color="Command",
y="Time (s)",
x="Git Hash:O",
)
.properties(width=200, height=200, title=bench_group)
)
chart.save(PLOTS / f"{bench_group}.svg")