Repository navigation
perf(server): use monthly serving models #2029
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 19 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
cfef569
perf(analytics): bound power curve builds
Asherlc b69e412
test(analytics): update power eligibility fixture
Asherlc e81b6ed
docs(ops): record SAST registry outage
Asherlc c51911e
Merge remote-tracking branch 'origin/main' into Asherlc/use-subagents
Asherlc c6beae1
fix(analytics): preserve bounded power progress
Asherlc f86b76e
fix(analytics): order ClickHouse FINAL clause
Asherlc b59a46e
test(analytics): isolate power progress fixtures
Asherlc 6c9446c
test(analytics): match power lifecycle schema
Asherlc 33b6dc1
Merge remote-tracking branch 'origin/main' into Asherlc/use-subagents
Asherlc ea8efc6
fix(mobile): defer background WHOOP init
Asherlc d0d3d7f
fix(mobile): serialize initial WHOOP sync
Asherlc d13fe4f
fix(mobile): stop WHOOP sync on background
Asherlc 8177587
test(mobile): await WHOOP stream startup
Asherlc de3ed01
Merge remote-tracking branch 'origin/main' into Asherlc/use-subagents
Asherlc c6fb426
fix(analytics): accept current dbt statuses
Asherlc 6b14d54
Merge remote-tracking branch 'origin/main' into Asherlc/use-subagents
Asherlc a867312
perf(server): use monthly serving models
Asherlc 3783b5e
refactor(server): drop report timezone input
Asherlc 5aab1d4
test(server): cover report serving lifecycle
Asherlc f833747
docs(perf): record report query evidence
Asherlc fbdb8db
test(server): verify report query bindings
Asherlc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
160 changes: 160 additions & 0 deletions
160
packages/server/src/repositories/monthly-report-repository.integration.test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| import { afterAll, beforeAll, describe, expect, it } from "vitest"; | ||
| import { setupTestDatabase, type TestContext } from "../../../../src/db/test-helpers.ts"; | ||
| import { | ||
| createClickHouseTestActivitySensorStore, | ||
| executeClickHouseTestCommand, | ||
| } from "../routers/clickhouse-integration-test-helpers.ts"; | ||
| import type { ActivitySensorStore } from "./activity-repository.ts"; | ||
| import { MonthlyReportRepository } from "./monthly-report-repository.ts"; | ||
|
|
||
| const userId = "77777777-7777-4777-8777-777777777777"; | ||
| const activityId = "88888888-8888-4888-8888-888888888888"; | ||
|
|
||
| describe("MonthlyReportRepository ClickHouse read models", () => { | ||
| let testContext: TestContext; | ||
| let sensorStore: ActivitySensorStore; | ||
|
|
||
| beforeAll(async () => { | ||
| testContext = await setupTestDatabase(); | ||
| sensorStore = await createClickHouseTestActivitySensorStore(testContext); | ||
|
|
||
| await executeClickHouseTestCommand( | ||
| testContext, | ||
| `INSERT INTO analytics.activity_summary ( | ||
| activity_id, | ||
| user_id, | ||
| activity_type, | ||
| started_at, | ||
| ended_at, | ||
| avg_hr, | ||
| max_hr | ||
| ) VALUES ( | ||
| toUUID('${activityId}'), | ||
| toUUID('${userId}'), | ||
| 'cycling', | ||
| toDateTime64(toStartOfMonth(today()) + INTERVAL 5 DAY, 6, 'UTC'), | ||
| toDateTime64(toStartOfMonth(today()) + INTERVAL 5 DAY + INTERVAL 1 HOUR, 6, 'UTC'), | ||
| 100, | ||
| 200 | ||
| )`, | ||
| ); | ||
| await executeClickHouseTestCommand( | ||
| testContext, | ||
| `INSERT INTO analytics.daily_sleep ( | ||
| user_id, | ||
| date, | ||
| provider_id, | ||
| started_at, | ||
| duration_minutes, | ||
| refresh_version, | ||
| is_deleted, | ||
| refreshed_at | ||
| ) VALUES ( | ||
| toUUID('${userId}'), | ||
| toDate(toStartOfMonth(today()) + INTERVAL 5 DAY), | ||
| 'test-provider', | ||
| toDateTime64(toStartOfMonth(today()) + INTERVAL 5 DAY, 6, 'UTC'), | ||
| 300, | ||
| 1, | ||
| 0, | ||
| now64(9) | ||
| ), ( | ||
| toUUID('${userId}'), | ||
| toDate(toStartOfMonth(today()) + INTERVAL 5 DAY), | ||
| 'test-provider', | ||
| toDateTime64(toStartOfMonth(today()) + INTERVAL 5 DAY, 6, 'UTC'), | ||
| 480, | ||
| 2, | ||
| 0, | ||
| now64(9) | ||
| ), ( | ||
| toUUID('${userId}'), | ||
| toDate(toStartOfMonth(today()) + INTERVAL 6 DAY), | ||
| 'test-provider', | ||
| toDateTime64(toStartOfMonth(today()) + INTERVAL 6 DAY, 6, 'UTC'), | ||
| 600, | ||
| 1, | ||
| 0, | ||
| now64(9) | ||
| ), ( | ||
| toUUID('${userId}'), | ||
| toDate(toStartOfMonth(today()) + INTERVAL 6 DAY), | ||
| 'test-provider', | ||
| toDateTime64(toStartOfMonth(today()) + INTERVAL 6 DAY, 6, 'UTC'), | ||
| 600, | ||
| 2, | ||
| 1, | ||
| now64(9) | ||
| )`, | ||
| ); | ||
| await executeClickHouseTestCommand( | ||
| testContext, | ||
| `INSERT INTO analytics.daily_recovery ( | ||
| user_id, | ||
| date, | ||
| hrv, | ||
| resting_hr, | ||
| is_deleted, | ||
| refresh_version, | ||
| refreshed_at | ||
| ) VALUES ( | ||
| toUUID('${userId}'), | ||
| toDate(toStartOfMonth(today()) + INTERVAL 5 DAY), | ||
| 40, | ||
| 60, | ||
| 0, | ||
| 1, | ||
| now64(9) | ||
| ), ( | ||
| toUUID('${userId}'), | ||
| toDate(toStartOfMonth(today()) + INTERVAL 5 DAY), | ||
| 60, | ||
| 50, | ||
| 0, | ||
| 2, | ||
| now64(9) | ||
| ), ( | ||
| toUUID('${userId}'), | ||
| toDate(toStartOfMonth(today()) + INTERVAL 6 DAY), | ||
| 80, | ||
| 45, | ||
| 0, | ||
| 1, | ||
| now64(9) | ||
| ), ( | ||
| toUUID('${userId}'), | ||
| toDate(toStartOfMonth(today()) + INTERVAL 6 DAY), | ||
| 80, | ||
| 45, | ||
| 1, | ||
| 2, | ||
| now64(9) | ||
| )`, | ||
| ); | ||
|
|
||
| for (const recursiveView of ["v_activity", "v_sleep", "v_daily_metrics"]) { | ||
| await executeClickHouseTestCommand(testContext, `DROP TABLE analytics.${recursiveView} SYNC`); | ||
| } | ||
| }, 120_000); | ||
|
|
||
| afterAll(async () => { | ||
| await testContext?.cleanup(); | ||
| }); | ||
|
|
||
| it("builds the report from compact serving models without recursive views", async () => { | ||
| const report = await new MonthlyReportRepository(userId, sensorStore).getReport(12); | ||
|
|
||
| expect(report.current).toEqual({ | ||
| monthStart: `${new Date().toISOString().slice(0, 7)}-01`, | ||
| trainingHours: 1, | ||
| activityCount: 1, | ||
| avgDailyStrain: 30, | ||
| avgSleepMinutes: 480, | ||
| avgRestingHr: 50, | ||
| avgHrv: 60, | ||
| trainingHoursTrend: null, | ||
| avgSleepTrend: null, | ||
| }); | ||
| expect(report.history).toHaveLength(12); | ||
| }); | ||
| }); | ||
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.