Skip to content

sleep --derive: hr_avg emitted at full float64 precision; total_sleep_min equals light_min #21

Description

@DTTerastar

Severity

minor

Summary

Two related cosmetic / data-hygiene problems in the --derive polyfill path of the sleep subcommand.

1. hr_avg precision blows up on derived rows

Real Withings rows in CSV print hr_avg as a small integer-ish value. Derived rows print 16 digits of float noise:

$ withings-export sleep --since 7d --derive 2>/dev/null | head -3
date,start,end,timezone,total_sleep_min,...,hr_avg,hr_min,hr_max,...,source
2026-04-18,...,Local,385,...,45.86206896551724,0,0,...,derived
2026-04-19,...,Local,567,...,43.037974683544306,0,0,...,derived

This is the same column non-derived rows fill with a single integer. Format with %.0f (matches markdown's fmtRound) or %.1f for parity with the fmtFloat1 helper already in cmd/shared.go.

2. Derived rows put all minutes into light_min

Every derived row has total_sleep_min == light_min and deep_min == rem_min == 0. That isn't surprising for an HR-only polyfill, but consumers can't tell whether "deep_min=0" means "this user had zero deep sleep" or "we don't actually know". For derived rows, please leave the per-stage columns blank/null rather than zero, or at minimum document this in prime / --help. Same applies to wakeup_count, time_to_sleep_sec, etc.

Reproduce

See command above.

Expected

  • Round derived hr_avg to integer or one decimal in CSV/markdown.
  • For derived rows, emit empty CSV cells / JSON null for fields the heuristic cannot infer (deep, rem, wakeups, latencies).

Metadata

Metadata

Assignees

Labels

area:format--format markdown/json/csv and codec behavior.kind:bugObserved behavior diverges from documented behavior.priority:mediumReproducible bug or gap with a workaround, or a well-scoped enhancement clearly in charter.

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions