From 7cf8a6bcd192281caf75b59570d9e2ce54244338 Mon Sep 17 00:00:00 2001 From: Seongho Bae Date: Wed, 1 Jul 2026 16:02:37 +0900 Subject: [PATCH 01/10] Chart later numeric report rows --- python/fast_mlsirm/report.py | 13 +++++++------ tests/test_report.py | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/python/fast_mlsirm/report.py b/python/fast_mlsirm/report.py index 89fbcd684..3b81a7c71 100644 --- a/python/fast_mlsirm/report.py +++ b/python/fast_mlsirm/report.py @@ -245,7 +245,12 @@ def _bar_chart(rows: list[dict[str, Any]], value_key: str | None) -> str: return "" if not rows: return "" - values = [float(row[value_key]) for row in rows if _is_number(row.get(value_key))] + numeric_rows = [ + (index, row, float(row[value_key])) + for index, row in enumerate(rows) + if _is_number(row.get(value_key)) + ] + values = [value for _, _, value in numeric_rows] if not values: return "" @@ -253,11 +258,7 @@ def _bar_chart(rows: list[dict[str, Any]], value_key: str | None) -> str: upper = max(values) span = upper - lower chart_rows = [] - for index, row in enumerate(rows[:12]): - raw_value = row.get(value_key) - if not _is_number(raw_value): - continue - value = float(raw_value) + for index, row, value in numeric_rows[:12]: width = 64.0 if span == 0 else 8.0 + ((value - lower) / span) * 92.0 chart_rows.append( "\n".join( diff --git a/tests/test_report.py b/tests/test_report.py index 0019a48fa..6de507e6c 100644 --- a/tests/test_report.py +++ b/tests/test_report.py @@ -185,6 +185,29 @@ def test_render_table_section_omits_empty_chart_placeholder(tmp_path): assert "No chartable values were recorded for this section." not in html +def test_render_table_section_charts_later_numeric_rows(tmp_path): + source = tmp_path / "fit_diagnostics.json" + out = tmp_path / "report.html" + item_ids = list(range(13)) + outfit = [None] * 12 + [1.2] + source.write_text( + json.dumps( + { + "model_fit": {"loglik": -3.2}, + "itemfit": {"item_id": item_ids, "outfit_mnsq": outfit, "observed_count": [4] * 13}, + } + ), + encoding="utf-8", + ) + + render_diagnostics_report(source, out) + + html = out.read_text(encoding="utf-8") + assert '