Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/server/src/routers/recovery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1421,11 +1421,11 @@ describe("recoveryRouter.strainTarget", () => {
});
}

it("omits the strain target when no recovery summary exists", async () => {
it("returns null when no recovery summary exists", async () => {
const caller = setup({ readinessRows: [] });
const result = await caller.strainTarget({});

expect(result).toBeUndefined();
expect(result).toBeNull();
});

it("reads daily loads from the compact activity load read model", async () => {
Expand Down
35 changes: 19 additions & 16 deletions packages/server/src/routers/recovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,22 @@ export interface ReadinessRow {
weights: ReadinessWeights;
}

export interface StrainTargetResult {
targetStrain: number;
currentStrain: number;
currentStrainSource?: "activity" | "none";
currentPhysiologyLoad?: number | null;
progressPercent: number;
zone: "Push" | "Maintain" | "Recovery";
explanation: string;
dailyLoad?: number;
acuteLoad?: number;
chronicLoad?: number;
workloadRatio?: number | null;
readinessScore?: number;
}
const strainTargetResultSchema = z.object({
targetStrain: z.number(),
currentStrain: z.number(),
currentStrainSource: z.enum(["activity", "none"]).optional(),
currentPhysiologyLoad: z.number().nullable().optional(),
progressPercent: z.number(),
zone: z.enum(["Push", "Maintain", "Recovery"]),
explanation: z.string(),
dailyLoad: z.number().optional(),
acuteLoad: z.number().optional(),
chronicLoad: z.number().optional(),
workloadRatio: z.number().nullable().optional(),
readinessScore: z.number().optional(),
});

export type StrainTargetResult = z.infer<typeof strainTargetResultSchema>;

const strainTargetReadinessRowSchema = z.object({
date: dateStringSchema,
Expand Down Expand Up @@ -605,7 +607,8 @@ export const recoveryRouter = router({
*/
strainTarget: cachedProtectedQuery({ maxAge: CacheTTL.MEDIUM })
.input(z.object({ days: z.number().default(30), endDate: endDateSchema }))
.query(async ({ ctx, input }): Promise<StrainTargetResult | undefined> => {
.output(strainTargetResultSchema.nullable())
.query(async ({ ctx, input }): Promise<StrainTargetResult | null> => {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
Comment thread
qodo-code-review[bot] marked this conversation as resolved.
Resolved
const sensorStore = requireSensorStore(ctx.sensorStore, "recovery.strainTarget");
const recoveryAccessWindowClause =
ctx.accessWindow?.kind === "limited"
Expand Down Expand Up @@ -678,7 +681,7 @@ export const recoveryRouter = router({
);

const readinessMetrics = readinessRows[0];
if (!readinessMetrics) return undefined;
if (!readinessMetrics) return null;

const params = getEffectiveParams(await loadPersonalizedParams(ctx.db, ctx.userId));
const components: ReadinessComponents = {
Expand Down
4 changes: 2 additions & 2 deletions packages/web/src/components/DailyOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface DailyOverviewProps {
readiness: ReadinessRow[] | undefined;
workloadRatio: WorkloadRatioResult | undefined;
sleepPerformance: SleepPerformanceInfo | null | undefined;
strainTarget?: StrainTargetResult | undefined;
strainTarget?: StrainTargetResult | null;
readinessLoading?: boolean;
workloadLoading?: boolean;
strainTargetLoading?: boolean;
Expand Down Expand Up @@ -217,7 +217,7 @@ function StrainBreakdown({
strainTarget,
}: {
workloadRatio: WorkloadRatioResult;
strainTarget?: StrainTargetResult;
strainTarget?: StrainTargetResult | null;
}) {
const today = workloadRatio.timeSeries[workloadRatio.timeSeries.length - 1];
const acuteLoad = today?.acuteLoad ?? 0;
Expand Down
Loading