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

Add wear coverage to output properties of info.json file #46

Merged
merged 2 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
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
16 changes: 16 additions & 0 deletions src/actipy/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ def read_device(input_file,
data, info_resample = P.resample(data, resample_hz)
info.update(info_resample)
timer.stop()

info_wear_coverage = calculate_wear_coverage(data)
info.update(info_wear_coverage)

return data, info

Expand Down Expand Up @@ -405,6 +408,19 @@ def fix_nonincr_time(data):
return data, errs


def calculate_wear_coverage(data):
""" Check device wear covers all 24 hours of the day """
info = {}
coverage = data.groupby(data.index.hour).agg(lambda x: x.notna().mean())

if len(coverage) < 24 or np.min(coverage) < 0.01:
info['Covers24hOK'] = 0
else:
info['Covers24hOK'] = 1

return info


class Timer:
def __init__(self, verbose=True):
self.verbose = verbose
Expand Down
3 changes: 2 additions & 1 deletion tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def test_read_device():
"EndTime": '2023-06-08 15:19:33',
"NumTicks": 1021800,
"WearTime(days)": 0.1211432638888889,
"NumInterrupts": 1
"NumInterrupts": 1,
"Covers24hOK": 0
}
assert_dict_equal(info, info_ref, rel=0.01)

Expand Down
Loading