Repository navigation
fix: retain interrupted main sleep without counting legacy naps twice #605
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
Open
DropTabl
wants to merge
2
commits into
OpenStrap:main
Choose a base branch
from
DropTabl:fix/sleep-continuation-gap
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+273
−67
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:openstrap_edge/compute/accepted_naps.dart'; | ||
| import 'package:openstrap_edge/compute/nap_edits.dart'; | ||
|
|
||
| Map<String, dynamic> bundle({bool mainSleep = true}) => { | ||
| if (mainSleep) | ||
| 'sleep': { | ||
| 'window': { | ||
| 'value': {'onset_ms': 0, 'offset_ms': 8 * 3600 * 1000}, | ||
| }, | ||
| }, | ||
| 'naps': {'value': <Map<String, dynamic>>[], 'assessment_complete': true}, | ||
| 'sleep_periods': { | ||
| 'assessment_complete': true, | ||
| 'periods': [ | ||
| if (mainSleep) {'is_main': true, 'duration_min': 360}, | ||
| ], | ||
| }, | ||
| }; | ||
|
|
||
| NapEdit nap(int start, int end, {String source = 'legacy'}) => NapEdit( | ||
| kind: NapEditKind.added, | ||
| startSec: start, | ||
| endSec: end, | ||
| snapshot: source == 'manual' ? null : {'source': source, 'duration_min': 120}, | ||
| ); | ||
|
|
||
| void main() { | ||
| test('a legacy continuation is not also credited as a nap', () { | ||
| final day = bundle(); | ||
| final edit = nap(6 * 3600, 8 * 3600); | ||
| composeAcceptedNaps(day, [edit]); | ||
|
|
||
| expect(day['naps']['value'], isEmpty); | ||
| expect(day['scalars']['nap_min'], 0); | ||
| expect(day['sleep_periods']['periods'], hasLength(1)); | ||
| expect(day['sleep_periods']['total_asleep_min'], 360); | ||
| composeAcceptedNaps(day, [edit]); | ||
| expect(day['scalars']['nap_min'], 0); | ||
| expect(day['sleep_periods']['total_asleep_min'], 360); | ||
|
|
||
| // Keep the stored decision: a later correction that removes the main | ||
| // window can expose this original snapshot again. | ||
| final withoutMain = bundle(mainSleep: false); | ||
| composeAcceptedNaps(withoutMain, [edit]); | ||
| expect(withoutMain['naps']['value'], hasLength(1)); | ||
| expect(withoutMain['scalars']['nap_min'], 120); | ||
| }); | ||
|
|
||
| for (final bounds in [ | ||
| (-3600, 3600), | ||
| (7 * 3600, 9 * 3600), | ||
| (-3600, 9 * 3600), | ||
| ]) { | ||
| test( | ||
| 'a partially overlapping legacy nap keeps its recorded duration: $bounds', | ||
| () { | ||
| final day = bundle(); | ||
| final edit = nap(bounds.$1, bounds.$2); | ||
| composeAcceptedNaps(day, [edit]); | ||
| expect(day['naps']['value'], hasLength(1)); | ||
| expect(day['scalars']['nap_min'], 120); | ||
| expect(day['sleep_periods']['total_asleep_min'], 480); | ||
| composeAcceptedNaps(day, [edit]); | ||
| expect(day['scalars']['nap_min'], 120); | ||
| expect(day['sleep_periods']['total_asleep_min'], 480); | ||
| }, | ||
| ); | ||
| } | ||
|
|
||
| test('legacy naps adjoining the main window stay separate', () { | ||
| final day = bundle(); | ||
| composeAcceptedNaps(day, [nap(-7200, 0), nap(8 * 3600, 10 * 3600)]); | ||
| expect(day['naps']['value'], hasLength(2)); | ||
| expect(day['scalars']['nap_min'], 240); | ||
| expect(day['sleep_periods']['total_asleep_min'], 600); | ||
| }); | ||
|
|
||
| for (final window in [ | ||
| <String, dynamic>{}, | ||
| {'onset_ms': 1000, 'offset_ms': 0}, | ||
| {'onset_ms': 'unknown', 'offset_ms': 8 * 3600 * 1000}, | ||
| ]) { | ||
| test('invalid main window preserves the legacy nap: $window', () { | ||
| final day = bundle(); | ||
| day['sleep'] = { | ||
| 'window': {'value': window}, | ||
| }; | ||
| composeAcceptedNaps(day, [nap(6 * 3600, 8 * 3600)]); | ||
| expect(day['naps']['value'], hasLength(1)); | ||
| }); | ||
| } | ||
|
|
||
| for (final source in ['manual', 'confirmed']) { | ||
| test('a corrected window preserves a $source nap decision', () { | ||
| final day = bundle(); | ||
| composeAcceptedNaps(day, [nap(6 * 3600, 8 * 3600, source: source)]); | ||
| expect(day['naps']['value'], hasLength(1)); | ||
| expect(day['scalars']['nap_min'], 120); | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: OpenStrap/edge
Length of output: 6375
🌐 Web query:
"74165e45254203c5784ad88a53d8ec6ab099d6dd" DropTabl analytics OpenStrap PR 96💡 Result:
🏁 Script executed:
Repository: OpenStrap/edge
Length of output: 43821
🏁 Script executed:
Repository: OpenStrap/edge
Length of output: 41452
🏁 Script executed:
Repository: OpenStrap/edge
Length of output: 22516
Repin the analytics dependency before release.
DropTabl/analyticsis a public user fork, and analytics PR#96is still open. The current exact SHA is suitable for this merge, but release from this fork would bypass the upstream repository’s merge and retention controls. After PR#96merges, replace the URL andrefwith the upstream merge commit and setkAnalyticsPinto the same SHA.This is not a merge-time build blocker. The lockfile and version pin already agree.
🤖 Prompt for AI Agents
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.
Kept an exact reviewed fork pin while analytics#96 remains open, now updated to 302332bbe74d82b9bd10d08f93f8a058a3108123 so it includes the grouped-span cap fix. YAML, lockfile, and kAnalyticsPin agree and the version/pin checks pass. Added the upstream URL/merge-SHA repin requirement next to the dependency and retained it in the PR description. This remains a before-release follow-up after analytics#96 merges; no release is being made from this branch.
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.
@DropTabl Understood. The reviewed fork pin remains acceptable for this PR. The upstream repin remains a before-release follow-up, not a merge blocker.
Would you like a GitHub issue to track that follow-up?
You are interacting with an AI system.