Commit 1abb045
fix(backend): weekly score window is 7 days, not 8 (off-by-one) (#10015)
get_scores() documents its weekly window as "tasks created in the 7 days
ending on that date", but builds it as:
day_end = day + timedelta(days=1)
week_start = day - timedelta(days=7) # created_at in [day-7, day+1)
[day-7, day+1) spans 8 calendar days (day-7 .. day inclusive), so every task
created on the day-7 date is counted in the weekly totals, inflating
weekly.total_tasks and skewing weekly.score.
The adjacent daily window is built as [day, day+1) — exactly one day — which
fixes the intended construction: an N-day window ending on `day` is
[day-(N-1), day+1). For the 7-day weekly window that is [day-6, day+1).
Fix: week_start = day - timedelta(days=6). This preserves the created_at
field choice (the "matches Rust backend which uses created_at" comment is
about the field, not the window; the Rust backend has no weekly-score
window) and only corrects the span from 8 to 7 days.
Test: the existing get_scores coverage only asserted the query uses the
created_at field, never the window bounds. Added
test_weekly_window_spans_seven_days_ending_on_date, which captures the
FieldFilter calls and asserts the created_at lower bound for date=2026-07-19
is 2026-07-13 (day-6), not 2026-07-12 (day-7).
Verification: exercised the real get_scores with a mocked db + FieldFilter
tracker -> created_at >= 2026-07-13 (7-day span); reverting the one-line fix
yields 2026-07-12 (8-day span) and the new assertion fails.
black --line-length 120 --check: clean.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 177117a commit 1abb045
2 files changed
Lines changed: 39 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1058 | 1058 | | |
1059 | 1059 | | |
1060 | 1060 | | |
1061 | | - | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
1062 | 1065 | | |
1063 | 1066 | | |
1064 | 1067 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1634 | 1634 | | |
1635 | 1635 | | |
1636 | 1636 | | |
| 1637 | + | |
| 1638 | + | |
| 1639 | + | |
| 1640 | + | |
| 1641 | + | |
| 1642 | + | |
| 1643 | + | |
| 1644 | + | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
| 1654 | + | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + | |
| 1658 | + | |
| 1659 | + | |
| 1660 | + | |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
| 1665 | + | |
| 1666 | + | |
| 1667 | + | |
| 1668 | + | |
| 1669 | + | |
| 1670 | + | |
| 1671 | + | |
1637 | 1672 | | |
1638 | 1673 | | |
1639 | 1674 | | |
| |||
0 commit comments