mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-12 14:16:12 +00:00
Maintainer-voice sweep across `src/`. ~190 references to the maintainer by first name in code comments and JSDoc neutralised to "the maintainer", "the live tenant", "users", or "the user" depending on context. Three sed passes covering ~50 distinct patterns (`Marc reported`, `Marc wants`, `Marc kept`, `Marc rolled back`, etc.). Test fixtures (`displayName: "Marc B."`, `username: "marc"`, `<HeroStrip userName="Marc">`) kept as opaque test data per the brief. CHANGELOG normalisation. The v1.4.14 + v1.4.15 entries paired a German bullet with its English translation by historical design — the in-app copy is English-default and the user docs are English, so the mixed-language style was a holdover from the early-marathon notes. A one-off node script extracted the `_..._` English paragraph from each bilingual bullet and rewrote the entry as that text. ~44 bullets reduced; one Docs bullet that lost a leading word in the regex fixed by hand. CLAUDE.md → CONTRIBUTING-AI.md rename so the filename is no longer AI-vendor-specific. `CONTRIBUTING.md` reference updated. `AGENTS.md` stays in place for multi-agent compatibility (the conventions doc is shared with Codex / Cursor / etc.). Wave-4 state wrap. STATE.md now records C1–C5 + D + D2 as complete; v1421-backlog.md grew a "Closed in v1.4.22" header listing the 20 items the marathon landed; `.planning/phase-W4-report.md` documents the per-commit decisions, test deltas, and the 23 items deferred to v1.4.23 with reasoning. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
56 lines
2.3 KiB
TypeScript
56 lines
2.3 KiB
TypeScript
/**
|
|
* Compute a 7-day trend delta from a metric summary.
|
|
*
|
|
* Backstory — v1.4.15 Fix 4 ("7-Tage-Schnitt" → "7-Tage-Trend"):
|
|
* the dashboard tiles labelled the 7-day average as "7T:" / "7d:"
|
|
* with the mean value beside it. the maintainer found that label unclear
|
|
* (sounded like an "average") when the goal of the tile is to
|
|
* convey *direction* over the past week. We re-use the existing
|
|
* 7-day linear-regression slope (already in `DataSummary.slope7`)
|
|
* and project a stable end-to-end delta as
|
|
*
|
|
* delta = slope.slope * 7 // units per day → unit delta over 7d
|
|
*
|
|
* The trend-card then paints the delta with metric-aware sentiment
|
|
* colour (up-good vs up-bad).
|
|
*
|
|
* v1.4.16 Fix A4: fall back to slope30 (projected onto 7 days) when
|
|
* slope7 is unavailable. Some metrics (mood, sleep) have <2 entries
|
|
* within the trailing 7-day window for users who don't log daily,
|
|
* which used to surface as a missing delta on the dashboard tile —
|
|
* the maintainer's complaint: "Bei Stimmung wird zum Beispiel kein Trend in
|
|
* Zahlen dargestellt." A 30-day slope still answers the question
|
|
* "is this metric drifting up or down?" — we just project it onto
|
|
* a 7-day window for label consistency. Returning `null` is reserved
|
|
* for the truly insufficient case where neither slope is available.
|
|
*
|
|
* Pure & deterministic — pinned by unit test.
|
|
*/
|
|
import type { TrendSlope } from "@/lib/analytics/trends";
|
|
|
|
export interface TrendCapableSummary {
|
|
slope7: TrendSlope | null;
|
|
slope30?: TrendSlope | null;
|
|
}
|
|
|
|
export function summaryToTrend7Delta(
|
|
summary: TrendCapableSummary | undefined | null,
|
|
): number | null {
|
|
if (!summary) return null;
|
|
// Primary: trailing-7-day linear-regression slope projected to a
|
|
// 7-day window. slope.slope is units per day (see
|
|
// lib/analytics/trends.ts).
|
|
if (summary.slope7) {
|
|
return summary.slope7.slope * 7;
|
|
}
|
|
// Fallback: slope30 projected onto 7 days. Same units (per day) so
|
|
// we still multiply by 7. This keeps the delta visible for sparser
|
|
// metrics (mood, sleep) that don't accumulate enough points in
|
|
// every trailing 7-day window. The arrow + colour interpretation
|
|
// stays correct because slope30 is computed the same way.
|
|
if (summary.slope30) {
|
|
return summary.slope30.slope * 7;
|
|
}
|
|
return null;
|
|
}
|