Skip to content

Add vs-yesterday delta calculation via snapshot storage - #58

Merged
christabel888 merged 1 commit into
Stellar-Insightss:mainfrom
ndii-dev:issue-3-stat-delta-snapshots
Aug 28, 2026
Merged

Add vs-yesterday delta calculation via snapshot storage#58
christabel888 merged 1 commit into
Stellar-Insightss:mainfrom
ndii-dev:issue-3-stat-delta-snapshots

Conversation

@ndii-dev

Copy link
Copy Markdown

Closes #3

Adds migrations/031_create_daily_stat_snapshots.sql (daily_stat_snapshots,
one row per UTC calendar day) and src/analytics/stat_deltas.rs:

Note: this uses its own daily_stat_snapshots table rather than #45's
network_daily_metrics, since this PR needs to stand alone and #45 may not
be merged yet — the two tables cover overlapping fields; whoever merges
first should decide which becomes canonical.

…tellar-Insightss#3)

New daily_stat_snapshots table (migration 031) + src/analytics/stat_deltas.rs:
StatDelta::compute guards yesterday==0/missing (returns None, never panics
or divides by zero), write_daily_snapshot upserts today's row, and
compute_summary_deltas diffs today vs yesterday for all four Stellar-Insightss#1 stat
fields. Covered by a 2-day fixture test and a cold-start (no prior
snapshot) test.
@christabel888
christabel888 merged commit 46e7f8d into Stellar-Insightss:main Aug 28, 2026
christabel888 pushed a commit to ndii-dev/backend that referenced this pull request Aug 28, 2026
Conflict in src/cache.rs was a trivial comment wording difference,
resolved by keeping the grammatically-correct plural.

Also fixed a real bug this merge chain exposed: Stellar-Insightss#54 and Stellar-Insightss#58 (both
already merged to main) independently numbered their migrations 031
(031_create_network_metrics_timeseries.sql and
031_create_daily_stat_snapshots.sql). sqlx::migrate! requires unique
version numbers per migration, so main was left in a broken state.
Renumbered the latter to 034_create_daily_stat_snapshots.sql (the
next free slot after 032/033) — no code or other migration references
the old filename.

Verified with cargo check (clean).
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.

Add vs-yesterday delta calculation via previous-day snapshot storage

3 participants