diff --git a/lib/src/onehz/registry/group_registry.dart b/lib/src/onehz/registry/group_registry.dart index ee2c717..c534cf7 100644 --- a/lib/src/onehz/registry/group_registry.dart +++ b/lib/src/onehz/registry/group_registry.dart @@ -330,6 +330,7 @@ const GroupRegistry kAnalyticsGroupRegistry = GroupRegistry(1, [ 'lib/src/onehz/incremental_core.dart', 'lib/src/onehz/wellness/anomaly.dart', 'lib/src/onehz/wellness/changepoint.dart', + 'lib/src/onehz/wellness/cycle_lengths.dart', 'lib/src/onehz/wellness/readiness_composite.dart', 'lib/src/onehz/wellness/temp_circadian.dart', 'lib/src/onehz/wellness/temp_health.dart', diff --git a/lib/src/onehz/wellness/temp_health.dart b/lib/src/onehz/wellness/temp_health.dart index aeecc7c..f92652c 100644 --- a/lib/src/onehz/wellness/temp_health.dart +++ b/lib/src/onehz/wellness/temp_health.dart @@ -21,6 +21,7 @@ import '../types.dart'; import '../util.dart'; import '../foundations/baseline.dart'; +import 'cycle_lengths.dart' show cycleLengthImplausibleGapDays; // --------------------------------------------------------------------------- // 1. Skin-temp z-score illness flag (cycle-aware) @@ -277,6 +278,9 @@ Metric> menstrualCoverline( /// so the open cycle contributes nothing rather than a guess. One completed /// cycle is enough to give the open one a length. /// +/// A closed cycle longer than the 60 day cap is a missed log and counts for +/// nothing. +/// /// A date more than 1.5 cycles past its start is a lapse in logging, not a /// four-week luteal phase — it stops counting. List lutealFlags(List dates, List cycleStartDates) { @@ -314,6 +318,8 @@ List lutealFlags(List dates, List cycleStartDates) { ? starts[si + 1].difference(starts[si]).inDays.toDouble() : medianGap; if (len == null || len < 15) continue; + // a gap past the cycle cap is a missed log, not a cycle + if (len > cycleLengthImplausibleGapDays) continue; if (elapsed > 1.5 * len) continue; // stale log, not a long luteal phase if (elapsed >= len / 2) out[i] = true; } diff --git a/test/luteal_flags_test.dart b/test/luteal_flags_test.dart index 03e8945..932a209 100644 --- a/test/luteal_flags_test.dart +++ b/test/luteal_flags_test.dart @@ -25,6 +25,19 @@ void main() { [false, true, false]); }); + test('a gap over the cycle cap is a missed log, not a luteal phase', () { + expect( + lutealFlags(['2026-11-10'], ['2026-09-01', '2026-09-29', '2026-12-22']), + [false]); + }); + + test('a closed cycle of exactly the cap still counts', () { + // 01-01 to 03-02 is 60 days: second half starts at day 30 + expect( + lutealFlags(['2026-01-20', '2026-02-15'], ['2026-01-01', '2026-03-02']), + [false, true]); + }); + test('one logged start has no length to count with', () { expect(lutealFlags(['2026-02-20'], ['2026-01-01']), [false]); });