Skip to content

fix(dashboard): use start bound for hourly chart date filter#113

Open
sivlek14 wants to merge 2 commits into
phuryn:mainfrom
sivlek14:fix/hourly-chart-date-filter
Open

fix(dashboard): use start bound for hourly chart date filter#113
sivlek14 wants to merge 2 commits into
phuryn:mainfrom
sivlek14:fix/hourly-chart-date-filter

Conversation

@sivlek14
Copy link
Copy Markdown

@sivlek14 sivlek14 commented May 8, 2026

Summary

applyFilter() destructures { start, end } from getRangeBounds(selectedRange) and uses them consistently for the daily chart and session filters — but the hourly chart filter referenced an undefined cutoff variable:

// before
const hourlySrc = (rawData.hourly_by_model || []).filter(r =>
  selectedModels.has(r.model) && (!cutoff || r.day >= cutoff)   // ← ReferenceError
);

// after
const hourlySrc = (rawData.hourly_by_model || []).filter(r =>
  selectedModels.has(r.model) && (!start || r.day >= start)
);

Under any active date range (anything other than "all"), this threw a ReferenceError, causing the "Average Hourly Distribution" chart to silently empty.

A static regression test is added to tests/test_dashboard.py that asserts cutoff is absent from HTML_TEMPLATE and that the hourly filter uses the start bound.

Test plan

  • python3 -m unittest tests.test_dashboard.TestApplyFilterHourlyRegression -v — two new tests pass
  • python3 -m unittest discover -s tests -v — full suite green (96 tests)
  • Manual: open the dashboard, select any date range other than "All time", confirm the "Average Hourly Distribution" chart populates correctly

🤖 Generated with Claude Code

applyFilter() destructures { start, end } from getRangeBounds() but the
hourly filter referenced an undefined `cutoff` variable.  Under any active
date range this threw a ReferenceError, silently emptying the
"Average Hourly Distribution" chart.  Fixed by using `start`, consistent
with the daily and sessions filters in the same function.

Adds a static regression test that asserts `cutoff` is absent from
HTML_TEMPLATE and that the hourly filter references the `start` bound.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 8, 2026 04:11
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a dashboard JavaScript runtime error in applyFilter() where the hourly chart filter referenced an undefined cutoff variable, and adds a Python regression test to prevent reintroducing the issue.

Changes:

  • Update the hourly chart data filter to use the start bound returned by getRangeBounds(selectedRange) instead of an undefined variable.
  • Add regression tests that inspect HTML_TEMPLATE to ensure the hourly filter uses start and does not reference cutoff.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
dashboard.py Fixes the hourly chart’s date-range filtering logic in the embedded JS template.
tests/test_dashboard.py Adds static regression tests to catch undefined-variable usage in the hourly filtering code.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread dashboard.py Outdated
Comment thread tests/test_dashboard.py
Comment on lines +272 to +277
def test_no_undefined_cutoff_in_template(self):
self.assertNotIn("cutoff", HTML_TEMPLATE)

def test_hourly_filter_uses_start_bound(self):
idx = HTML_TEMPLATE.index("hourlySrc")
snippet = HTML_TEMPLATE[idx:idx + 300]
Comment thread tests/test_dashboard.py
Comment on lines +275 to +278
def test_hourly_filter_uses_start_bound(self):
idx = HTML_TEMPLATE.index("hourlySrc")
snippet = HTML_TEMPLATE[idx:idx + 300]
self.assertIn("!start || r.day >= start", snippet)
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Comment thread tests/test_dashboard.py
date range caused a ReferenceError, silently emptying the hourly chart."""

def test_no_undefined_cutoff_in_template(self):
self.assertNotIn("cutoff", HTML_TEMPLATE)
Comment thread tests/test_dashboard.py
Comment on lines +275 to +280
def test_hourly_filter_uses_start_bound(self):
idx = HTML_TEMPLATE.index("hourlySrc")
snippet = HTML_TEMPLATE[idx:idx + 300]
self.assertIn("!start || r.day >= start", snippet)


Comment thread dashboard.py
Comment on lines 744 to 748
const hourlySrc = (rawData.hourly_by_model || []).filter(r =>
selectedModels.has(r.model) && (!cutoff || r.day >= cutoff)
selectedModels.has(r.model) &&
(!start || r.day >= start) &&
(!end || r.day <= end)
);
@sivlek14
Copy link
Copy Markdown
Author

sivlek14 commented May 8, 2026

@copilot apply changes based on the comments in this thread

@sivlek14
Copy link
Copy Markdown
Author

sivlek14 commented May 8, 2026

@copilot apply changes based on the comments in this thread

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants