Skip to content

fix(analytics): Packets / Hour readable on long histories (#2193) - #39

Closed
A13xB0 wants to merge 6 commits into
masterfrom
fix/packets-per-hour-long-span
Closed

A13xB0 wants to merge 6 commits into
masterfrom
fix/packets-per-hour-long-span

Conversation

@A13xB0

@A13xB0 A13xB0 commented Oct 12, 2026 •

Copy link
Copy Markdown
Owner

Fixes Kpa-clawbot#2193 (in the fork for review; not submitted upstream).

Problem

On an instance that keeps months of packets, the Overview tab's Packets / Hour chart becomes unreadable: 2,932 hourly bars in 720 units of plot, a date label every day, and the hours with no packets (which the server leaves out) squeezed off the axis.

Before and after

Both use the real /api/analytics/rf answer from the instance in the issue (2,933 hourly buckets over 124 days), served to the page in place of the fixture's own.

Before (master, page on "All data"):

before

After, same data:

after

Phone:

A short store (pre-prod, 7 days in memory, plus a few old packets a day for weeks before that because they were heard again). The chart starts where the real data does:

short store

Change

All in public/analytics.js; no API change.

  • packetsPerHourCard() replaces the inline block:
    • rolls the hours up to hourly, 6-hourly, daily or weekly bars, at most 180, and titles the card to match (Packets / Day);
    • counts missing hours as zero;
    • puts about 10 labels on round UTC times;
    • starts on the first UTC day with at least 2% of a typical recent day (the median of the last seven whole days), at its first hour with a tenth of a typical hour. Scanning forward, an outage after the start is never taken for it.
  • Theme refresh before the data: every load fires theme-refresh about 300 ms after the theme resolves, and the page re-rendered the current tab on it. When the analytics answers came later (a busy or just-restarted server), the Overview was drawn from an empty object and threw Cannot read properties of undefined (reading 'totalTransmissions'). It now skips that refresh until the data has landed; loadAnalytics() renders the tab with the current theme when it does.

The span is still picked by the page's time window.

Tests

  • tests/unit/test-issue-2193-packets-per-hour.js (in test-all.sh, red then green): 122 days gives 123 daily bars with 4 to 12 labels; 7 days gives 168 hourly bars; missing hours are drawn as zero; the chart starts at the data, not at the stragglers, and not after an outage; no data says so.
  • The theme-refresh guard has no test of its own: it's a three-line early return, and the commit message explains the race.
  • sh test-all.sh passes; the Neighbor-graph filter E2E fails under CI load: skip-message transition is undone by a later re-render (#1758 lifecycle) Kpa-clawbot/CoreScope#1925 neighbour-graph theme-refresh test and the analytics chart test still pass; the screenshots show no page errors and no sideways scroll at 1280 px or 390 px.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KaR4xu8gVykQBkH8yG8m6H

@A13xB0 A13xB0 added bug Something isn't working upstream: not submitted Fork only so far; not opened upstream live: pre-prod In the image running on CoreScope pre-production labels Oct 12, 2026
@A13xB0 A13xB0 changed the title fix(analytics): Packets / Hour readable on long histories, bounded to 7 days / 30 days / All (#2193) fix(analytics): Packets / Hour readable on long histories (#2193) Oct 12, 2026
A13xB0 and others added 2 commits October 12, 2026 21:02
…-clawbot#2193)

Months of hours should roll up to daily bars with a handful of labels,
missing hours count as zero, and the chart should start where the data
does rather than at the few old packets a short store keeps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KaR4xu8gVykQBkH8yG8m6H
…t#2193)

A long history now rolls up to coarser bars (hourly, 6-hourly, daily or
weekly; at most 180) with about 10 labels on round UTC times, missing hours
count as zero, and the title follows the bucket (Packets / Day). The chart
starts where the data does: a short store also keeps a few old packets
that were heard again, weeks before the rest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KaR4xu8gVykQBkH8yG8m6H
@A13xB0
A13xB0 force-pushed the fix/packets-per-hour-long-span branch from 8097f97 to 350fd8c Compare October 12, 2026 20:06
Every load fires a theme-refresh about 300ms after the theme resolves, and
the page re-rendered the current tab on it. On a slow or just-restarted
server the analytics answers land later, so the Overview was drawn from
the empty data object and threw (reading 'totalTransmissions').
loadAnalytics() renders the tab, with the current theme, once the answers
land, so the early refresh has nothing to do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KaR4xu8gVykQBkH8yG8m6H
@A13xB0
A13xB0 force-pushed the fix/packets-per-hour-long-span branch from 350fd8c to 9878913 Compare October 12, 2026 20:21
@A13xB0 A13xB0 added upstream: in review Open as a PR on Kpa-clawbot/CoreScope, waiting on review and removed upstream: not submitted Fork only so far; not opened upstream labels Oct 12, 2026
@A13xB0

A13xB0 commented Oct 12, 2026

Copy link
Copy Markdown
Owner Author

Submitted upstream as Kpa-clawbot#2194.

A13xB0 and others added 3 commits October 15, 2026 10:19
… alone

Regression test for 9878913. Drives init() with answers that never land,
fires the captured theme-refresh handler, and checks that nothing throws
and the tab is not re-rendered. Without the guard it fails with the
production error (reading 'totalTransmissions').

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KaR4xu8gVykQBkH8yG8m6H
…d says so

Review on Kpa-clawbot#2194: the start crop also cut a genuinely quieter early stretch
inside a window the user picked (90 days, the first 30 quiet: 30 days
hidden), and nothing on the card said so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KaR4xu8gVykQBkH8yG8m6H
In a picked window the server has already cut the data to it, so a quieter
early stretch is real: the chart now starts at the window's first hour.
Under "All data" the straggler crop stays, and the card title says
"since MM-DD" when it applies. The renderer gets the window the data was
fetched with from _analyticsData. Also corrects the comment on which seven
days set the floor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KaR4xu8gVykQBkH8yG8m6H
@A13xB0 A13xB0 added upstream: merged Merged into Kpa-clawbot/CoreScope master and removed upstream: in review Open as a PR on Kpa-clawbot/CoreScope, waiting on review labels Oct 18, 2026
@A13xB0

A13xB0 commented Oct 18, 2026

Copy link
Copy Markdown
Owner Author

Merged upstream as Kpa-clawbot#2194; closing.

@A13xB0 A13xB0 closed this Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working live: pre-prod In the image running on CoreScope pre-production upstream: merged Merged into Kpa-clawbot/CoreScope master

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Analytics: Packets / Hour chart unreadable on long-retention instances (labels overlap, bars stack)

1 participant