Skip to content

Commit

Permalink
Merge pull request #893 from wadpac/issue879_bugVisualization
Browse files Browse the repository at this point in the history
Issue879 bug visualization
  • Loading branch information
vincentvanhees authored Sep 11, 2023
2 parents 406d939 + 25b32ab commit a990e0f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# CHANGES IN GGIR VERSION 2.10-3

- Visualreport: Bug fixed extracting the numeric value of the days to exclude in g.plot5 #879

- Part 1: Fixed minor bug to keep calibration data in the data quality report after re-running parts 1 and 2 with overwrite = TRUE and backup.cal.coef = "retrieve" #896

- Part 5: Fix minor bug by which GGIR skipped the last day if measurement finishes before midnight and timewindow = MM #891

- Part 4: Added parameter sleepefficiency.metric to decide if in-bed time (denominator) should be guider_spt or acc_spt + latency #811


# CHANGES IN GGIR VERSION 2.10-2

- Part 1: Revision to readability of code (credits: Lena Kushleyeva)
Expand Down
13 changes: 13 additions & 0 deletions R/g.part2.R
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,19 @@ g.part2 = function(datadir = c(), metadatadir = c(), f0 = c(), f1 = c(),
SUM$summary$names_appendedRecordings = names_appendedRecordings
SUM$summary$overlap_hrs_appendedRecordings = overlap_appendedRecordings
}
# convert daysummary and summary variables to numeric
char2num_df = function(df) {
# save as numeric columns that can be coerced to numeric
df = lapply(df, function(x) tryCatch(as.numeric(as.character(x)),
error = function(cond) return(x),
warning = function(cond) return(x)))
# list to data frame
df = as.data.frame(df, check.names = FALSE)
return(df)
}
SUM$summary = char2num_df(SUM$summary)
SUM$daysummary = char2num_df(SUM$daysummary)
# save milestone data
save(SUM, IMP, tail_expansion_log, file = paste0(metadatadir, ms2.out, "/", RDname)) #IMP is needed for g.plot in g.report.part2
}
if (M$filecorrupt == FALSE & M$filetooshort == FALSE) rm(IMP)
Expand Down
6 changes: 3 additions & 3 deletions R/g.plot5.R
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,15 @@ g.plot5 = function(metadatadir = c(), dofirstpage = FALSE, viewingwindow = 1,
lengthnight = summarysleep_tmp$SptDuration #including wake periods
nocsleepdur = summarysleep_tmp$SleepDurationInSpt
sleepefficiency = (nocsleepdur / lengthnight) * 100
f01 = as.numeric(P2daysummary_tmp[,c45])
f02 = as.numeric(P2daysummary_tmp[,MainMetric])
f01 = P2daysummary_tmp[,c45]
f02 = P2daysummary_tmp[,MainMetric]
f05 = matrix(NA, nrow = 2, ncol = length(summarysleep_tmp$SptDuration))
f05[1,] = summarysleep_tmp$SleepDurationInSpt
f05[2,] = summarysleep_tmp$SptDuration - summarysleep_tmp$SleepDurationInSpt
f05_2 = summarysleep_tmp$SptDuration
f06 = sleepefficiency
# f07 = P2daysummary_tmp$N.valid.hours # Previously needed when reading csv-report Part 2
f07 = as.numeric(P2daysummary_tmp$`N valid hours`)
f07 = P2daysummary_tmp$`N valid hours`
# allocate colours
CLS = c("white", "black")
CLS_A = rep(CLS[1], length(days_PA))
Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/test_chainof5parts.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ test_that("chainof5parts", {
expect_equal(nrow(IMP$metashort), 11280)
expect_equal(round(mean(IMP$metashort$ENMO), digits = 5), 0.00802, tolerance = 3)
expect_equal(round(as.numeric(SUM$summary$meas_dur_def_proto_day), digits = 3), 1)
expect_equal(SUM$summary$`N valid WEdays`, "1")
expect_equal(SUM$summary$`N valid WKdays`, "2")
expect_equal(SUM$summary$`N valid WEdays`, 1)
expect_equal(SUM$summary$`N valid WKdays`, 2)

# part 2 with strategy = 5
g.part2(datadir = fn, metadatadir = metadatadir, f0 = 1, f1 = 1,
Expand All @@ -67,8 +67,8 @@ test_that("chainof5parts", {
expect_equal(nrow(IMP$metashort), 11280)
expect_equal(round(mean(IMP$metashort$ENMO), digits = 5), 0.03398, tolerance = 3)
expect_equal(round(as.numeric(SUM$summary$meas_dur_def_proto_day), digits = 3), 1)
expect_equal(SUM$summary$`N valid WEdays`, "1")
expect_equal(SUM$summary$`N valid WKdays`, "2")
expect_equal(SUM$summary$`N valid WEdays`, 1)
expect_equal(SUM$summary$`N valid WKdays`, 2)

# part 2 with strategy = 2 and iglevels = 1
g.part2(datadir = fn, metadatadir = metadatadir, f0 = 1, f1 = 1,
Expand Down Expand Up @@ -103,7 +103,7 @@ test_that("chainof5parts", {
expect_equal(round(mean(IMP$metashort$ENMO), digits = 5), 0.02911, tolerance = 3)
expect_that(round(as.numeric(SUM$summary$meas_dur_dys), digits = 5), equals(1.95833))
expect_that(ncol(SUM$daysummary), equals(34))
expect_equal(SUM$daysummary$`p50_ENMO_mg_0-24hr`, c("17.15", "33", "0"))
expect_equal(SUM$daysummary$`p50_ENMO_mg_0-24hr`, c(17.15, 33, 0))
expect_equal(round(as.numeric(SUM$daysummary$`p90_ENMO_mg_0-24hr`)), c(44, 54, 41), tolerance = 0)
expect_equal(mean(as.numeric(SUM$daysummary$`M3_ENMO_mg_0-24hr`)), 89.26, tolerance = 3)
expect_equal(mean(as.numeric(SUM$daysummary$`M3_q40_ENMO_mg_0-24hr`)), 37.383, tolerance = 3)
Expand Down

0 comments on commit a990e0f

Please sign in to comment.