Feature/issue 303/new nonwear sleep interaction#306
Conversation
Handle changes for nonwear/sleep overlap. Need to cleanup + add to orchestrator.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #306 +/- ##
==========================================
+ Coverage 96.55% 96.68% +0.13%
==========================================
Files 17 17
Lines 1132 1147 +15
==========================================
+ Hits 1093 1109 +16
+ Misses 39 38 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
After meeting with Greg; if we use the adaptive pass, nonwear should be modified accordingly (remove the overlap) |
| sleep_windows: List[SleepWindow], | ||
| nonwear_measurement: models.Measurement, | ||
| adaptive: bool = False, | ||
| nonwear_sleep_buffer: int = 0, |
There was a problem hiding this comment.
Can this be optional and None is equivalent to adaptive == False?
| def sleep_cleanup( | ||
| sleep_windows: List[SleepWindow], nonwear_measurement: models.Measurement | ||
| ) -> models.Measurement: | ||
| sleep_windows: List[SleepWindow], |
There was a problem hiding this comment.
Iterable[SleepWindow]
| ) | ||
|
|
||
| return models.Measurement(time=sleep.time, measurements=cleaned_sleep) | ||
| if adaptive: |
There was a problem hiding this comment.
Flip around to "if not adaptive return"
| nw_run_starts = np.where(nonwear_change == 1)[0] | ||
| nw_run_ends = np.where(nonwear_change == -1)[0] | ||
|
|
||
| for s, e in zip(nw_run_starts, nw_run_ends): |
There was a problem hiding this comment.
zip(...., strict=True)
|
|
||
|
|
||
| def test_new_sleep_cleanup_nonwear_gap_absorbed_only_with_sufficient_buffer() -> None: | ||
| """Test nonwear + gap is absorbed only when buffer >= gap length.""" |
There was a problem hiding this comment.
Contradictory statement to the test; either change docstring or change the test
reindervdw-cmi
left a comment
There was a problem hiding this comment.
Minor comments, but no need for re-review.
Resolves #303
Begin co-pilot summary:
This pull request introduces significant improvements to the sleep cleanup logic in the analytics module, particularly adding adaptive handling of nonwear periods that immediately precede or are embedded within sleep windows. The changes also update the function signatures and return types, and expand the test suite to ensure robust handling of these new behaviors.
Enhancements to sleep cleanup logic:
sleep_cleanupfunction inanalytics.pynow supports an adaptive mode that can absorb nonwear periods into sleep if sleep is detected within a configurable buffer after nonwear ends. The function signature and return type have been updated to return both the cleaned sleep and updated nonwear measurements. [1] [2]API and documentation updates:
sleep_cleanupandsleep_bouts_cleanuphave been updated to clarify the new behavior, arguments, and return types, reflecting thatsleep_cleanupnow returns a tuple and supports adaptive cleanup, and thatsleep_bouts_cleanupreturns a single measurement. [1] [2]Integration and usage:
_run_filemethod has been updated to unpack the new tuple return value fromsleep_cleanup, ensuring downstream compatibility.Testing improvements:
test_analytics.pyhas been expanded with several new tests to verify the adaptive sleep cleanup logic, including cases where nonwear is adjacent to sleep, embedded within sleep, separated by a gap, or not adjacent at all. Existing tests have been updated to handle the new tuple return type.