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:
@@ -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]
|
||||
|
||||
@@ -67,7 +67,7 @@ def _dummy_metrics(**overrides):
|
||||
elevation_gain_m=100.0, elevation_loss_m=95.0,
|
||||
avg_speed_kmh=10.0, max_speed_kmh=20.0,
|
||||
avg_hr_bpm=None, max_hr_bpm=None,
|
||||
avg_cadence_rpm=None, avg_power_w=None, max_power_w=None,
|
||||
avg_cadence_rpm=None, avg_power_w=None, np_power_w=None, max_power_w=None,
|
||||
bbox=None, start_latlng=None, end_latlng=None,
|
||||
mmp=None, best_efforts=None, best_climb_m=None,
|
||||
)
|
||||
@@ -208,6 +208,7 @@ def test_build_summary_required_fields():
|
||||
max_hr_bpm=None,
|
||||
avg_cadence_rpm=None,
|
||||
avg_power_w=None,
|
||||
np_power_w=None,
|
||||
max_power_w=None,
|
||||
bbox=None,
|
||||
start_latlng=None,
|
||||
|
||||
Reference in New Issue
Block a user