Comments (4)
For additional context:
the get_time_in_sleep_stage
function in the sleep module, breaks when the pd.Series is transformed to a dictionary with the .to_dict()
method. In fact, while in the Series two rows can have the same index, in the dictionary only the last row is kept for the key.
3 possible ways to fix:
- Assume that the first sleep of the day is the important one (i.e. the person is sleeping at night) by:
participant_sleep_summary = participant_sleep_summary.groupby("calendarDate").head(1)
- Filter out rows with sleep score 0 completely, before producing the dictionary
- Avoid the transformation to dict and return the pd.Series, giving the possibility to appropriately handle each sleep occurrence later on. In this case, note, however that if
average=True
, the mean can be skewed greatly by 0 sleep score naps.
from pywearable.
This was temporarily fixed in b07d089 . The new implementation returns only the first sleep of the day, and discards additional sleeps occuring during the day,
I am leaving this issue open for further improvements.
from pywearable.
I believe that the current implementation has to be improved. The order in which Labfront returns the sleep summaries is not always consistent with improving validation methods. In the example reported below, for example, we have that for the calendarDate 2023-08-04, the first sleep summary has a AUTO_TENTATIVE validation, the second one an ENHANCED_FINAL validation, and the third one a ENHANCED_TENTATIVE validation:
sleepSummaryId | calendarDate | timezoneOffsetInMs | unixTimestampInMs | isoDate | durationInMs | validation |
---|---|---|---|---|---|---|
x4dbbd48-64cc2270-5d84 | 2023-08-04 | 7200000 | 1691099760000 | 2023-08-03T23:56:00.000+02:00 | 23940000 | AUTO_TENTATIVE |
x4dbbd48-64cc23d8-567c | 2023-08-04 | 7200000 | 1691100120000 | 2023-08-04T00:02:00.000+02:00 | 22140000 | ENHANCED_FINAL |
x4dbbd48-64cc2414-55c8 | 2023-08-04 | 7200000 | 1691100180000 | 2023-08-04T00:03:00.000+02:00 | 21960000 | ENHANCED_TENTATIVE |
x4dbbd48-64cd70e4-675c | 2023-08-05 | 7200000 | 1691185380000 | 2023-08-04T23:43:00.000+02:00 | 26460000 | AUTO_FINAL |
x4dbbd48-64cd7288-6720 | 2023-08-05 | 7200000 | 1691185800000 | 2023-08-04T23:50:00.000+02:00 | 26400000 | ENHANCED_TENTATIVE |
x4dbbd48-64ceb328-7350 | 2023-08-06 | 7200000 | 1691267880000 | 2023-08-05T22:38:00.000+02:00 | 29520000 | AUTO_TENTATIVE |
x4dbbd48-64ceb490-73c8 | 2023-08-06 | 7200000 | 1691268240000 | 2023-08-05T22:44:00.000+02:00 | 29640000 | ENHANCED_FINAL |
x4dbbd48-64d00e44-71e8 | 2023-08-07 | 7200000 | 1691356740000 | 2023-08-06T23:19:00.000+02:00 | 29160000 | ENHANCED_TENTATIVE |
x4dbbd48-64d00ef8-6a2c | 2023-08-07 | 7200000 | 1691356920000 | 2023-08-06T23:22:00.000+02:00 | 27180000 | AUTO_TENTATIVE |
x4dbbd48-64d00ef8-70f8 | 2023-08-07 | 7200000 | 1691356920000 | 2023-08-06T23:22:00.000+02:00 | 28920000 | ENHANCED_TENTATIVE |
Some functions of the module currently retrieve only the first row for a given calendarDate: in this case, we would have gotten a AUTO_TENTATIVE sleep summary, while the proper one should be the ENHANCED_FINAL. Thus, an improved method would be:
- Check if there are multiple sleep summaries for a given calendarDate (being aware of the fact that Garmin also tracks daily naps)
- Get the sleep summary with the best validation available
Tagging here also @Vaeliss so that he can have a look at it
from pywearable.
Labfront suggests to follow these decision scheme based on the documentation reported here:
- The ENHANCED_FINAL one with the longest sleep period
- The ENHANCED_TENTATIVE one with the longest sleep period
- The AUTO_FINAL one with the longest sleep period
- The AUTO_TENTATIVE one with the longest sleep period
from pywearable.
Related Issues (20)
- Union types as X | Y cause dependency errors when using python 3.9
- sleep.get_total_sleep_time returns 0 instead of nan HOT 1
- CPD_midpoint and CPD_duration unexpected behavior with single day computations HOT 3
- get_sleep_statistic has no "all" as default for user_id
- Eliminate dependency from july
- Integrate bedtime and wakeup time statistics in get_sleep_statistics HOT 3
- loader_kwargs as parameter in processing functions HOT 1
- Integrate LifeSnaps dataset
- Respiration statistics HOT 1
- get_sleep_summary_graph first and last empty days HOT 1
- Load Labfront Health Snapshot from Health API
- Load Labfront Accelerometer data from Garmin SDK
- Load Movesense data from Labfront
- Installation via pip
- Returning ordered dictionaries instead of dicts
- LabronftLoader failed to inizialize HOT 1
- Add check with non datetime data in sleep statistics
- Hypnograms starting and/or ending with awake condition have unintended consequences on sleep metrics HOT 2
- New LabfrontLoader fails with movesense folder
- Statistics based on physiological cycles and not on midnight-to-midnight HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pywearable.