Skip to content
Open
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
16 changes: 8 additions & 8 deletions src/cli/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,28 @@ export function formatJson(data: unknown): string {
// ---------------------------------------------------------------------------

function rhrPart(s: MetricSnapshot): string {
if (s.value === null) {
const value = formatNumber(s.value);
if (value === MISSING) {
return `RHR ${MISSING}`;
}
const glyph = arrow(s.trend);
const base = `RHR ${s.value.toFixed(0)}`;
const base = `RHR ${value}`;
return glyph ? `${base} ${glyph}` : base;
}

function hrvPart(s: MetricSnapshot): string {
if (s.value === null) {
const value = formatNumber(s.value);
if (value === MISSING) {
return `HRV ${MISSING}`;
}
const glyph = arrow(s.trend);
const base = `HRV ${s.value.toFixed(0)}ms`;
const base = `HRV ${value}ms`;
return glyph ? `${base} ${glyph}` : base;
}

function spo2Part(s: MetricSnapshot): string {
if (s.value === null) {
return `SpO2 ${MISSING}`;
}
return `SpO2 ${s.value.toFixed(1)}%`;
const value = formatNumber(s.value, 1);
return value === MISSING ? `SpO2 ${MISSING}` : `SpO2 ${value}%`;
}

function sleepPart(sleep: SleepSession | null): string {
Expand Down
10 changes: 10 additions & 0 deletions test/cli/format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ describe("formatPercent", () => {
});

describe("formatBareSummary", () => {
it("renders non-finite metrics as missing, without units or trend arrows", () => {
const s = summary({
hrv: snap({ trend: "rising", value: Number.POSITIVE_INFINITY }),
rhr: snap({ trend: "falling", value: Number.NaN }),
spo2: snap({ value: Number.NEGATIVE_INFINITY }),
});
const [line] = formatBareSummary(s).split("\n");
expect(line).toBe("RHR — HRV — Sleep 7.2h 93%eff SpO2 —");
});

it("renders a missing metric as an em dash, not 0 or NaN", () => {
const s = summary({ rhr: emptySnap("rhr") });
const [line] = formatBareSummary(s).split("\n");
Expand Down
Loading