Skip to content

Commit

Permalink
Fix faulty onset and nonwear parsing. (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReinderVosDeWael authored Jan 23, 2024
1 parent 9ee0617 commit 8abbf4e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/actigraphy/components/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ def _find_continuous_blocks(vector: Sequence[bool]) -> list[int]:
if value
and (
index == 0
or index == len(vector)
or index == len(vector) - 1
or not vector[index - 1]
or not vector[index + 1]
)
Expand Down
14 changes: 9 additions & 5 deletions src/actigraphy/database/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@ def initialize_datapoints(
"""
logger.debug("Initializing data points.")
window_size_ratio = (
ggir_metadata.m.windowsizes[1] // ggir_metadata.m.windowsizes[0] - 1
)
window_size_ratio = ggir_metadata.m.windowsizes[1] // ggir_metadata.m.windowsizes[0]
non_wear_elements = np.where(ggir_metadata.m.metalong["nonwearscore"] > 1)[0]
non_wear_indices_in_data = [
element * window_size_ratio for element in non_wear_elements
]
non_wear_indices = np.concatenate(
[np.arange(index, index + window_size_ratio) for index in non_wear_elements],
[
np.arange(index, index + window_size_ratio)
for index in non_wear_indices_in_data
],
)
return [
_metashort_row_to_sql_datapoint(row, non_wear=index in non_wear_indices) # type: ignore[arg-type, unused-ignore] # pre-commit mypy flags this, local mypy does not.
Expand Down Expand Up @@ -79,7 +83,7 @@ def timestamp2datetime(
onset_time = timestamp2datetime(onset, day, utc_offset)
wakeup_time = timestamp2datetime(wakeup, day, utc_offset)

if onset_time.hour < 12: # noqa: PLR2004
if datetime.time.fromisoformat(onset).hour < 12: # noqa: PLR2004
onset_time += datetime.timedelta(days=1)
if onset_time > wakeup_time:
wakeup_time += datetime.timedelta(days=1)
Expand Down

0 comments on commit 8abbf4e

Please sign in to comment.