Skip to content

Group stats by source kind and add rolling event counts per station - #17

Merged
bkeepers merged 2 commits into
mainfrom
source-kinds
Aug 23, 2026
Merged

Group stats by source kind and add rolling event counts per station#17
bkeepers merged 2 commits into
mainfrom
source-kinds

Conversation

@bkeepers

Copy link
Copy Markdown
Member

/v1/stats listed every API client, UDP sender and HTTP feeder as its own source, so our own feeds showed up as a dozen v1:ed25519:… and udp:… entries next to each upstream. They now roll up into one entry per kind: v1, udp, http, mmsi, with the upstreams keeping their names. Event windows are summed per kind, vessels and vessels_exclusive are unioned per kind, and last_age_s is the youngest member.

Each row in /v1/stations now carries events as {"last_24h", "last_7d"} from the same 7-day hourly ring that backs /v1/stats. That ring replaces the 24-hour one the earned feeder tier used, so the tier reads the same numbers. Station rings are saved in the usage file and re-attached when a station reports again after a restart, so a deploy neither zeroes a feeder's counts nor lists stations that haven't reported since. duplicates and positions remain since first heard.

The viewer's station panel shows the 24-hour count; docs/API.md describes both shapes. Tests cover the per-kind grouping, a source that only ever duplicates, and the station-ring restore.

Every API publisher, UDP sender and HTTP feeder rolls up into one source kind (v1, udp, http, mmsi) in /v1/stats; upstreams keep their name. Event rings, vessel counts and last-event age are per kind.

Each /v1/stations row reports events over the last 24 hours and 7 days from the same hourly ring, which replaces the 24-hour ring behind the earned feeder tier. Station rings persist in the usage file and re-attach when the station reports again after a restart.
Copilot AI lite review requested due to automatic review settings August 23, 2026 13:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates AISCast’s usage and station statistics so /v1/stats and /v1/stations present more actionable aggregates: sources are rolled up by “source kind” (e.g., v1, udp, http, mmsi, plus upstream names), and stations now expose rolling event-window counts derived from the same 7‑day hourly ring used for stats and persisted across restarts.

Changes:

  • Roll up /v1/stats.sources by source kind, unioning vessel sets and summing event windows per kind.
  • Replace per-station 24h buckets with the shared 7‑day hourly ring and expose events: {last_24h, last_7d} on /v1/stations (persisted in the usage file and restored on restart).
  • Update viewer and API docs/tests to match the new events shape.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
viewer/index.html Updates station panel to display events.last_24h.
server/stats.go Persists/restores station rings; groups stats sources by kind; adjusts stats payload shapes.
server/stats_test.go Updates per-kind expectations and adds restart/restore test for station rings.
server/stations.go Introduces 7‑day hourRing for station events, adds ring persistence/restore, and groups vessel counts by source kind.
server/pipeline.go Records usage events per source kind (via sourceKind).
server/hub_test.go Updates station stats assertions to new events map shape.
docs/API.md Updates examples and endpoint documentation for the new events and per-kind sources shapes.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread server/stats.go Outdated
@bkeepers
bkeepers merged commit 52ca975 into main Aug 23, 2026
3 checks passed
@bkeepers
bkeepers deleted the source-kinds branch August 23, 2026 13:36
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