Skip to content

Commit

Permalink
Merge branch 'master' into issue653_step_updated_withmaster
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentvanhees committed Oct 1, 2024
2 parents 241be6c + 7a402c7 commit 8d34347
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 18 deletions.
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# CHANGES IN GGIR VERSION 3.1-?

- Part 5: Fixed minor bug in g.part5.addfirstwake causing the first wake is not correctly added when
no SIBs are detected from the beginning of the recording until the first detected night. #1198

- Part 5: Add parameters require_complete_lastnight_part5 to control whether last window is included if last night is incomplete. #1196

- General: GGIR version look-up in .onattach() no longer crashes when computer is offline, fixes #1203.

- Reports: The calendar_date and filename columns in reports have been standardized, as %Y-%m-%d and the input accelerometer file name, respectively. #1197

# CHANGES IN GGIR VERSION 3.1-4

- Part 3: Update threshold used for HorAngle to 60 degree, and auto-setting HASPT.ignore.invalid to NA when NotWorn guider is used. #1186
Expand Down
2 changes: 1 addition & 1 deletion R/GGIR.R
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ GGIR = function(mode = 1:5, datadir = c(), outputdir = c(),
g.report.part2(metadatadir = metadatadir, f0 = f0, f1 = f1,
maxdur = params_cleaning[["maxdur"]],
store.long = store.long, params_output,
verbose = verbose)
verbose = verbose, desiredtz = params_general[["desiredtz"]])
}
}
if (length(which(do.report == 4)) > 0) {
Expand Down
2 changes: 2 additions & 0 deletions R/g.part5.R
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ g.part5 = function(datadir = c(), metadatadir = c(), f0=c(), f1=c(),
# convert to character/numeric if stored as factor in metashort and metalong
M$metashort = correctOlderMilestoneData(M$metashort)
M$metalong = correctOlderMilestoneData(M$metalong)
filename = filename_dir
# load output g.part3
longitudinal_axis = NULL # initialise var that is part of ms3.out
load(paste0(metadatadir, "/meta/ms3.out/", fnames.ms3[i]))
Expand Down Expand Up @@ -601,6 +602,7 @@ g.part5 = function(datadir = c(), metadatadir = c(), f0=c(), f1=c(),
ID = ID,
params_output = params_output,
params_247 = params_247,
filename = filename,
timewindow = timewindowi)
}
}
Expand Down
6 changes: 4 additions & 2 deletions R/g.part5.addfirstwake.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ g.part5.addfirstwake = function(ts, summarysleep, nightsi, sleeplog, ID,
if (is.na(wake_night1_index)) wake_night1_index = 0
if (wake_night1_index < firstwake & wake_night1_index > 1 &
(wake_night1_index - 1) > nightsi[1]) {
newWakeIndex = max(which(ts$sibdetection[1:(wake_night1_index - 1)] == 1))
newWakeIndex = c()
firstSIBs = which(ts$sibdetection[1:(wake_night1_index - 1)] == 1)
if (length(firstSIBs) > 0) newWakeIndex = max(firstSIBs)
if (length(newWakeIndex) == 0) {
newWakeIndex = wake_night1_index - 1
}
Expand All @@ -94,4 +96,4 @@ g.part5.addfirstwake = function(ts, summarysleep, nightsi, sleeplog, ID,
}
}
return(ts)
}
}
5 changes: 3 additions & 2 deletions R/g.part5.savetimeseries.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ g.part5.savetimeseries = function(ts, LEVELS, desiredtz, rawlevels_fname,
includedaycrit.part5 = 2/3, ID = NULL,
params_output,
params_247 = NULL,
filename = "",
timewindow = NULL) {

ms5rawlevels = data.frame(date_time = ts$time, class_id = LEVELS,
# class_name = rep("",Nts),
stringsAsFactors = FALSE)
Expand Down Expand Up @@ -104,7 +105,7 @@ g.part5.savetimeseries = function(ts, LEVELS, desiredtz, rawlevels_fname,
mdat$timestamp = as.POSIXct(mdat$timenum, origin = "1970-01-01",tz = desiredtz)
rawlevels_fname = gsub(pattern = ".csv", replacement = ".RData", x = rawlevels_fname)
fname = unique(rawlevels_fname[grep("*RData$", rawlevels_fname)])
save(mdat, file = fname)
save(mdat, filename, file = fname)
}
#===============================
rm(mdat)
Expand Down
9 changes: 5 additions & 4 deletions R/g.part6.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ g.part6 = function(datadir = c(), metadatadir = c(), f0 = c(), f1 = c(),
} else {
mdat = data.table::fread(file = paste0(metadatadir, "/meta/ms5.outraw/",
params_phyact[["part6_threshold_combi"]], "/", fnames.ms5raw[i]), data.table = FALSE)
filename = fnames.ms5raw[i]
}
nfeatures = 50
summary = matrix(NA, nfeatures, 1)
Expand Down Expand Up @@ -188,7 +189,7 @@ g.part6 = function(datadir = c(), metadatadir = c(), f0 = c(), f1 = c(),
summary[fi] = format(starttime)
s_names[fi] = "starttime"
fi = fi + 1
summary[fi] = gsub(pattern = "[.]RData|[.]csv", replacement = "", x = fnames.ms5raw[i])
summary[fi] = gsub(pattern = "[.]RData$|[.]csv$", replacement = "", x = filename)
s_names[fi] = "filename"
fi = fi + 1
summary[fi] = ifelse(test = nrow(ts) == 1,
Expand Down Expand Up @@ -281,9 +282,9 @@ g.part6 = function(datadir = c(), metadatadir = c(), f0 = c(), f1 = c(),
}
output_part6$GGIRversion = GGIRversion
save(output_part6, GGIRversion, file = paste0(metadatadir, ms6.out, "/",
gsub(pattern = "[.]csv|[.]RData",
replacement = "",
x = fnames.ms5raw[i]), ".RData"))
gsub(pattern = "[.]csv|[.]RData",
replacement = "",
x = fnames.ms5raw[i]), ".RData"))
}
rm(output_part6, summary)
}
Expand Down
12 changes: 10 additions & 2 deletions R/g.report.part2.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
g.report.part2 = function(metadatadir = c(), f0 = c(), f1 = c(), maxdur = 0,
store.long = FALSE, params_output, myfun = c(), verbose = TRUE) {
store.long = FALSE, params_output, myfun = c(), verbose = TRUE,
desiredtz = "") {
ms2.out = "/meta/ms2.out"
if (file.exists(paste0(metadatadir,ms2.out))) {
if (length(dir(paste0(metadatadir,ms2.out))) == 0) {
Expand Down Expand Up @@ -278,7 +279,14 @@ g.report.part2 = function(metadatadir = c(), f0 = c(), f1 = c(), maxdur = 0,
if (length(SUMMARY) > 0 & length(daySUMMARY) > 0) {
SUMMARY_clean = tidyup_df(SUMMARY)
daySUMMARY_clean = tidyup_df(daySUMMARY)

daySUMMARY_clean$start_time = daySUMMARY_clean$calendar_date
# reorder to have starttime next to calendar_date
old_vars = which(colnames(daySUMMARY_clean) != "start_time")
new_var = which(colnames(daySUMMARY_clean) == "start_time")
daySUMMARY_clean = daySUMMARY_clean[, c(old_vars[1:3], new_var, old_vars[4:length(old_vars)])]
# format calendar dates
dd = iso8601chartime2POSIX(daySUMMARY_clean$calendar_date, tz = desiredtz)
daySUMMARY_clean$calendar_date = format(dd, format = "%Y-%m-%d")
#===============================================================================
# store final matrices again
data.table::fwrite(x = SUMMARY_clean, file = paste0(metadatadir, "/results/part2_summary.csv"),
Expand Down
3 changes: 3 additions & 0 deletions R/g.report.part4.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ g.report.part4 = function(datadir = c(), metadatadir = c(), loglocation = c(),
}
nightsummary2 = as.data.frame(do.call(rbind, lapply(fnames.ms4, myfun)), stringsAsFactors = FALSE)
nightsummary2$night = as.numeric(gsub(" ", "", nightsummary2$night))
nightsummary2$calendar_date = as.Date(nightsummary2$calendar_date, format = "%d/%m/%Y")
nightsummary2$calendar_date = format(nightsummary2$calendar_date, format = "%Y-%m-%d")
nightsummary2$filename = gsub(".RData$", "", nightsummary2$filename)
# ====================================== Add non-wearing during SPT from part 5, if it is availabe:
ms5.out = "/meta/ms5.out"
if (file.exists(paste(metadatadir, ms5.out, sep = ""))) {
Expand Down
3 changes: 3 additions & 0 deletions R/g.report.part5.R
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ g.report.part5 = function(metadatadir = c(), f0 = c(), f1 = c(), loglocation = c
outputfinal = outputfinal[,-cut]
}

# revise filename
outputfinal$filename = gsub(".RData$", "", outputfinal$filename)

# order data.frame
outputfinal$window_number = as.numeric(gsub(" ", "", outputfinal$window_number))
outputfinal = outputfinal[order(outputfinal$filename, outputfinal$window_number, outputfinal$window), ]
Expand Down
1 change: 1 addition & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
}
pkgs <- available.packages(repos = repos)
cran_version <- package_version(pkgs[which(pkgs[,1] == "GGIR"),"Version"])
if (length(cran_version) == 0) return() # handle no internet connection
local_version <- packageVersion("GGIR")
behind_cran <- cran_version > local_version
if (interactive()) {
Expand Down
9 changes: 7 additions & 2 deletions man/g.part5.savetimeseries.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
includedaycrit.part5 = 2/3,
ID = NULL, params_output,
params_247 = NULL,
filename = "",
timewindow = NULL)
}
\arguments{
Expand All @@ -26,7 +27,7 @@
See \link{GGIR}.
}
\item{rawlevels_fname}{
Path to the file where the output should be stored
Path to the file where the output (time series) should be stored
}
\item{DaCleanFile}{
Content of data_cleaning_file as documented in \link{g.report.part5}.
Expand All @@ -49,6 +50,10 @@
\item{params_247}{
See \link{GGIR}
}
\item{filename}{
Character (default = "") indicating the name of the accelerometer data file
that was used as input. This name will be stored inside the time series output file.
}
\item{timewindow}{
See \link{GGIR}
}
Expand All @@ -60,4 +65,4 @@
\keyword{internal}
\author{
Vincent T van Hees <v.vanhees@accelting.com>
}
}
6 changes: 5 additions & 1 deletion man/g.report.part2.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
}
\usage{
g.report.part2(metadatadir = c(), f0 = c(), f1 = c(), maxdur = 0,
store.long = FALSE, params_output, myfun = c(), verbose = TRUE)
store.long = FALSE, params_output, myfun = c(),
verbose = TRUE, desiredtz = "")
}
\arguments{
\item{metadatadir}{
Expand Down Expand Up @@ -44,6 +45,9 @@
\item{verbose}{
See details in \link{GGIR}.
}
\item{desiredtz}{
See details in \link{GGIR}.
}
}
\value{
Function does not produce data, but only writes reports
Expand Down
11 changes: 7 additions & 4 deletions tests/testthat/test_part6.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ test_that("Part 6 with household co-analysis", {
data(data.ts)
mdat = data.ts
mdat$timenum = mdat$timenum - (5 * 60)
save(mdat, file = paste0(dn, "/800-900-001_left wrist.RData"))
filename = "800-900-001_left wrist.bin"
save(mdat, filename, file = paste0(dn, "/800-900-001_left wrist.RData"))
mdat$timenum = mdat$timenum + (7 * 60)
save(mdat, file = paste0(dn, "/800-900-002_left wrist.RData"))
filename = "800-900-002_left wrist.bin"
save(mdat, filename, file = paste0(dn, "/800-900-002_left wrist.RData"))
mdat$timenum = mdat$timenum + (14 * 60)
save(mdat, file = paste0(dn, "/800-900-003_left wrist.RData"))
filename = "800-900-003_left wrist.bin"
save(mdat, filename, file = paste0(dn, "/800-900-003_left wrist.RData"))

# Run household co-analysis
# Update parameters to align with datset
# Update parameters to align with dataset
params_general = load_params(topic = "general")$params_general
params_general[["desiredtz"]] = "America/Curacao"
params_phyact = load_params(topic = "phyact")$params_phyact
Expand Down

0 comments on commit 8d34347

Please sign in to comment.