Add vs-yesterday delta calculation via snapshot storage - #58
Merged
christabel888 merged 1 commit intoAug 28, 2026
Merged
Conversation
…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
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:StatDelta::compute(today, yesterday)returnspercent_change: Nonewhenyesterdayis missing or0.0(never panics/divides by zero/emitsinf/NaN), and doesn't assume the change is always positive.write_daily_snapshotupserts today's row (intended to ride on Add daily-active-accounts computation job in src/jobs #2's job).compute_summary_deltasdiffs today vs. yesterday for all four of Add /api/v1/stats/summary endpoint: DAA, tx count 24h, payment volume 24h, active soroban contracts #1'sstat fields (DAA, tx count, payment volume, active Soroban contracts).
cold-start case (zero prior snapshots) asserting every delta comes back
Nonerather than panicking.Note: this uses its own
daily_stat_snapshotstable rather than #45'snetwork_daily_metrics, since this PR needs to stand alone and #45 may notbe merged yet — the two tables cover overlapping fields; whoever merges
first should decide which becomes canonical.