Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with non-default dayborder in part 5 #1008

Merged
merged 8 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- Part 1: Fix bug where on machines with GMT timezone and R >= 4.3.0, for GENEActiv .bin files, the starting timestamps of M$metalong and M$metashort were truncated to midninght #1000

- Part 5: Fix bug where part5 output showed duplicate rows when argument dayborder is set to nondefault value #1006

# CHANGES IN GGIR VERSION 3.0-2

- Part 2: Fix bug that caused part 2 to struggle with corrupt ActiGraph .gt3x files #972
Expand Down
7 changes: 1 addition & 6 deletions R/g.analyse.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
n_ws2_perday = (1440*60) / ws2
n_ws3_perday = (1440*60) / ws3
if (((nrow(metalong)/((1440*60)/ws2)*10) - (nrow(metashort)/((60/ws3)*1440)) * 10) > 1) {
cat("Matrices 'metalong' and 'metashort' are not compatible")
stop("Matrices 'metalong' and 'metashort' are not compatible")

Check warning on line 70 in R/g.analyse.R

View check run for this annotation

Codecov / codecov/patch

R/g.analyse.R#L70

Added line #L70 was not covered by tests
}
#----------------------
# Extract ID centrally
Expand Down Expand Up @@ -168,9 +168,6 @@
# LW = length(which(as.numeric(qcheck) != 1)) / (60/ws3) #number of minutes wear time between first and last midnights
nfulldays = (lastmidnighti - firstmidnighti) / ((3600/ws2)*24)
ndays = length(midnights) + 1 #ceiling(nfulldays + 2) # ceiling to cope with days with 23 hours
if (ndays != round(ndays)) { #day saving time causing trouble?
cat("One day in this measurement is longer or shorter than 24 hours (probably related to day saving time)")
}
#-------------------------------------
# Detect orientation (at the moment only desighned for hip with accelerometer):
# assess which angle per axis is most strongly 24 hour correlated:
Expand Down Expand Up @@ -279,8 +276,6 @@
average24h = average24h / average24hc
AveAccAve24hr[h] = mean(average24h) #average acceleration in an average 24 hour cycle
}
} else {
cat("file skipped for general average caculation because not enough data")
}
rm(metalong); rm(metashort)
dataqual_summary = data.frame(clipping_score = LC2 / ((LD/1440)*96),
Expand Down
4 changes: 1 addition & 3 deletions R/g.analyse.perday.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@
if (firstmidnighti == 1) { #if measurement starts at midnight
ndays = ndays - 1
startatmidnight = 1
cat("measurement starts at midnight or there is no midnight")
}
if (lastmidnight == time[length(time)] & nrow(metashort) < ((60/ws3) * 1440)) { #if measurement ends at midnight
ndays = ndays - 1
endatmidnight = 1
cat("measurement ends at midnight or there is no midnight")
}
}

Expand Down Expand Up @@ -141,7 +139,7 @@
if (length(params_247[["qwindow"]]) < 2) params_247[["qwindow"]] = c()
if (length(params_247[["qwindow"]]) > 0) {
if (length(qwindow_names) == 1) {
cat("Argument to qwindow is invalid, requires a vector of at least length 2")
warning("Argument to qwindow is invalid, requires a vector of at least length 2")

Check warning on line 142 in R/g.analyse.perday.R

View check run for this annotation

Codecov / codecov/patch

R/g.analyse.perday.R#L142

Added line #L142 was not covered by tests
}
if (length(qwindow_names) == 2) {
if (params_247[["qwindow"]][1] != 0 | params_247[["qwindow"]][2] != 24) {
Expand Down
5 changes: 3 additions & 2 deletions R/g.part5.definedays.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ g.part5.definedays = function(nightsi, wi, indjump, nightsi_bu,
if (nightsi[1] == 1) {
wi = wi + 1
# add extra nightsi to get the last day processed (as wi has been increased by 1)
nightsi = c(nightsi, nightsi + (24*(60/epochSize) * 60) - 1)
nightsi = c(nightsi, nightsi[length(nightsi)] + (24*(60/epochSize) * 60))
}
if (length(nightsi) >= wi) {
if (wi == 1) {
Expand Down Expand Up @@ -89,6 +89,7 @@ g.part5.definedays = function(nightsi, wi, indjump, nightsi_bu,
# in MM, also define segments of the day based on qwindow
if (!is.na(qqq[1]) & !is.na(qqq[2])) {
fullQqq = qqq[1]:qqq[2]
firstepoch = format(ts$time[qqq[1]], "%H:%M:%S")
lastepoch = format(ts$time[qqq[2]], "%H:%M:%S")
qnames = NULL
if (is.data.frame(qwindow)) {
Expand All @@ -108,7 +109,7 @@ g.part5.definedays = function(nightsi, wi, indjump, nightsi_bu,
}
# build up segments
segments = list(qqq)
segments_timing = paste("00:00:00", lastepoch, sep = "-")
segments_timing = paste(firstepoch, lastepoch, sep = "-")
segments_names = "MM"
si = 2
do.segments = TRUE
Expand Down
10 changes: 3 additions & 7 deletions R/g.report.part5.R
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ g.report.part5 = function(metadatadir = c(), f0 = c(), f1 = c(), loglocation = c
out = base::merge(tmp, out, all = TRUE)
}
if (length(tail_expansion_log) != 0) {
# col2na = grep(pattern = "spt|sleeplog_used",
# x = names(out), value = FALSE)
col2na = grep(pattern = paste0("sleep_efficiency|N_atleast5minwakenight|daysleeper|",
"daysleeper|sleeplog_used|_spt_sleep|_spt_wake"),
x = names(out), value = FALSE)
Expand All @@ -146,10 +144,8 @@ g.report.part5 = function(metadatadir = c(), f0 = c(), f1 = c(), loglocation = c

# order data.frame
outputfinal$window_number = as.numeric(gsub(" ", "", outputfinal$window_number))
# outputfinal_segments = outputfinal[which(!outputfinal$window %in% c("MM", "WW")),]
# outputfinal = outputfinal[which(outputfinal$window %in% c("MM", "WW")),]
outputfinal = outputfinal[order(outputfinal$filename, outputfinal$window, outputfinal$window_number),]

outputfinal = outputfinal[order(outputfinal$filename, outputfinal$window_number, outputfinal$window), ]

# split results to different spreadsheets in order to minimize individual
# filesize and to ease organising dataset
uwi = as.character(unique(outputfinal$window))
Expand Down Expand Up @@ -475,7 +471,7 @@ g.report.part5 = function(metadatadir = c(), f0 = c(), f1 = c(), loglocation = c
}
OF3tmp = OF3[, columns2keep]
foo34 = function(df,aggPerIndividual,nameold,namenew,cval,window) {
# function to help with calculating additinal variables
# function to help with calculating additional variables
# related to counting how many days of measurement there are
# that meet a certain criteria
# cval is a vector with 0 and 1, indicating whether the criteria is met
Expand Down