fix(polar): align collection response fields

This commit is contained in:
Marc-André Bombeck committed 2026-07-20 14:36:21 +02:00
1 parent 3c5afea912
commit 1840779dd7
2 files changed
+11 -4

No files matched your search

+3 -1
View File
@@ -203,7 +203,7 @@ describe("mapNightlyRecharge", () => {
const rec: PolarNightlyRecharge = {
date: "2026-06-10",
nightly_recharge_status: 6,
hrv_avg: 55,
heart_rate_variability_avg: 55,
heart_rate_avg: 52.4,
breathing_rate_avg: 14.2,
};
@@ -448,6 +448,7 @@ describe("mapSpo2", () => {
const r: PolarSpo2 = {
test_time: 1_781_059_600,
blood_oxygen_percent: 96,
source_device_id: "device-1",
};
const mapped = mapSpo2(r);
expect(mapped[0]?.type).toBe("OXYGEN_SATURATION");
@@ -456,6 +457,7 @@ describe("mapSpo2", () => {
expect(mapped[0]?.measuredAt.toISOString()).toBe(
"2026-06-10T02:46:40.000Z",
);
expect(mapped[0]?.externalId).toBe("spo2:1781059600:device-1");
});
it("rejects out-of-range readings", () => {
expect(mapSpo2({ test_time: 1_781_059_600, blood_oxygen_percent: 0 })).toEqual(
+8 -3
View File
@@ -180,7 +180,7 @@ export interface PolarNightlyRecharge {
ans_charge?: number | null;
ans_charge_status?: number | null;
heart_rate_avg?: number | null;
hrv_avg?: number | null;
heart_rate_variability_avg?: number | null;
breathing_rate_avg?: number | null;
}
@@ -226,6 +226,7 @@ export interface PolarCardioLoad {
/** One Polar SpO2 (Elixir pulse-ox) test result. `test_time` is a Unix
* timestamp in seconds; `blood_oxygen_percent` is the recorded percentage. */
export interface PolarSpo2 {
source_device_id?: string;
test_time?: number;
blood_oxygen_percent?: number | null;
}
@@ -395,10 +396,13 @@ export function mapNightlyRecharge(
fieldTag: "recovery",
});
}
if (typeof r.hrv_avg === "number" && r.hrv_avg > 0) {
if (
typeof r.heart_rate_variability_avg === "number" &&
r.heart_rate_variability_avg > 0
) {
out.push({
type: "HRV_RMSSD",
value: round2(r.hrv_avg),
value: round2(r.heart_rate_variability_avg),
unit: "ms",
measuredAt,
fieldTag: "hrv_rmssd",
@@ -634,6 +638,7 @@ export function mapSpo2(r: PolarSpo2): MappedMeasurement[] {
unit: "%",
measuredAt,
fieldTag: "spo2",
externalId: `spo2:${r.test_time}:${r.source_device_id ?? "unknown"}`,
},
];
}