diff --git a/average-results.py b/average-results.py index 3bdaad2..62ed1d7 100755 --- a/average-results.py +++ b/average-results.py @@ -20,6 +20,19 @@ WHITE_POINT = (96.422, 100.0, 82.521) # sample's Delta-E is measured against it. The marker is stripped to recover # the real sample name. REF_MARKER = "*" +NOTE_PREFIX = "# note:" + + +def load_notes(path: Path) -> list[str]: + """Read display notes from '# note: ...' comment lines in the samples file.""" + if not path.exists(): + return [] + notes = [] + for line in path.read_text(encoding="utf-8").splitlines(): + stripped = line.strip() + if stripped.lower().startswith(NOTE_PREFIX): + notes.append(stripped[len(NOTE_PREFIX):].strip()) + return notes def _strip_ref_marker(name: str) -> str: @@ -156,7 +169,9 @@ def de_bucket(d: float) -> str: return "clearly different" -def write_html(rows: list[dict], ref_used: str | None, path: Path) -> None: +def write_html( + rows: list[dict], ref_used: str | None, path: Path, notes: list[str] | None = None +) -> None: """Write a self-contained HTML view of the averaged results.""" has_de = ref_used is not None esc = html.escape @@ -173,12 +188,15 @@ def write_html(rows: list[dict], ref_used: str | None, path: Path) -> None: lab = tuple(float(r[f"{c}_mean"]) for c in LAB_COLS) std = tuple(float(r[f"{c}_std"]) for c in LAB_COLS) is_ref = has_de and r["sample_id"] == ref_used - cls = ' class="ref"' if is_ref else "" + is_pred = int(float(r["n_scans"])) == 0 + row_cls = "ref" if is_ref else ("pred" if is_pred else "") + cls = f' class="{row_cls}"' if row_cls else "" ref_tag = ' reference' if is_ref else "" + pred_tag = ' predicted' if is_pred else "" cells = [ f'', - f'{esc(r["sample_id"])}{ref_tag}', - f'{esc(str(r["n_scans"]))}', + f'{esc(r["sample_id"])}{ref_tag}{pred_tag}', + f'{esc(str(r["n_scans"])) if not is_pred else "—"}', ] for m, s in zip(lab, std): cells.append(f'{m:.2f}±{s:.2f}') @@ -195,6 +213,11 @@ def write_html(rows: list[dict], ref_used: str | None, path: Path) -> None: "No Delta-E reference was set (mark one sample with a leading '*')." ) generated = datetime.now().strftime("%Y-%m-%d %H:%M") + notes = notes or [] + notes_html = "" + if notes: + items = "".join(f"
  • {esc(n)}
  • " for n in notes) + notes_html = f' \n' html_doc = f""" @@ -211,6 +234,8 @@ def write_html(rows: list[dict], ref_used: str | None, path: Path) -> None: main {{ max-width:760px; margin:0 auto; }} h1 {{ font-size:22px; margin:0 0 4px; }} .muted {{ color:var(--text2); margin:0 0 20px; }} + .notes {{ list-style:none; padding:0; margin:0 0 20px; color:var(--text2); font-size:13px; }} + .notes li {{ margin:2px 0; }} table {{ border-collapse:separate; border-spacing:0; width:100%; border:1px solid var(--stroke); border-radius:8px; overflow:hidden; }} th,td {{ padding:7px 10px; text-align:right; font-size:13px; @@ -220,6 +245,8 @@ def write_html(rows: list[dict], ref_used: str | None, path: Path) -> None: border-bottom:1px solid var(--stroke); }} tbody tr + tr td {{ border-top:1px solid var(--stroke); }} tr.ref td {{ background:var(--fill); }} + tr.pred td {{ background:#fff8e6; }} + tr.pred td.name {{ font-style:italic; }} .patch {{ width:18px; height:18px; display:inline-block; vertical-align:middle; border-radius:5px; border:1px solid var(--stroke); }} .std {{ color:var(--text3); font-size:11px; margin-left:3px; }} @@ -237,7 +264,7 @@ def write_html(rows: list[dict], ref_used: str | None, path: Path) -> None:

    Averaged color measurements

    Per-sample CIELAB means (± standard deviation) across the averaged scans. {ref_note}

    - +{notes_html}
    {"".join(head_cells)} @@ -339,7 +366,8 @@ def main() -> int: writer.writerows(averaged) html_path = args.output.with_suffix(".html") - write_html(averaged, ref_used, html_path) + notes = load_notes(args.samples) if args.samples.exists() else [] + write_html(averaged, ref_used, html_path, notes) print(f"Wrote {len(averaged)} averaged sample(s) to {args.output}") print(f"Wrote HTML view to {html_path}") diff --git a/samples.example.txt b/samples.example.txt index c09c10e..86e6b9b 100644 --- a/samples.example.txt +++ b/samples.example.txt @@ -6,6 +6,10 @@ # measured against it. If none is marked, the first sample is used. Example: # *INK_A # +# Optional notes for averaged.html (one per line, shown above the results table): +# note: Glaze: CPO1192 +# note: Firing Temperature: 1150 C +# # Single materials: just the material name/code, e.g. # INK_A #