Skip to content

Commit

Permalink
Merge branch 'master' into issue906_create_part6
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentvanhees committed Nov 3, 2023
2 parents cf12d31 + ce4257c commit 70fcedf
Show file tree
Hide file tree
Showing 30 changed files with 1,030 additions and 159 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ RELEASE_CYCLE.md
^docs$
^pkgdown$
^vignettes/chapter*.Rmd
^data-raw$
21 changes: 21 additions & 0 deletions .github/lock.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: 'Lock Threads'

on:
schedule:
- cron: '0 0 1 * *'
workflow_dispatch:

permissions:
issues: write
pull-requests: write

concurrency:
group: lock

jobs:
action:
runs-on: ubuntu-latest
steps:
- uses: dessant/lock-threads@v4
with:
issue-inactive-days: '180'
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export(g.analyse, g.calibrate,
convertEpochData, appendRecords, extractID,
g.part5_analyseSegment, g.part5_initialise_ts,
g.part5.analyseRest, part6AlignIndividuals,
part6PairwiseAggregation, g.part6, g.report.part6)
part6PairwiseAggregation, g.part6, g.report.part6, check_log, g.report.part5_dictionary)


importFrom("grDevices", "colors", "dev.off", "pdf",
"rgb", "rainbow", "palette")
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGES IN GGIR VERSION 3.0-1

- Part 2: Added possibility to csv file with date-oriented definition of study protocol #943

- Part 5: New function to provide definition of the variable names in part 5 reports #938

- Part 2: Bug fix in csv report generation when appending part 2 milestone data with differing number of columns #951

- Part 6: Added as a new part
Expand Down
1 change: 1 addition & 0 deletions R/GGIR.R
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ GGIR = function(mode = 1:5, datadir = c(), outputdir = c(),
week_weekend_aggregate.part5 = params_output[["week_weekend_aggregate.part5"]],
LUX_day_segments = params_247[["LUX_day_segments"]],
verbose = verbose, sep_reports = params_output[["sep_reports"]])
g.report.part5_dictionary(metadatadir = metadatadir, sep_reports = params_output[["sep_reports"]])
} else {
if (verbose == TRUE) cat("\nSkipped because no milestone data available")
}
Expand Down
68 changes: 68 additions & 0 deletions R/check_log.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
check_log = function(log, dateformat, colid = 1, datecols = c(),
logPath, logtype) {

# at the moment this is used only for activity log and study dates log
dateformat_param = ifelse(logtype == "activity log", "qwindow_dateformat", "study_dates_dateformat")

# assume ID to be in first column
log = log[which(log[, colid] != ""),] # ignore rows for which there is no id

# replace cells with only a dot by empty character
# the documentation clearly states that no dots should be used
# to indicate missing value, but this is just in case users still forget about it
for (jn in 1:ncol(log)) {
dotcells = which(log[,jn] == ".")
if (length(dotcells) > 0) {
# is.na(actlog_vec[dotcells]) = TRUE
log[dotcells, jn] = ""
}
}
# Check dates
# extract example date value
if (is.null(datecols)) {
datecols = grep(pattern = "date|Date|DATE", x = colnames(log), value = FALSE)
}
if (length(datecols) > 0) {
exampledates = unlist(log[,datecols])
exampledates = exampledates[which(!is.na(exampledates))]

e1 = strsplit(exampledates, split = "/|-")
e1 = e1[lengths(e1) > 0L]
date_consistency_check = t(as.data.frame(e1))
numrange = apply(X = date_consistency_check, MARGIN = 2, FUN = function(x) diff(range(sapply(x, nchar))))
if (any(numrange > 1)) {
stop(paste0("\nDifferent date formats were encountered in your ",
logtype, ": ", logPath,". ",
"Please note that this may not be visible when you open the ", logtype,
" in MS Excel, but it should be visible in a plain text editor. ",
"To resolve this update the format for all date cells in the ",
"log to be consistent and in line with the value of argument",
dateformat_param, ", which is currently: ", dateformat), call. = FALSE)
}
} else {
exampledates = c()
}

Nhyphen = length(grep(pattern = "-", x = log[, datecols]))
Ndash = length(grep(pattern = "/", x = log[, datecols]))
if (Nhyphen > 0 & Ndash > 0) {
warning(paste0("\nYou may be mixing slash and hyphen separated dates ",
"inside the same ", logtype , ", which could lead to errors. ",
"Please fix."),
call. = FALSE)
}
# Replace / by - if that is what is expected dateformat
if (Ndash > 0 & length(grep(pattern = "/", x = dateformat)) == 0) {
for (rc in 1:ncol(log)) {
log[, rc] = gsub(pattern = "/", replacement = "-", x = log[, rc])
}
}
# Replace - by / if that is what is expected dateformat
if (Nhyphen > 0 & length(grep(pattern = "-", x = dateformat)) == 0) {
for (rc in 1:ncol(log)) {
log[, rc] = gsub(pattern = "-", replacement = "/", x = log[, rc])
}
}
# return
return(log)
}
29 changes: 17 additions & 12 deletions R/check_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ check_params = function(params_sleep = c(), params_metrics = c(),

}
if (length(params_cleaning) > 0) {
numeric_params = c("includedaycrit", "ndayswindow", "strategy", "maxdur", "hrs.del.start",
numeric_params = c("includedaycrit", "ndayswindow", "data_masking_strategy", "maxdur", "hrs.del.start",
"hrs.del.end", "includedaycrit.part5", "minimum_MM_length.part5",
"includenightcrit", "max_calendar_days")
boolean_params = c("excludefirstlast.part5", "do.imp", "excludefirstlast",
Expand Down Expand Up @@ -213,24 +213,29 @@ check_params = function(params_sleep = c(), params_metrics = c(),
}

if (length(params_cleaning) > 0) {
if (params_cleaning[["strategy"]] %in% c(2, 4) & params_cleaning[["hrs.del.start"]] != 0) {
warning(paste0("\nSetting argument hrs.del.start in combination with strategy = ",
params_cleaning[["strategy"]]," is not meaningful, because this is only used when straytegy = 1"), call. = FALSE)
# overwrite data_masking_strategy with strategy in case the latter is used
if (params_cleaning[["strategy"]] != params_cleaning[["data_masking_strategy"]]
& params_cleaning[["strategy"]] != 1) {
params_cleaning[["data_masking_strategy"]] = params_cleaning[["strategy"]]
}
if (params_cleaning[["strategy"]] %in% c(2, 4) & params_cleaning[["hrs.del.end"]] != 0) {
warning(paste0("\nSetting argument hrs.del.end in combination with strategy = ",
params_cleaning[["strategy"]]," is not meaningful, because this is only used when straytegy = 1"), call. = FALSE)
if (params_cleaning[["data_masking_strategy"]] %in% c(2, 4) & params_cleaning[["hrs.del.start"]] != 0) {
warning(paste0("\nSetting argument hrs.del.start in combination with data_masking_strategy = ",
params_cleaning[["data_masking_strategy"]]," is not meaningful, because this is only used when straytegy = 1"), call. = FALSE)
}
if (!(params_cleaning[["strategy"]] %in% c(3, 5)) & params_cleaning[["ndayswindow"]] != 7) {
warning(paste0("\nSetting argument ndayswindow in combination with strategy = ",
params_cleaning[["strategy"]]," is not meaningful, because this is only used when strategy = 3 or strategy = 5"), call. = FALSE)
if (params_cleaning[["data_masking_strategy"]] %in% c(2, 4) & params_cleaning[["hrs.del.end"]] != 0) {
warning(paste0("\nSetting argument hrs.del.end in combination with data_masking_strategy = ",
params_cleaning[["data_masking_strategy"]]," is not meaningful, because this is only used when straytegy = 1"), call. = FALSE)
}
if (params_cleaning[["strategy"]] == 5 &
if (!(params_cleaning[["data_masking_strategy"]] %in% c(3, 5)) & params_cleaning[["ndayswindow"]] != 7) {
warning(paste0("\nSetting argument ndayswindow in combination with data_masking_strategy = ",
params_cleaning[["data_masking_strategy"]]," is not meaningful, because this is only used when data_masking_strategy = 3 or data_masking_strategy = 5"), call. = FALSE)
}
if (params_cleaning[["data_masking_strategy"]] == 5 &
params_cleaning[["ndayswindow"]] != round(params_cleaning[["ndayswindow"]])) {
newValue = round(params_cleaning[["ndayswindow"]])
warning(paste0("\nArgument ndayswindow has been rounded from ",
params_cleaning[["ndayswindow"]], " to ", newValue, " days",
"because when strategy == 5 we expect an integer value", call. = FALSE))
"because when data_masking_strategy == 5 we expect an integer value", call. = FALSE))
params_cleaning[["ndayswindow"]] = newValue
}
if (length(params_cleaning[["data_cleaning_file"]]) > 0) {
Expand Down
2 changes: 1 addition & 1 deletion R/createConfigFile.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ createConfigFile = function(config.parameters = c(), GGIRversion = "") {
"backup.cal.coef", "dayborder", "dynrange",
"configtz", "do.lfen", "hb", "lb", "n", "myfun") == TRUE) {
out[i,3] = "Calibration, Feature extraction, Epoch size, Time zone"
} else if (NM %in% c("strategy", "hrs.del.start", "hrs.del.end", "maxdur",
} else if (NM %in% c("strategy", "data_masking_strategy", "hrs.del.start", "hrs.del.end", "maxdur",
"includedaycrit", "M5L5res", "winhr", "qwindow", "qlevels",
"ilevels", "mvpathreshold", "boutcriter", "ndayswindow",
"do.imp", "epochvalues2csv", "mvpadur",
Expand Down
18 changes: 11 additions & 7 deletions R/g.analyse.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
g.analyse = function(I, C, M, IMP, params_247 = c(), params_phyact = c(),
params_general = c(), params_cleaning = c(),
quantiletype = 7, myfun = c(), ...) {
quantiletype = 7, myfun = c(), ID, ...) {

#get input variables
input = list(...)
Expand Down Expand Up @@ -34,7 +34,11 @@ g.analyse = function(I, C, M, IMP, params_247 = c(), params_phyact = c(),

fname = I$filename
averageday = IMP$averageday
strategy = IMP$strategy
if (is.null(IMP$data_masking_strategy)) {
data_masking_strategy = IMP$strategy
} else {
data_masking_strategy = IMP$data_masking_strategy
}
hrs.del.start = IMP$hrs.del.start
hrs.del.end = IMP$hrs.del.end
maxdur = IMP$maxdur
Expand Down Expand Up @@ -67,7 +71,7 @@ g.analyse = function(I, C, M, IMP, params_247 = c(), params_phyact = c(),
}
#----------------------
# Extract ID centrally
ID = extractID(hvars = hvars, idloc = idloc, fname = I$filename)
# ID = extractID(hvars = hvars, idloc = idloc, fname = I$filename)

#--------------------------------------------------------------
# Extract qwindow if an activity log is provided:
Expand Down Expand Up @@ -144,7 +148,7 @@ g.analyse = function(I, C, M, IMP, params_247 = c(), params_phyact = c(),
midnights = dmidn$midnights; midnightsi = dmidn$midnightsi
starttimei = 1
endtimei = nrow(M$metalong)
if (strategy == 2) {
if (data_masking_strategy == 2) {
starttimei = firstmidnighti
endtimei = lastmidnighti - 1
}
Expand Down Expand Up @@ -230,8 +234,8 @@ g.analyse = function(I, C, M, IMP, params_247 = c(), params_phyact = c(),
myfun = myfun, desiredtz = desiredtz,
params_247 = params_247, params_phyact = params_phyact)
}
#metashort is shortened from midgnight to midnight if requested (strategy 2)
if (strategy == 2) {
#metashort is shortened from midgnight to midnight if requested (data_masking_strategy 2)
if (data_masking_strategy == 2) {
if (starttimei == 1) {
metashort = as.matrix(metashort[starttimei:(endtimei*(ws2/ws3)),])
} else {
Expand All @@ -250,7 +254,7 @@ g.analyse = function(I, C, M, IMP, params_247 = c(), params_phyact = c(),
lookat = lookattmp[which(lookattmp > 1)] #]c(2:ncol(metashort[,lookattmp]))
colnames_to_lookat = colnames(metashort)[lookat]
AveAccAve24hr = matrix(NA,length(lookat),1)
if (length(which(r5 == 0)) > 0) { #to catch strategy 2 with only 1 midnight and other cases where there is no valid data
if (length(which(r5 == 0)) > 0) { #to catch data_masking_strategy 2 with only 1 midnight and other cases where there is no valid data
for (h in 1:length(lookat)) {
average24h = matrix(0,n_ws3_perday,1)
average24hc = matrix(0,n_ws3_perday,1)
Expand Down
8 changes: 4 additions & 4 deletions R/g.analyse.perfile.R
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ g.analyse.perfile = function(I, C, metrics_nav,
}
vi = vi + 6 + ((dtwtel * sp) - 1)
}
filesummary[vi] = params_cleaning[["strategy"]]
filesummary[vi] = params_cleaning[["data_masking_strategy"]]
filesummary[(vi + 1)] = params_cleaning[["hrs.del.start"]]
filesummary[(vi + 2)] = params_cleaning[["hrs.del.end"]]
filesummary[(vi + 3)] = params_cleaning[["maxdur"]]
Expand All @@ -277,9 +277,9 @@ g.analyse.perfile = function(I, C, metrics_nav,
s_names[vi:(vi + 6)] = as.character(c(paste0("data exclusion stategy (value=1, ignore specific hours;",
" value=2, ignore all data before the first midnight and",
" after the last midnight)"),
"n hours ignored at start of meas (if strategy=1)",
"n hours ignored at end of meas (if strategy=1)",
"n days of measurement after which all data is ignored (if strategy=1)",
"n hours ignored at start of meas (if data_masking_strategy=1)",
"n hours ignored at end of meas (if data_masking_strategy=1)",
"n days of measurement after which all data is ignored (if data_masking_strategy=1)",
"epoch size to which acceleration was averaged (seconds)",
"if_hip_long_axis_id", "GGIR version"))
vi = vi + 6
Expand Down
59 changes: 4 additions & 55 deletions R/g.conv.actlog.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,62 +23,11 @@ g.conv.actlog = function(qwindow, qwindow_dateformat="%d-%m-%Y", epochSize = 5)

# Read content of activity diary file
actlog = data.table::fread(file = qwindow, data.table = FALSE)
# assume ID to be in first column
actlog = actlog[which(actlog[,1] != ""),] # ignore rows for which there is no id

# replace cells with only a dot by empty character
# the documentation clearly states that no dots should be used
# to indeicate missing value, but this is just in case users still forget about it
for (jn in 1:ncol(actlog)) {
dotcells = which(actlog[,jn] == ".")
if (length(dotcells) > 0) {
# is.na(actlog_vec[dotcells]) = TRUE
actlog[dotcells, jn] = ""
}
}
# extract example date value
datecols = grep(pattern = "date|Date|DATE", x = colnames(actlog), value = FALSE)
if (length(datecols) > 0) {
exampledates = unlist(actlog[,datecols])
exampledates = exampledates[which(!is.na(exampledates))]

e1 = strsplit(exampledates, split = "/|-")
e1 = e1[lengths(e1) > 0L]
date_consistency_check = t(as.data.frame(e1))
numrange = apply(X = date_consistency_check, MARGIN = 2, FUN = function(x) diff(range(sapply(x, nchar))))
if (any(numrange > 1)) {
stop(paste0("\nDifferent date formats were encountered in your activity ",
"log: ",qwindow,". ",
"Please note that this may not be visible when you open the activity log",
" in MS Excel, but it should be visible in a plain text editor. ",
"To resolve this update the format for all date cells in the ",
"activity log to be consistent and in line with the value of argument",
" qwindow_dateformat, which is currently: ", qwindow_dateformat), call. = FALSE)
}
} else {
exampledates = c()
}

Nhyphen = length(grep(pattern = "-", x = actlog[, datecols]))
Ndash = length(grep(pattern = "/", x = actlog[, datecols]))
if (Nhyphen > 0 & Ndash > 0) {
warning(paste0("\nYou may be mixing slash and hyphen separated dates ",
"inside the same activity diary, which could lead to errors. ",
"Please fix."),
call. = FALSE)
}
# Replace / by - if that is what is expected dateformat
if (Ndash > 0 & length(grep(pattern = "/", x = qwindow_dateformat)) == 0) {
for (rc in 1:ncol(actlog)) {
actlog[, rc] = gsub(pattern = "/", replacement = "-", x = actlog[, rc])
}
}
# Replace - by / if that is what is expected dateformat
if (Nhyphen > 0 & length(grep(pattern = "-", x = qwindow_dateformat)) == 0) {
for (rc in 1:ncol(actlog)) {
actlog[, rc] = gsub(pattern = "-", replacement = "/", x = actlog[, rc])
}
}
# check ID and date cols in actlog
actlog = check_log(actlog, dateformat = qwindow_dateformat,
colid = 1, datecols = NULL,
logPath = qwindow, logtype = "activity log")

# find dates
actlog_vec = unlist(actlog) # turn into vector
Expand Down
Loading

0 comments on commit 70fcedf

Please sign in to comment.