Fix pre-existing test failures in test_writer and test_metrics

test_writer: _dummy_metrics() and test_build_summary_required_fields were
missing np_power_w=None after the field was added to ComputedMetrics.

test_metrics: the leading-zero elevation heuristic fired on a single 0.0
start value, incorrectly skipping the first legitimate elevation step.
Guard now requires at least 2 consecutive near-zero leading values before
activating the Apple Watch lock-acquisition workaround.
This commit is contained in:
Davide Scaini
2026-05-13 23:15:26 +02:00
parent e61d05fc41
commit 9dd533825f
2 changed files with 14 additions and 8 deletions
+12 -7
View File
@@ -377,16 +377,21 @@ def _elevation(
# Some devices (e.g. Apple Watch) record exactly 0.0 for the initial samples
# while waiting for barometric/GPS lock, then jump to the real altitude.
# Detect this by checking for a leading near-zero run followed by a large
# jump: skip those zeros and seed the accumulator from the first real value.
# Safety: if the activity genuinely stays near sea level, no value in the
# series will exceed `threshold`, so `start` stays 0 — unchanged behaviour.
# Only activate when there are at least 2 consecutive near-zero leading
# values — a single 0.0 is a legitimate sea-level starting point.
start = 0
if abs(elevations[0]) < 0.5:
for i, e in enumerate(elevations):
if abs(e) > threshold:
start = i
n_leading = 0
for e in elevations:
if abs(e) < 0.5:
n_leading += 1
else:
break
if n_leading > 1:
for i, e in enumerate(elevations):
if abs(e) > threshold:
start = i
break
gain = loss = 0.0
committed = elevations[start]