Skip to content
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

Fixing None values screen dur #151

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions cortex/secondary/screen_duration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import numpy as np
from ..feature_types import secondary_feature
from ..primary.screen_active import screen_active
from ..raw.device_state import device_state

MS_IN_A_DAY = 86400000
@secondary_feature(
Expand Down Expand Up @@ -32,9 +33,17 @@ def screen_duration(**kwargs):
value (float): The time (in ms) spent with the device screen on.

"""
_screen_active = screen_active(**kwargs)
_screen_duration = np.sum([active_bout['duration'] for active_bout in _screen_active['data']])

_device_state = device_state(id=kwargs['id'],
start=kwargs['start'],
end=kwargs['end'],
_limit=1)['data']

# screen duration should be None if there is no data
if _screen_active['has_raw_data'] == 0:
if len(_device_state) == 0:
_screen_duration = None
return {'timestamp':kwargs['start'], 'value': _screen_duration}
else:
_screen_active = screen_active(**kwargs)
_screen_duration = np.sum([active_bout['duration'] for active_bout in _screen_active['data']])

return {'timestamp': kwargs['start'], 'value': _screen_duration}