Compare commits

..

2 Commits

View File

@@ -117,10 +117,11 @@ def de2000(lab1, lab2) -> float:
def add_delta_e(rows: list[dict], references: dict[str, str]) -> bool: def add_delta_e(rows: list[dict], references: dict[str, str]) -> bool:
"""Add a CIEDE2000 column to each averaged row vs that sample's reference. """Add a CIEDE2000 column to each averaged row vs that sample's reference.
Samples absent from `references` are references themselves (dE00 = 0). Samples absent from `references` are references themselves (dE00 left
Returns True if the column was written (only when at least one sample empty — they have no external comparison). Returns True if the column
names a reference). Never raises so the scan pipeline can continue even was written (only when at least one sample names a reference). Never
when a named reference is missing. raises so the scan pipeline can continue even when a named reference
is missing.
""" """
if not rows or not references: if not rows or not references:
return False return False
@@ -131,7 +132,7 @@ def add_delta_e(rows: list[dict], references: dict[str, str]) -> bool:
sid = row["sample_id"] sid = row["sample_id"]
ref_id = references.get(sid) ref_id = references.get(sid)
if ref_id is None: if ref_id is None:
row[DE_COL] = 0.0 row[DE_COL] = ""
wrote = True wrote = True
continue continue
ref_row = by_id.get(ref_id) ref_row = by_id.get(ref_id)
@@ -221,10 +222,10 @@ def write_html(
if has_de: if has_de:
raw = r.get(DE_COL, "") raw = r.get(DE_COL, "")
if raw == "" or raw is None: if raw == "" or raw is None:
cells.append('<td class="de">&mdash;</td>') cells.append("<td>&mdash;</td>")
else: else:
d = float(raw) d = float(raw)
de_cls = "de win" if is_ref else ("de bad" if d >= 3.5 else "de") de_cls = "de bad" if d >= 3.5 else "de"
cells.append( cells.append(
f'<td class="{de_cls}" title="{esc(de_bucket(d))}">{d:.2f}</td>' f'<td class="{de_cls}" title="{esc(de_bucket(d))}">{d:.2f}</td>'
) )
@@ -252,7 +253,7 @@ def write_html(
<title>Averaged color measurements</title> <title>Averaged color measurements</title>
<style> <style>
:root {{ --text:#1f2328; --text2:#57606a; --text3:#8b949e; --stroke:#d0d7de; :root {{ --text:#1f2328; --text2:#57606a; --text3:#8b949e; --stroke:#d0d7de;
--bg:#fff; --fill:#f6f8fa; --good:#1a7f37; --bad:#bc4c00; }} --bg:#fff; --fill:#f6f8fa; --bad:#bc4c00; }}
* {{ box-sizing:border-box; }} * {{ box-sizing:border-box; }}
body {{ margin:0; padding:32px 24px 48px; background:var(--bg); color:var(--text); body {{ margin:0; padding:32px 24px 48px; background:var(--bg); color:var(--text);
font:14px/1.5 -apple-system,"Segoe UI",Roboto,Helvetica,Arial,sans-serif; }} font:14px/1.5 -apple-system,"Segoe UI",Roboto,Helvetica,Arial,sans-serif; }}
@@ -278,7 +279,6 @@ def write_html(
.tag {{ font-size:11px; color:var(--text3); border:1px solid var(--stroke); .tag {{ font-size:11px; color:var(--text3); border:1px solid var(--stroke);
border-radius:4px; padding:0 5px; margin-left:6px; }} border-radius:4px; padding:0 5px; margin-left:6px; }}
.de {{ font-weight:600; }} .de {{ font-weight:600; }}
.win {{ color:var(--good); }}
.bad {{ color:var(--bad); }} .bad {{ color:var(--bad); }}
.faint {{ color:var(--text3); font-size:12px; margin-top:14px; }} .faint {{ color:var(--text3); font-size:12px; margin-top:14px; }}
@media print {{ body {{ padding:0; }} }} @media print {{ body {{ padding:0; }} }}