Skip to content

Commit 1013697

Browse files
committed
fix issue with date assignation to sleep periods
1 parent 05f3c72 commit 1013697

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ LazyData: true
2020
Suggests:
2121
testthat (>= 3.0.0), randomForest, gsignal, rattle
2222
Config/testthat/edition: 3
23-
RoxygenNote: 7.3.1
23+
RoxygenNote: 7.3.2
2424
Depends:
2525
R (>= 2.10)
2626
Imports:

NEWS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# actimetric 0.1.4
22

3-
* Time series: stores classes as factor in time series to ease interpretation #51
3+
* Time series:
4+
- stores classes as factor in time series to ease interpretation #51
5+
- fixed minor bug related to assignation of date to sleep periods #60
46
* Documentation: minor revision of documentation for functions check_classifier and getBout #41
57
* Reading data: minor revision of ReadAndCalibrate when reading ActiGraph devices with the Idle Sleep Mode activated #58
68

R/aggregate_per_date.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,15 @@ aggregate_per_date = function(tsDir, epoch, classifier, classes,
104104
return(list(starts = starts, ends = ends))
105105
}
106106
if ("nighttime.awake" %in% classes) {
107+
noons = which(ts$time == "12:00:00")
107108
start_end_nighttime = find_start_end(ts, column = "activity",
108109
class = c("nighttime.awake", "nighttime.sleep"))
109-
start_end_nighttime_dates = ts$date[start_end_nighttime$ends] # dates based on wakeup
110+
start_end_nighttime_dates = NULL
111+
for (ni in 1:length(start_end_nighttime$ends)) {
112+
next_noon = which(noons > start_end_nighttime$ends[ni])[1]
113+
start_end_nighttime_dates[ni] = ts$date[noons[next_noon]]
114+
}
115+
# start_end_nighttime_dates = ts$date[start_end_nighttime$ends] # dates based on wakeup
110116
rows2fill = which(availableDates %in% start_end_nighttime_dates)
111117
ds[rows2fill, ci] = as.character(ts$timestamp[start_end_nighttime$starts])
112118
ds[rows2fill, ci + 1] = as.character(ts$timestamp[start_end_nighttime$ends])

R/classifySleep.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ classifySleep = function(anglez, starttime, classifier, infoClassifier, ts, do.s
129129
ts$activity[which(ts$sleep_periods == 1)] = sleep_id
130130
}
131131
}
132+
# recode nighttime as nighttime.awake and sleep as nighttime.sleep
133+
classes = gsub("nighttime", "nighttime.awake", classes)
134+
classes = gsub("sleep", "nighttime.sleep", classes)
132135
activity = factor(x = ts$activity, levels = 1:length(classes), labels = classes)
133136
return(activity)
134137
}

0 commit comments

Comments
 (0)