mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-09 21:10:59 +00:00
style(workouts): format pulse enrichment
This commit is contained in:
1 parent
5ec1a3836f
commit
104a058096
3 files changed
+10
-22
No files matched your search
@@ -135,10 +135,8 @@ export const GET = apiHandler(
|
||||
canonicalCluster.find((c) => c.id === row.id) ??
|
||||
canonicalCluster[0] ??
|
||||
null;
|
||||
const effectiveAvgHeartRate =
|
||||
canonical?.avgHeartRate ?? row.avgHeartRate;
|
||||
const effectiveMaxHeartRate =
|
||||
canonical?.maxHeartRate ?? row.maxHeartRate;
|
||||
const effectiveAvgHeartRate = canonical?.avgHeartRate ?? row.avgHeartRate;
|
||||
const effectiveMaxHeartRate = canonical?.maxHeartRate ?? row.maxHeartRate;
|
||||
|
||||
// ── Enrichment reads (all over existing tables — no migration) ────
|
||||
|
||||
|
||||
@@ -111,9 +111,7 @@ describe("pickCanonicalWorkoutRows", () => {
|
||||
zoneDurations: { zone_one_milli: 60_000 },
|
||||
},
|
||||
});
|
||||
expect(
|
||||
(picked.metadata as Record<string, unknown>).zoneDurations,
|
||||
).toEqual({
|
||||
expect((picked.metadata as Record<string, unknown>).zoneDurations).toEqual({
|
||||
zone_one_milli: 60_000,
|
||||
});
|
||||
expect(picked.metadata).not.toHaveProperty("whoopWorkoutStrain");
|
||||
@@ -213,11 +211,7 @@ describe("pickCanonicalWorkoutRows", () => {
|
||||
metadata: { zoneDurations: { zone_three_milli: 60_000 } },
|
||||
};
|
||||
|
||||
const result = pickCanonicalWorkoutRows([
|
||||
apple,
|
||||
wrongSport,
|
||||
wrongWindow,
|
||||
]);
|
||||
const result = pickCanonicalWorkoutRows([apple, wrongSport, wrongWindow]);
|
||||
expect(result.find((row) => row.id === "apple")).toMatchObject({
|
||||
avgHeartRate: null,
|
||||
maxHeartRate: null,
|
||||
@@ -284,7 +278,9 @@ describe("pickCanonicalWorkoutRows", () => {
|
||||
]);
|
||||
|
||||
expect(result).toHaveLength(2);
|
||||
expect(result.find((row) => row.id === "apple-u1")?.avgHeartRate).toBeNull();
|
||||
expect(
|
||||
result.find((row) => row.id === "apple-u1")?.avgHeartRate,
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("uses each WHOOP twin at most once for same-slot occurrences", () => {
|
||||
|
||||
@@ -96,11 +96,7 @@ function sanitizedWhoopZoneDurations(
|
||||
for (const key of WHOOP_ZONE_DURATION_KEYS) {
|
||||
const value = raw[key];
|
||||
if (value === undefined) continue;
|
||||
if (
|
||||
typeof value !== "number" ||
|
||||
!Number.isFinite(value) ||
|
||||
value < 0
|
||||
) {
|
||||
if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
|
||||
return null;
|
||||
}
|
||||
sanitized[key] = value;
|
||||
@@ -116,10 +112,8 @@ function enrichFromWhoopTwin<T extends WorkoutPickerRow>(
|
||||
const donorZones = sanitizedWhoopZoneDurations(donor.metadata);
|
||||
const needsZones =
|
||||
donorZones != null && winnerMetadata?.zoneDurations == null;
|
||||
const needsAvg =
|
||||
winner.avgHeartRate == null && donor.avgHeartRate != null;
|
||||
const needsMax =
|
||||
winner.maxHeartRate == null && donor.maxHeartRate != null;
|
||||
const needsAvg = winner.avgHeartRate == null && donor.avgHeartRate != null;
|
||||
const needsMax = winner.maxHeartRate == null && donor.maxHeartRate != null;
|
||||
|
||||
if (!needsAvg && !needsMax && !needsZones) return winner;
|
||||
|
||||
|
||||
Reference in new issue
Block a user