Skip to content

Commit 9463850

Browse files
committed
identify next noon in last spt even when recording ends before the next 12pm
1 parent 4cf0403 commit 9463850

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

R/aggregate_per_date.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,13 @@ aggregate_per_date = function(tsDir, epoch, classifier, classes,
110110
start_end_nighttime_dates = NULL
111111
for (ni in 1:length(start_end_nighttime$ends)) {
112112
next_noon = which(noons > start_end_nighttime$ends[ni])[1]
113-
start_end_nighttime_dates[ni] = ts$date[noons[next_noon]]
113+
if (is.na(next_noon)) {
114+
# if there is not a next_noon, meaning that recording finished before 12pm
115+
# following the last wake up
116+
start_end_nighttime_dates[ni] = as.character(as.Date(ts$date[noons[length(noons)]]) + 1)
117+
} else {
118+
start_end_nighttime_dates[ni] = ts$date[noons[next_noon]]
119+
}
114120
}
115121
# start_end_nighttime_dates = ts$date[start_end_nighttime$ends] # dates based on wakeup
116122
rows2fill = which(availableDates %in% start_end_nighttime_dates)

0 commit comments

Comments
 (0)