API: GET /api/stats endpoint #4

Open
opened 2026-03-28 02:09:49 +00:00 by forgejo_admin · 0 comments

Type

Feature

Lineage

Standalone — scoped from Daily 100 design spec.

Repo

forgejo_admin/daily-100-api

User Story

As a user
I want computed stats about my progress
So that I can see streaks, level, and completion rate

Context

GET /api/stats returns all derived statistics computed from daily_entries. Fields: perfect_days (count of 8/8 days), current_streak (consecutive days with score > 0), best_streak, perfect_streak (consecutive 8/8 days), best_perfect_streak, completion_rate (checked items / total possible * 100), level, level_title, next_level, next_level_at, level_progress. Level thresholds by perfect days: 1=Rookie, 7=Regular, 21=Committed, 50=Warrior, 100=Machine, 200=Legend, 365=Immortal.

File Targets

Files the agent should modify or create:

  • app/routes/stats.py -- GET endpoint handler
  • app/services/stats.py -- stats computation logic

Files the agent should NOT touch:

  • app/models.py -- already defined
  • app/routes/today.py -- separate concern

Acceptance Criteria

  • All stat fields computed correctly from daily_entries
  • Level calculation uses exponential curve thresholds
  • Streak calculation handles gaps correctly
  • completion_rate = total_checked / (total_days * 8) * 100
  • Returns zeros/defaults when no data exists

Test Expectations

  • Unit test: empty database returns sensible defaults
  • Unit test: perfect streak calculation with gaps
  • Unit test: level boundary transitions
  • Unit test: completion rate with mixed data
  • Run command: pytest tests/test_stats.py

Constraints

  • All stats computed from queries, never stored
  • Use CTEs or window functions for streak calculation
  • Level progress is a float 0.0-1.0

Checklist

  • PR opened
  • Tests pass
  • No unrelated changes
  • daily-100 -- project
### Type Feature ### Lineage Standalone — scoped from Daily 100 design spec. ### Repo `forgejo_admin/daily-100-api` ### User Story As a user I want computed stats about my progress So that I can see streaks, level, and completion rate ### Context GET /api/stats returns all derived statistics computed from daily_entries. Fields: perfect_days (count of 8/8 days), current_streak (consecutive days with score > 0), best_streak, perfect_streak (consecutive 8/8 days), best_perfect_streak, completion_rate (checked items / total possible * 100), level, level_title, next_level, next_level_at, level_progress. Level thresholds by perfect days: 1=Rookie, 7=Regular, 21=Committed, 50=Warrior, 100=Machine, 200=Legend, 365=Immortal. ### File Targets Files the agent should modify or create: - `app/routes/stats.py` -- GET endpoint handler - `app/services/stats.py` -- stats computation logic Files the agent should NOT touch: - `app/models.py` -- already defined - `app/routes/today.py` -- separate concern ### Acceptance Criteria - [ ] All stat fields computed correctly from daily_entries - [ ] Level calculation uses exponential curve thresholds - [ ] Streak calculation handles gaps correctly - [ ] completion_rate = total_checked / (total_days * 8) * 100 - [ ] Returns zeros/defaults when no data exists ### Test Expectations - [ ] Unit test: empty database returns sensible defaults - [ ] Unit test: perfect streak calculation with gaps - [ ] Unit test: level boundary transitions - [ ] Unit test: completion rate with mixed data - Run command: `pytest tests/test_stats.py` ### Constraints - All stats computed from queries, never stored - Use CTEs or window functions for streak calculation - Level progress is a float 0.0-1.0 ### Checklist - [ ] PR opened - [ ] Tests pass - [ ] No unrelated changes ### Related - `daily-100` -- project
Commenting is not possible because the repository is archived.
No labels
No milestone
No project
No assignees
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ldraney/daily-100-api#4
No description provided.