mirror of
https://github.com/kuhyx/screen-locker.git
synced 2026-11-17 22:05:01 +01:00
Qualify a run on EITHER duration or distance, not both
Some checks are pending
pre-commit / pre-commit (push) Waiting to run
Tests / test (3.10) (push) Waiting to run
Tests / test (3.11) (push) Waiting to run
Tests / test (3.12) (push) Waiting to run
Tests / lock-popup-safety (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
Some checks are pending
pre-commit / pre-commit (push) Waiting to run
Tests / test (3.10) (push) Waiting to run
Tests / test (3.11) (push) Waiting to run
Tests / test (3.12) (push) Waiting to run
Tests / lock-popup-safety (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
MIN_RUN_DURATION_MINUTES and MIN_RUN_DISTANCE_KM were an AND (30+ min AND 5.0+ km), which rejected a fast 5 km run that took under 30 minutes. They are now an OR at 40 min / 3.5 km: a run qualifies at either threshold alone. Distance keeps its 5% GPS tolerance; duration, from the device clock, does not. Fixed one stale test whose fixture (1 min / 6 km) predated the OR change: 6 km alone now qualifies under the new rule, so the fixture needed to fail BOTH branches to still exercise the "no file verified, return first result" path it was written for. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KdSp6Nbrs9xvsWkCMDN9a1
This commit is contained in:
parent
5d4d491fb7
commit
a2ce5049f0
@ -419,6 +419,20 @@
|
||||
stores the true, un-inflated distance.
|
||||
</p>
|
||||
|
||||
<div class="note" style="border-left:4px solid #b58900;padding:0.75rem 1rem;margin:1.5rem 0;background:#fdf6e3">
|
||||
<strong>Superseded 2026-08-14.</strong> The numbers on this page describe the
|
||||
rule as it stood on 2026-07-18 and are kept for that history. The thresholds
|
||||
and their <em>shape</em> have both since changed: duration and distance were
|
||||
an <strong>AND</strong> here (30+ min <em>and</em> 5.0+ km); they are now an
|
||||
<strong>OR</strong> — a run qualifies at
|
||||
<code>MIN_RUN_DISTANCE_KM = 3.5</code> (inclusive, still with the 5% GPS
|
||||
tolerance described above) <em>or</em> at
|
||||
<code>MIN_RUN_DURATION_MINUTES = 40</code> (strict, no tolerance). The
|
||||
30-minute floor every run had to clear is gone, so a fast 5 km now
|
||||
passes too. The interactive demo and quiz below still use the old 5.0 km
|
||||
AND-rule.
|
||||
</div>
|
||||
|
||||
<h3>3.5 The CLI bug this surfaced (unrelated file, same root cause)</h3>
|
||||
|
||||
<p>
|
||||
|
||||
@ -58,8 +58,12 @@ WORKOUT_HTTP_PORT = 8765
|
||||
MIN_WORKOUT_DURATION_MINUTES = 60
|
||||
RUNNERUP_PACKAGES = ("org.runnerup", "org.runnerup.free")
|
||||
RUNNERUP_DB_SDCARD_TMP = "/sdcard/.runnerup_tmp_verification.db"
|
||||
MIN_RUN_DURATION_MINUTES = 30
|
||||
MIN_RUN_DISTANCE_KM = 5.0
|
||||
# A run qualifies on EITHER criterion — they are an OR, not an AND. A short
|
||||
# but long-lasting run counts, and so does a fast 5 km that takes under 40 min.
|
||||
# Do not reinstate an AND here: it would reject exactly the slow-run case this
|
||||
# pair exists to allow.
|
||||
MIN_RUN_DURATION_MINUTES = 40 # strict: "over 40 minutes"
|
||||
MIN_RUN_DISTANCE_KM = 3.5 # inclusive: "as low as 3.5 km"
|
||||
# GPS distance tracking undershoots on tight turns/tree cover/urban canyons;
|
||||
# a run within 5% of the minimum is accepted rather than rejected on
|
||||
# measurement noise. Duration comes from the device clock, not GPS, so it
|
||||
|
||||
@ -245,17 +245,22 @@ class RunnerUpVerificationMixin(RunnerUpDbMixin):
|
||||
)
|
||||
|
||||
duration_min = data["duration_seconds"] / 60
|
||||
if duration_min < MIN_RUN_DURATION_MINUTES:
|
||||
distance_km = data["distance_m"] / 1000
|
||||
|
||||
# Either criterion qualifies the run on its own (see _constants.py).
|
||||
# Distance gets the GPS tolerance; duration, from the device clock,
|
||||
# does not.
|
||||
distance_ok = (
|
||||
distance_km * (1 + RUNNERUP_DISTANCE_TOLERANCE) >= MIN_RUN_DISTANCE_KM
|
||||
)
|
||||
duration_ok = duration_min > MIN_RUN_DURATION_MINUTES
|
||||
if not distance_ok and not duration_ok:
|
||||
msg = (
|
||||
f"Run was {duration_min:.0f} min — need {MIN_RUN_DURATION_MINUTES}+ min"
|
||||
f"Run was {distance_km:.1f} km / {duration_min:.0f} min — need "
|
||||
f"{MIN_RUN_DISTANCE_KM:g}+ km or {MIN_RUN_DURATION_MINUTES}+ min"
|
||||
)
|
||||
return "too_short", msg
|
||||
|
||||
distance_km = data["distance_m"] / 1000
|
||||
if distance_km * (1 + RUNNERUP_DISTANCE_TOLERANCE) < MIN_RUN_DISTANCE_KM:
|
||||
msg = f"Run was {distance_km:.1f} km — need {MIN_RUN_DISTANCE_KM:.0f}+ km"
|
||||
return "too_short", msg
|
||||
if distance_km < MIN_RUN_DISTANCE_KM:
|
||||
if distance_ok and distance_km < MIN_RUN_DISTANCE_KM:
|
||||
_logger.info(
|
||||
"RunnerUp distance %.2f km is under the %.1f km minimum but "
|
||||
"within %.0f%% GPS tolerance — accepted.",
|
||||
|
||||
@ -113,19 +113,23 @@ class TestValidateRunnerupData:
|
||||
assert status == "wrong_sport"
|
||||
assert "unknown(99)" in msg
|
||||
|
||||
def test_too_short_duration_returns_too_short(
|
||||
def test_short_duration_alone_still_verified_on_distance(
|
||||
self,
|
||||
mock_tk: MagicMock,
|
||||
mock_sys_exit: MagicMock,
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
"""Duration below MIN_RUN_DURATION_MINUTES → too_short with 'min' in message."""
|
||||
"""Short duration alone is not enough to reject — distance still qualifies.
|
||||
|
||||
The criteria are an OR, so 6 km in 1 min is verified on distance. If
|
||||
the OR ever regressed to an AND this would return too_short.
|
||||
"""
|
||||
locker = create_locker(mock_tk, tmp_path)
|
||||
status, msg = locker._validate_runnerup_data(
|
||||
{"sport": 0, "duration_seconds": 60, "distance_m": 6000}
|
||||
)
|
||||
assert status == "too_short"
|
||||
assert "min" in msg
|
||||
assert status == "verified"
|
||||
assert "6.0 km" in msg
|
||||
|
||||
def test_too_short_distance_returns_too_short(
|
||||
self,
|
||||
@ -133,13 +137,18 @@ class TestValidateRunnerupData:
|
||||
mock_sys_exit: MagicMock,
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
"""Distance below MIN_RUN_DISTANCE_KM → too_short with 'km' in message."""
|
||||
"""Both criteria missed → too_short naming both.
|
||||
|
||||
0.1 km is far under the distance line and 30 min is under the duration
|
||||
line, so neither branch of the OR qualifies.
|
||||
"""
|
||||
locker = create_locker(mock_tk, tmp_path)
|
||||
status, msg = locker._validate_runnerup_data(
|
||||
{"sport": 0, "duration_seconds": 2400, "distance_m": 100}
|
||||
{"sport": 0, "duration_seconds": 1800, "distance_m": 100}
|
||||
)
|
||||
assert status == "too_short"
|
||||
assert "km" in msg
|
||||
assert "3.5+ km" in msg
|
||||
assert "40+ min" in msg
|
||||
|
||||
def test_valid_run_returns_verified(
|
||||
self,
|
||||
|
||||
@ -89,13 +89,17 @@ class TestValidateRunnerupDataDistanceTolerance:
|
||||
mock_sys_exit: MagicMock,
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
"""4.9 km * 1.05 = 5.145 >= 5.0 km minimum → verified."""
|
||||
"""3.45 km * 1.05 = 3.62 >= 3.5 km minimum → verified.
|
||||
|
||||
Duration is held under 40 min so the distance branch is what is
|
||||
actually under test, not the duration branch of the OR.
|
||||
"""
|
||||
locker = create_locker(mock_tk, tmp_path)
|
||||
status, msg = locker._validate_runnerup_data(
|
||||
{"sport": 0, "duration_seconds": 1947, "distance_m": 4929.05}
|
||||
{"sport": 0, "duration_seconds": 1500, "distance_m": 3450.0}
|
||||
)
|
||||
assert status == "verified"
|
||||
assert "4.9 km" in msg
|
||||
assert "3.5 km" in msg
|
||||
|
||||
def test_distance_below_tolerance_is_too_short(
|
||||
self,
|
||||
@ -103,13 +107,16 @@ class TestValidateRunnerupDataDistanceTolerance:
|
||||
mock_sys_exit: MagicMock,
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
"""4.0 km * 1.05 = 4.2 km, still short of the 5.0 km minimum → too_short."""
|
||||
"""3.0 km * 1.05 = 3.15 km, still short of the 3.5 km minimum → too_short.
|
||||
|
||||
Duration is under 40 min so the duration branch cannot rescue it.
|
||||
"""
|
||||
locker = create_locker(mock_tk, tmp_path)
|
||||
status, msg = locker._validate_runnerup_data(
|
||||
{"sport": 0, "duration_seconds": 1947, "distance_m": 4000}
|
||||
{"sport": 0, "duration_seconds": 1500, "distance_m": 3000}
|
||||
)
|
||||
assert status == "too_short"
|
||||
assert "km" in msg
|
||||
assert "3.5+ km" in msg
|
||||
|
||||
def test_distance_at_full_minimum_is_verified(
|
||||
self,
|
||||
@ -126,6 +133,104 @@ class TestValidateRunnerupDataDistanceTolerance:
|
||||
assert status == "verified"
|
||||
|
||||
|
||||
class TestValidateRunnerupDataOrCriteria:
|
||||
"""Distance and duration are an OR: either one alone qualifies a run."""
|
||||
|
||||
def test_long_but_short_distance_is_verified(
|
||||
self,
|
||||
mock_tk: MagicMock,
|
||||
mock_sys_exit: MagicMock,
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
"""2 km in 45 min → verified on the duration branch alone."""
|
||||
locker = create_locker(mock_tk, tmp_path)
|
||||
status, _ = locker._validate_runnerup_data(
|
||||
{"sport": 0, "duration_seconds": 2700, "distance_m": 2000}
|
||||
)
|
||||
assert status == "verified"
|
||||
|
||||
def test_far_but_quick_is_verified(
|
||||
self,
|
||||
mock_tk: MagicMock,
|
||||
mock_sys_exit: MagicMock,
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
"""3.6 km in 20 min → verified on the distance branch alone.
|
||||
|
||||
The old rule imposed a 30-minute floor on every run; it is gone, so a
|
||||
fast run is no longer rejected for being quick.
|
||||
"""
|
||||
locker = create_locker(mock_tk, tmp_path)
|
||||
status, _ = locker._validate_runnerup_data(
|
||||
{"sport": 0, "duration_seconds": 1200, "distance_m": 3600}
|
||||
)
|
||||
assert status == "verified"
|
||||
|
||||
def test_neither_criterion_met_is_too_short(
|
||||
self,
|
||||
mock_tk: MagicMock,
|
||||
mock_sys_exit: MagicMock,
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
"""3.0 km in 25 min misses both branches; message names both."""
|
||||
locker = create_locker(mock_tk, tmp_path)
|
||||
status, msg = locker._validate_runnerup_data(
|
||||
{"sport": 0, "duration_seconds": 1500, "distance_m": 3000}
|
||||
)
|
||||
assert status == "too_short"
|
||||
# Pinned literally: a ':.0f' format spec would render 3.5 as "4".
|
||||
assert "need 3.5+ km or 40+ min" in msg
|
||||
|
||||
def test_distance_boundary_is_inclusive(
|
||||
self,
|
||||
mock_tk: MagicMock,
|
||||
mock_sys_exit: MagicMock,
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
"""Exactly 3.5 km qualifies ("as low as 3.5 km")."""
|
||||
locker = create_locker(mock_tk, tmp_path)
|
||||
status, _ = locker._validate_runnerup_data(
|
||||
{"sport": 0, "duration_seconds": 600, "distance_m": 3500}
|
||||
)
|
||||
assert status == "verified"
|
||||
|
||||
def test_duration_boundary_is_strict(
|
||||
self,
|
||||
mock_tk: MagicMock,
|
||||
mock_sys_exit: MagicMock,
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
"""Exactly 40 min does not qualify, but 40.1 min does ("over 40")."""
|
||||
locker = create_locker(mock_tk, tmp_path)
|
||||
at_boundary, _ = locker._validate_runnerup_data(
|
||||
{"sport": 0, "duration_seconds": 2400, "distance_m": 1000}
|
||||
)
|
||||
assert at_boundary == "too_short"
|
||||
just_over, _ = locker._validate_runnerup_data(
|
||||
{"sport": 0, "duration_seconds": 2406, "distance_m": 1000}
|
||||
)
|
||||
assert just_over == "verified"
|
||||
|
||||
def test_real_2026_08_14_run_is_verified(
|
||||
self,
|
||||
mock_tk: MagicMock,
|
||||
mock_sys_exit: MagicMock,
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
"""Regression: the real run this rule change was made for.
|
||||
|
||||
Pulled from RunnerUp_2026-08-14-00-58-45_Running.tcx — 4 laps summing
|
||||
to 3817 m / 2502 s. It qualifies on both branches; under the previous
|
||||
AND rule it was rejected with "Run was 3.8 km — need 5+ km".
|
||||
"""
|
||||
locker = create_locker(mock_tk, tmp_path)
|
||||
status, msg = locker._validate_runnerup_data(
|
||||
{"sport": 0, "duration_seconds": 2502, "distance_m": 3817.0}
|
||||
)
|
||||
assert status == "verified"
|
||||
assert "3.8 km" in msg
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# _validate_runnerup_data
|
||||
# ---------------------------------------------------------------------------
|
||||
@ -178,7 +283,14 @@ class TestVerifyRunnerupViaFiles:
|
||||
mock_sys_exit: MagicMock,
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
"""Files found but none verified → returns first non-None validation result."""
|
||||
"""Files found but none verified → returns first non-None validation result.
|
||||
|
||||
Both duration and distance are held under their minimums so the OR
|
||||
in _validate_runnerup_data cannot rescue this fixture on either
|
||||
branch — otherwise a fixture qualifying on one branch alone would
|
||||
turn this into a test of that branch, not of the "no file verified"
|
||||
return-first-result behavior this test is actually about.
|
||||
"""
|
||||
locker = create_locker(mock_tk, tmp_path)
|
||||
object.__setattr__(
|
||||
locker,
|
||||
@ -189,7 +301,7 @@ class TestVerifyRunnerupViaFiles:
|
||||
locker,
|
||||
"_pull_and_parse_tcx",
|
||||
MagicMock(
|
||||
return_value={"sport": 0, "duration_seconds": 60, "distance_m": 6000}
|
||||
return_value={"sport": 0, "duration_seconds": 60, "distance_m": 1000}
|
||||
),
|
||||
)
|
||||
result = locker._verify_runnerup_via_files()
|
||||
|
||||
@ -217,7 +217,13 @@ class TestScanAndFillWeekRunnerup:
|
||||
mock_sys_exit: MagicMock,
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
"""_validate_runnerup_data returns not-verified → date not filled."""
|
||||
"""_validate_runnerup_data returns not-verified → date not filled.
|
||||
|
||||
Both duration and distance are held under their minimums -- the
|
||||
criteria are an OR, so a fixture qualifying on either alone would
|
||||
verify instead of exercising the not-verified path this test is
|
||||
about.
|
||||
"""
|
||||
locker = create_locker(mock_tk, tmp_path)
|
||||
log_file = tmp_path / "log.json"
|
||||
log_file.write_text("{}")
|
||||
@ -231,7 +237,7 @@ class TestScanAndFillWeekRunnerup:
|
||||
locker,
|
||||
"_pull_and_parse_tcx",
|
||||
MagicMock(
|
||||
return_value={"sport": 0, "duration_seconds": 60, "distance_m": 6000}
|
||||
return_value={"sport": 0, "duration_seconds": 60, "distance_m": 1000}
|
||||
),
|
||||
)
|
||||
assert locker._scan_and_fill_week_runnerup(log_file) == 0
|
||||
|
||||
@ -321,7 +321,10 @@ class TestBranchCoverageGaps:
|
||||
of 'if best is None:' (161->154), exercising the loop-continue with best set."""
|
||||
locker = create_locker(mock_tk, tmp_path)
|
||||
|
||||
# Both exports return non-verified data (too_short).
|
||||
# Both exports return non-verified data (too_short). Duration and
|
||||
# distance are an OR, so both must fail their minimum -- a fixture
|
||||
# qualifying on either alone would verify instead of exercising this
|
||||
# branch.
|
||||
# Iteration 1: best is None → sets best → loop continues to export 2.
|
||||
# Iteration 2: best is NOT None → False branch of 'if best is None:' (161->154).
|
||||
object.__setattr__(
|
||||
@ -329,7 +332,7 @@ class TestBranchCoverageGaps:
|
||||
"_find_runnerup_exports_for_date",
|
||||
MagicMock(return_value=["/sdcard/a.tcx", "/sdcard/b.tcx"]),
|
||||
)
|
||||
short_run = {"sport": 0, "duration_seconds": 60, "distance_m": 6000}
|
||||
short_run = {"sport": 0, "duration_seconds": 60, "distance_m": 1000}
|
||||
object.__setattr__(
|
||||
locker,
|
||||
"_pull_and_parse_tcx",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user