|
4 | 4 | from typing import Set, Dict, Optional, cast, List, DefaultDict, Tuple |
5 | 5 | from pathlib import Path, PurePath |
6 | 6 | from smtcomp import defs |
| 7 | +from rich.progress import track as rich_track |
7 | 8 |
|
8 | 9 | import polars as pl |
9 | 10 | import altair as alt |
10 | | -import smtcomp.scoring |
| 11 | +import altair.utils.html |
| 12 | +import altair.vegalite.display |
11 | 13 | from smtcomp.utils import * |
12 | | -import smtcomp.results |
| 14 | +import smtcomp.generate_website_page |
| 15 | +import frontmatter |
13 | 16 |
|
14 | 17 | c_file = pl.col("file") |
15 | 18 | c_logic = pl.col("logic") |
|
28 | 31 | def create_output( |
29 | 32 | config: defs.Config, |
30 | 33 | results: pl.LazyFrame, |
31 | | - output: Path, |
32 | 34 | logics: list[defs.Logic] = [], |
33 | 35 | divisions: list[defs.Division] = [], |
34 | | -) -> None: |
| 36 | +) -> alt.api.ChartType: |
35 | 37 |
|
36 | 38 | # We are computing the buckets offline because we have too much data |
37 | 39 | results = results.filter( |
@@ -82,7 +84,7 @@ def create_output( |
82 | 84 |
|
83 | 85 | bucket_domain: list[float] = list(df_buckets["bucket"]) |
84 | 86 |
|
85 | | - row1 = df_corr.row(1, named=True) |
| 87 | + row1 = df_corr.row(min(1, len(df_corr) - 1), named=True) |
86 | 88 |
|
87 | 89 | # Create heatmap with selection |
88 | 90 | select_x = alt.selection_point(fields=["solver"], name="solver1", value=row1["solver"], toggle=False) |
@@ -170,10 +172,58 @@ def create_output( |
170 | 172 | .add_params(division) |
171 | 173 | ) |
172 | 174 |
|
173 | | - graph = (g_select_provers | g_results_rect + g_results_text).resolve_scale(color="independent") |
| 175 | + graph: alt.api.ChartType = (g_select_provers | g_results_rect + g_results_text).resolve_scale(color="independent") |
174 | 176 |
|
175 | 177 | graph = alt.vconcat(graph, legend_answer_x | legend_answer_y | legend_logic | legend_division) |
176 | 178 |
|
177 | 179 | graph = graph.resolve_scale(color="independent") |
178 | 180 |
|
179 | | - graph.save(output) |
| 181 | + return graph |
| 182 | + |
| 183 | + |
| 184 | +def save_output( |
| 185 | + config: defs.Config, |
| 186 | + results: pl.LazyFrame, |
| 187 | + output: Path, |
| 188 | + logics: list[defs.Logic] = [], |
| 189 | + divisions: list[defs.Division] = [], |
| 190 | +) -> None: |
| 191 | + |
| 192 | + create_output(config, results, logics, divisions).save(output) |
| 193 | + |
| 194 | + |
| 195 | +def save_hugo_output(chart: alt.api.ChartType, output: Path, title: str) -> None: |
| 196 | + |
| 197 | + with alt.data_transformers.disable_max_rows(): |
| 198 | + content = chart.to_html( |
| 199 | + fullhtml=False, |
| 200 | + ) |
| 201 | + post = frontmatter.Post(content=content, title=title, layout="chart") |
| 202 | + output.write_text(frontmatter.dumps(post)) |
| 203 | + |
| 204 | + |
| 205 | +def generate_pages(config: defs.Config, results: pl.LazyFrame, track: defs.Track) -> None: |
| 206 | + page_suffix = smtcomp.generate_website_page.page_track_suffix(track) |
| 207 | + dst = config.web_results |
| 208 | + dst.mkdir(parents=True, exist_ok=True) |
| 209 | + |
| 210 | + df_results = results.filter(c_run == True).collect() |
| 211 | + results = df_results.lazy() |
| 212 | + |
| 213 | + divisions = list(df_results["division"].unique()) |
| 214 | + for div in rich_track(list(map(defs.Division.of_int, divisions)), description="Generating chart for divisions"): |
| 215 | + chart = create_output(config, results, divisions=[div]) |
| 216 | + save_hugo_output( |
| 217 | + chart, |
| 218 | + output=dst / f"{div.name.lower()}-{page_suffix}-chart.html", |
| 219 | + title=f"Chart for division {div.name}", |
| 220 | + ) |
| 221 | + |
| 222 | + logics = list(df_results["logic"].unique()) |
| 223 | + for logic in rich_track(list(map(defs.Logic.of_int, logics)), description="Generating chart for logics"): |
| 224 | + chart = create_output(config, results, logics=[logic]) |
| 225 | + save_hugo_output( |
| 226 | + chart, |
| 227 | + output=dst / f"{logic.name.lower()}-{page_suffix}-chart.html", |
| 228 | + title=f"Chart for logic {logic.name}", |
| 229 | + ) |
0 commit comments