docs(api): document GET /api/reports/week-comparison

Describe the session JSON endpoint used by the main dashboard week
comparison chart: partial Monday-to-today window, parallel prior week,
dense by_day series, and null change_percent when last week has no hours.

Note the path with other internal dashboard routes in API_VERSIONING.md.
This commit is contained in:
Dries Peeters
2026-04-27 17:53:54 +02:00
parent d7acfb9ff2
commit 07dbbd54a3
2 changed files with 36 additions and 1 deletions
+35
View File
@@ -296,6 +296,41 @@ Returns productivity aggregates for the **current user** only (completed time en
- **`last_7_days`:** seven objects in chronological order for the last seven **local** calendar days (app timezone), including days with **0** hours.
- **`estimated_value_tracked`:** `null` when the estimated billable total is zero or no rate applies; otherwise `hours ×` resolved rate using **`COALESCE(project.hourly_rate, entry client default, project client default)`** (see server implementation in `StatsService`). **`estimated_value_currency`** comes from **Settings → currency** with application default fallback.
#### This week vs last week (hours by day)
```
GET /api/reports/week-comparison
```
Returns a **partial calendar week** (Monday 00:00 local time through **now**) compared with the **same weekdays** in the previous week, for the **current user** only. Completed entries only (`end_time` is set). The week definition matches the main dashboard “Weeks hours” aggregate (`AnalyticsService.get_dashboard_stats`).
**Response (200):**
```json
{
"current_week": {
"total_hours": 18.5,
"by_day": [
{ "day": "2026-04-20", "hours": 6.0 },
{ "day": "2026-04-21", "hours": 4.25 }
]
},
"last_week": {
"total_hours": 22.0,
"by_day": [
{ "day": "2026-04-13", "hours": 5.0 },
{ "day": "2026-04-14", "hours": 7.5 }
]
},
"change_percent": -15.9
}
```
- **`by_day`:** dense list from week Monday through the comparison end date (this week through today; last week through the parallel weekday). Each **`day`** is an ISO date `YYYY-MM-DD`; **`hours`** is a float (including `0.0` for days with no entries).
- **`change_percent`:** percent change of **`current_week.total_hours`** vs **`last_week.total_hours`**, rounded to one decimal. **`null`** when last weeks total is zero (avoid division by zero).
The main dashboard renders this as a grouped bar chart (Chart.js) with a short summary line; data is loaded by `app/static/dashboard-enhancements.js` on dashboard refresh.
### Search
#### Global Search