Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/src/onehz/registry/group_registry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ const GroupRegistry kAnalyticsGroupRegistry = GroupRegistry(1, <GroupDecl>[
'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',
Expand Down
6 changes: 6 additions & 0 deletions lib/src/onehz/wellness/temp_health.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import '../types.dart';
import '../util.dart';
import '../foundations/baseline.dart';
import 'cycle_lengths.dart' show cycleLengthImplausibleGapDays;
Comment thread
abdulsaheel marked this conversation as resolved.
Resolved

// ---------------------------------------------------------------------------
// 1. Skin-temp z-score illness flag (cycle-aware)
Expand Down Expand Up @@ -277,6 +278,9 @@ Metric<List<OvulationEvent>> 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<bool> lutealFlags(List<String> dates, List<String> cycleStartDates) {
Expand Down Expand Up @@ -314,6 +318,8 @@ List<bool> lutealFlags(List<String> dates, List<String> 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;
}
Expand Down
13 changes: 13 additions & 0 deletions test/luteal_flags_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
});
Expand Down
Loading