Skip to content

Commit 9092125

Browse files
authored
Merge pull request #151 from BIDMCDigitalPsychiatry/fix_screen_dur_None
Fixing None values screen dur
2 parents 0cef85a + 67c8088 commit 9092125

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

cortex/secondary/screen_duration.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import numpy as np
33
from ..feature_types import secondary_feature
44
from ..primary.screen_active import screen_active
5+
from ..raw.device_state import device_state
56

67
MS_IN_A_DAY = 86400000
78
@secondary_feature(
@@ -32,9 +33,17 @@ def screen_duration(**kwargs):
3233
value (float): The time (in ms) spent with the device screen on.
3334
3435
"""
35-
_screen_active = screen_active(**kwargs)
36-
_screen_duration = np.sum([active_bout['duration'] for active_bout in _screen_active['data']])
36+
37+
_device_state = device_state(id=kwargs['id'],
38+
start=kwargs['start'],
39+
end=kwargs['end'],
40+
_limit=1)['data']
41+
3742
# screen duration should be None if there is no data
38-
if _screen_active['has_raw_data'] == 0:
43+
if len(_device_state) == 0:
3944
_screen_duration = None
40-
return {'timestamp':kwargs['start'], 'value': _screen_duration}
45+
else:
46+
_screen_active = screen_active(**kwargs)
47+
_screen_duration = np.sum([active_bout['duration'] for active_bout in _screen_active['data']])
48+
49+
return {'timestamp': kwargs['start'], 'value': _screen_duration}

0 commit comments

Comments
 (0)