Repository navigation
fix(wallet): report the dashboard net over the month, not over the 7-day series - #193
Merged
Merged
Conversation
…day series
`GET /api/dashboard` returned a `net` computed as `SUM(series)` — the last 7 days —
while the per-type `month` rows it is displayed above are a calendar-month aggregate,
and the row is labelled 本月净变化 / "Net change this month". The panel's total
therefore did not equal the rows directly beneath it (on the dashboard and on the
wallet page), and the 净 row could count the previous month's activity (day of
month <= 6) or miss this month's earlier activity (day of month >= 9).
`net` is now the signed sum of the `month` rows the handler already fetched —
income = `type IN ('earn','topup','gift')`, otherwise expense — the same
convention as the sparkline CASE, `transactions_trend`'s net column and
`routes/ops.rs`'s month flow. `series` is unchanged (the sparkline's source),
and the handler/module docs now name both windows.
Display-only: no settlement or enforcement path reads `net`.
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.
Summary
GET /api/dashboardreturned anetthat was computed over a different window than the row that displays it.netwasSUM(series)= the last 7 days, while the per-typemonthrows it sits above are a calendar-month aggregate — and the row is labelled 「本月净变化」 / "Net change this month", inside a card titled 「本月点数变化」 / "Month point changes".So the panel's total did not equal the rows directly beneath it, on the dashboard (
#dash-month-changes) and on the wallet page (#month-changes). It also drifted in both directions across the month: on day of month ≤ 6 the 7-day window still contains days of the previous month, and on day ≥ 9 a row from earlier in this month falls outside the 7-day window.netis now the signed sum of themonthrows the handler has already fetched — income =type IN ('earn','topup','gift'), otherwise expense — the same convention as the sparklineCASE,transactions_trend'snetcolumn androutes/ops.rs's month flow.seriesis unchanged (it is the sparkline's source, correctly labelled as 7 days), no new query is issued, and the frontend needs no change (it already readsLive.dashboard.net).Severity: display-only, not money. No settlement or enforcement path reads
net; storedptsand the other aggregates were already correct.Related Issue
None — no issue exists for this, and none is fabricated. Verified
closingIssuesReferencesis empty on purpose.Changes
src/routes/wallet.rs::dashboard:net= signed sum of the already-fetchedmonthrows (type-based direction), instead ofseries.iter()…sum()month/net= calendar month;series= last 7 days)config.example.tomlimpact); noui/change; no i18n keyTests
cargo test— 181 passed (baseline 180 + 1 new)cargo fmt --check— cleancargo clippy --all-targets -- -D warnings— cleanroutes::wallet::tests::dashboard_net_is_the_month_net_not_the_7_day_seriesThe new test drives the real handler through the router. Its fixture straddles both windows with pure data (no clock faking):
consume 10.0atstart of month(always in the month; inside the 7-day window only when day of month ≤ 7),consume 4.0atnow -6 days(always in the 7-day window; inside the month only when day of month ≥ 7),earn 3.0today (always in both). The assertion is the specification, computed independently by SQL in the test, not a copy of the implementation expression:Observed today (day 13), the fixture is discriminating:
A/B: reverting only the
netcomputation back toseries⇒ exactly this one assertion red / 180 green (it reportsnet = -1where the month spec is-11).Calibration recorded in the test comment: the two windows coincide on day 7 of a month (the window is then exactly days 1..7 ⊆ the month), so on that single day any data-only fixture is non-discriminating. The assertion is still the specification; no clock hack was added to force divergence.
Checklist
fix/)fix(wallet): …)