From 1f5a95527ed4a1af6d075c208e660fd6194a1949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CAidan?= <“abeiku17@gmail.com”> Date: Mon, 19 Aug 2024 14:21:36 +0100 Subject: [PATCH 1/2] Add wear coverage to output properties of info.json file --- src/actipy/reader.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/actipy/reader.py b/src/actipy/reader.py index 1c8138f..d5ba60e 100644 --- a/src/actipy/reader.py +++ b/src/actipy/reader.py @@ -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 @@ -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 From 69e172cfbfa288b4a3223c2252a2e462f310e618 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CAidan?= <“abeiku17@gmail.com”> Date: Mon, 19 Aug 2024 14:48:34 +0100 Subject: [PATCH 2/2] Update tests to add coverage --- tests/test_all.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_all.py b/tests/test_all.py index 2a9dcf4..5d6dbde 100644 --- a/tests/test_all.py +++ b/tests/test_all.py @@ -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)