Add period prediction accuracy feedback (P4.5 complete)
All checks were successful
Deploy / deploy (push) Successful in 1m36s

Implements visual feedback for cycle prediction accuracy in ICS calendar feeds:

- Add predictedDate field to PeriodLog type for tracking predicted vs actual dates
- POST /api/cycle/period now calculates and stores predictedDate based on
  previous lastPeriodDate + cycleLength, returns daysEarly/daysLate in response
- ICS feed generates "(Predicted)" events when actual period start differs
  from predicted, with descriptions like "period arrived 2 days early"
- Calendar route fetches period logs and passes them to ICS generator

This creates an accuracy feedback loop helping users understand their cycle
variability over time per calendar.md spec.

807 tests passing across 43 test files.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-11 22:21:52 +00:00
parent c708c2ed8b
commit 58f6c5605a
8 changed files with 442 additions and 45 deletions

View File

@@ -37,11 +37,26 @@ export async function GET(_request: NextRequest, { params }: RouteParams) {
);
}
// Fetch period logs for prediction accuracy display
const periodLogs = await pb.collection("period_logs").getFullList({
filter: `user = "${userId}"`,
sort: "-startDate",
});
// Generate ICS feed with 90 days of events (3 months)
const icsContent = generateIcsFeed({
lastPeriodDate: new Date(user.lastPeriodDate as string),
cycleLength: user.cycleLength as number,
monthsAhead: 3,
periodLogs: periodLogs.map((log) => ({
id: log.id,
user: log.user as string,
startDate: new Date(log.startDate as string),
predictedDate: log.predictedDate
? new Date(log.predictedDate as string)
: null,
created: new Date(log.created as string),
})),
});
// Return ICS content with appropriate headers