Skip to content

Commit

Permalink
#1218 improve extraction of timewindow from log and ignore column wit…
Browse files Browse the repository at this point in the history
…h the word impute
  • Loading branch information
vincentvanhees committed Nov 20, 2024
1 parent 3b8e914 commit c9d26af
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
17 changes: 14 additions & 3 deletions R/filterNonwearNight.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,21 @@ filterNonwearNight = function(r1, metalong, qwindowImp, desiredtz,
r1B$date = as.Date(metalong$time_POSIX)
for (qi in 1:nrow(qwindowImp)) {
qwindow_temp = qwindowImp$qwindow_values[[qi]]
# filter only SPT and time in bed reports
qwindow_temp = qwindow_temp[grep(pattern = "bed|wakeup|sleeponset", x = qwindowImp$qwindow_names[[qi]])]
qwindow_temp = sort(qwindow_temp)
if (length(qwindow_temp) > 3) {
# if diary has at least two timestamps other than 0 and 24
start = rev(qwindow_temp)[2]
end = qwindow_temp[2]
# convert to continuous scale to ease finding start and end
below18 = which(qwindow_temp < 18)
if (length(below18) > 0) {
qwindow_temp = qwindow_temp[below18] + 24
}
start = min(qwindow_temp)
end = max(qwindow_temp)
if (length(below18) > 0) {
start = ifelse(start > 24, yes = start - 24, no = start)
end = ifelse(end > 24, yes = end - 24, no = end)
}
if (start > end) {
r1B$filterWindow[which(r1B$date == qwindowImp$date[qi] &
r1B$hr >= start |
Expand Down
1 change: 1 addition & 0 deletions R/g.conv.actlog.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ g.conv.actlog = function(qwindow, qwindow_dateformat="%d-%m-%Y", epochSize = 5)
# local functions:
time2numeric = function(x) {
x = unlist(x)
x = x[grep(pattern = "impute", x = names(x), invert = TRUE)]
c2t = function(x2) {
tmp = as.numeric(unlist(strsplit(as.character(x2),":")))
if (length(tmp) == 2) hourinday = tmp[1] + (tmp[2]/60)
Expand Down
2 changes: 1 addition & 1 deletion man/GGIR.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ GGIR(mode = 1:5,
defined by activity diary file and a diary entry is missing use midnight-6am
as fall back setting. The main purpose of this functionality is to offer
the option to ignore short lasting nonwear episodes during the night
when there is suspicious that these are falsely detect, e.g. in individuals
when there is suspicion that these are falsely detect, e.g. in individuals
with extended motionless sleep periods caused by medication.}
\item{nonwearFilterWindow}{
Expand Down

0 comments on commit c9d26af

Please sign in to comment.