[kimi] Refactor scorecards.py — break up oversized functions (#1127) #1152

Merged
Rockachopa merged 1 commits from kimi/issue-1127 into main 2026-03-23 18:59:06 +00:00
Collaborator

Fixes #1127

Summary

Refactored src/dashboard/routes/scorecards.py to break up two functions over 100 lines each.

Changes

Extracted Helpers

  • _parse_period() - Period parsing with fallback to daily
  • _format_token_display() - Token formatting with +/- prefix
  • _format_token_class() - CSS class based on token sign
  • _build_patterns_html() - Pattern section HTML builder
  • _build_narrative_html() - Narrative bullets HTML builder
  • _build_metrics_row_html() - Metrics row HTML builder
  • _render_scorecard_panel() - Single panel renderer
  • _render_empty_scorecard() - Empty state renderer
  • _render_error_scorecard() - Error state renderer
  • _render_single_panel_wrapper() - Single panel wrapper with null handling
  • _render_all_panels_grid() - Grid layout for all panels

Line Count Reduction

Function Before After
agent_scorecard_panel() 108 lines 26 lines
all_scorecard_panels() 106 lines 26 lines

Acceptance Criteria

  • All 49 existing tests pass (pytest tests/dashboard/test_scorecards.py)
  • Dashboard scorecards render identically (same HTML output)
  • All extracted helpers have docstrings
  • Each function < 50 lines (target achieved)
Fixes #1127 ## Summary Refactored `src/dashboard/routes/scorecards.py` to break up two functions over 100 lines each. ## Changes ### Extracted Helpers - `_parse_period()` - Period parsing with fallback to daily - `_format_token_display()` - Token formatting with +/- prefix - `_format_token_class()` - CSS class based on token sign - `_build_patterns_html()` - Pattern section HTML builder - `_build_narrative_html()` - Narrative bullets HTML builder - `_build_metrics_row_html()` - Metrics row HTML builder - `_render_scorecard_panel()` - Single panel renderer - `_render_empty_scorecard()` - Empty state renderer - `_render_error_scorecard()` - Error state renderer - `_render_single_panel_wrapper()` - Single panel wrapper with null handling - `_render_all_panels_grid()` - Grid layout for all panels ### Line Count Reduction | Function | Before | After | |----------|--------|-------| | `agent_scorecard_panel()` | 108 lines | 26 lines | | `all_scorecard_panels()` | 106 lines | 26 lines | ### Acceptance Criteria - ✅ All 49 existing tests pass (`pytest tests/dashboard/test_scorecards.py`) - ✅ Dashboard scorecards render identically (same HTML output) - ✅ All extracted helpers have docstrings - ✅ Each function < 50 lines (target achieved)
kimi added 1 commit 2026-03-23 18:50:25 +00:00
refactor: Break up scorecards.py — two functions over 100 lines each
Some checks failed
Tests / lint (pull_request) Failing after 15s
Tests / test (pull_request) Has been skipped
e0f629d9c8
Extract shared logic into helpers:
- _parse_period(): Period parsing with fallback
- _format_token_display(): Token formatting with +/-
- _format_token_class(): CSS class based on token sign
- _build_patterns_html(): Pattern section HTML
- _build_narrative_html(): Narrative bullets HTML
- _build_metrics_row_html(): Metrics row HTML
- _render_scorecard_panel(): Single panel renderer
- _render_empty_scorecard(): Empty state renderer
- _render_error_scorecard(): Error state renderer
- _render_single_panel_wrapper(): Single panel wrapper
- _render_all_panels_grid(): Grid layout for all panels

Before:
- agent_scorecard_panel(): 108 lines
- all_scorecard_panels(): 106 lines

After:
- agent_scorecard_panel(): 26 lines
- all_scorecard_panels(): 26 lines

All helpers have docstrings. All 49 tests pass.

Fixes #1127
Rockachopa merged commit 382dd041d9 into main 2026-03-23 18:59:06 +00:00
Rockachopa deleted branch kimi/issue-1127 2026-03-23 18:59:06 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Rockachopa/Timmy-time-dashboard#1152