Repository navigation
feat: cap naps at 3 hours (manual entries and detected bouts) #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,9 +54,14 @@ typedef NapMap = Map<String, dynamic>; | |
| /// scatter of two-minute entries would swamp the real ones in every total. | ||
| const int kMinManualNapSec = 5 * 60; | ||
|
|
||
| /// Maximum. Anything longer is a sleep, not a nap, and belongs in the main | ||
| /// sleep window where the stager can actually say something about its stages. | ||
| const int kMaxManualNapSec = 6 * 60 * 60; | ||
| /// Maximum length of anything counted as a nap: 3 hours. Anything longer is a | ||
| /// sleep, not a nap, and belongs in the main sleep window where the stager can | ||
| /// actually say something about its stages. Applies to detected AND manually | ||
| /// logged naps alike — one cap, one place. | ||
| const int kMaxNapSec = 3 * 60 * 60; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update the validation messages to match the new limit. A four-hour entry is rejected, but
|
||
|
|
||
| /// Maximum for a manually logged nap — the same cap as detected naps. | ||
| const int kMaxManualNapSec = kMaxNapSec; | ||
|
|
||
| /// Whether a window can be logged as a nap. | ||
| bool manualNapWindowIsValid(int startSec, int endSec) { | ||
|
|
@@ -129,6 +134,16 @@ List<NapMap> applyNapEdits(List<NapMap> detected, List<NapEdit> edits) { | |
| return out; | ||
| } | ||
|
|
||
| /// Drops every nap whose window exceeds [kMaxNapSec]. A detected bout longer | ||
| /// than 3 h is a sleep fragment the detector misfiled as a nap; crediting it | ||
| /// into `nap_min` would count a night's sleep as daytime rest. The filter is | ||
| /// pure so the rule is testable without a derivation run. | ||
| List<NapMap> dropOversizedNaps(List<NapMap> naps) => [ | ||
| for (final n in naps) | ||
| if ((n['end'] as num).toInt() - (n['start'] as num).toInt() <= kMaxNapSec) | ||
| n, | ||
| ]; | ||
|
|
||
| /// Total asleep minutes across [naps] — the `nap_min` scalar. | ||
| /// | ||
| /// Always a number, including 0 for an empty list. The absent-versus-zero | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: BucciMobile/edge-copy
Length of output: 9927
Script executed:
Repository: BucciMobile/edge-copy
Length of output: 38490
Script executed:
Repository: BucciMobile/edge-copy
Length of output: 16533
Script executed:
Repository: BucciMobile/edge-copy
Length of output: 27898
Script executed:
Repository: BucciMobile/edge-copy
Length of output: 12202
Script executed:
Repository: BucciMobile/edge-copy
Length of output: 10863
Web query:
OpenStrap analytics 3a7ca34d30233ff11e6c2877083f319a907ccb31 detectNaps nap maximum durationResult:
Script executed:
Repository: BucciMobile/edge-copy
Length of output: 5668
Script executed:
Repository: BucciMobile/edge-copy
Length of output: 28104
Apply the cap to legacy detected naps.
ActivityStore.preserveLegacyNapscan copy a pre-upgrade detection longer than three hours intosleep_nap.napEditsthen replays it throughapplyNapEdits, bypassingcapped. If it is not contained in the main sleep window, it can remain innap_minand the timeline after re-derivation.Handle oversized legacy detections separately from explicit user entries, including legacy snapshots already stored in
sleep_nap.