Skip to content

Commit

Permalink
Merge pull request #1227 from wadpac/issue1225_DST_part3
Browse files Browse the repository at this point in the history
Fix handling of DST in the autumn in GGIR part 3.
  • Loading branch information
vincentvanhees authored Nov 21, 2024
2 parents aca2c15 + 83ec7a9 commit e98af24
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# CHANGES IN GGIR VERSION 3.1-?

- Part 2: Code revisions in preparation for expansion of functionality to better facilitate external function produced event data. #653
- Part 3: Improved handling of DST, #1225

- Part 2: Code revisions in preparation for expansion of functionality to better facilitate external function produced event data. #653 and #1228

# CHANGES IN GGIR VERSION 3.1-6

Expand Down
2 changes: 1 addition & 1 deletion R/g.part5.definedays.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ g.part5.definedays = function(nightsi, wi, indjump, nightsi_bu,
breaks_i = c()
for (bi in 1:length(breaks)) {
if (any(grepl(breaks[bi], ts$time[fullQqq]))) {
breaks_i[bi] = fullQqq[grep(breaks[bi], ts$time[fullQqq])]
breaks_i[bi] = fullQqq[grep(breaks[bi], ts$time[fullQqq])][1]
} else {
breaks_i[bi] = qqq[1]
}
Expand Down
11 changes: 10 additions & 1 deletion R/g.sib.det.R
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,18 @@ g.sib.det = function(M, IMP, I, twd = c(-12, 12),
qqq1 = 1 # preceding noon (not available in recording)
qqq2 = midnightsi[1] + (twd[1] * (3600 / ws3))# first noon in recording
} else {
qqq1 = midnightsi[j] + (twd[1] * (3600 / ws3)) #preceding noon
qqq1 = midnightsi[j] + (twd[1] * (3600 / ws3)) + 1 #preceding noon
qqq2 = midnightsi[j] + (twd[2] * (3600 / ws3)) #next noon
}
# twd assumed 24 hour window, which is not the case for DST
if (qqq2 < length(time)) {
qqq2_hour = as.numeric(format(iso8601chartime2POSIX(time[qqq2], tz = desiredtz), "%H"))
if (qqq2_hour == 11) {
qqq2 = qqq2 + (3600 / ws3)
} else if (qqq2_hour == 13) {
qqq2 = qqq2 - (3600 / ws3)
}
}
sptei = sptei + 1
if (qqq2 - qqq1 < 60) next # skip night if it has less than 60 epochs
if (qqq2 > length(time)) qqq2 = length(time)
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test_chainof5parts.R
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ test_that("chainof5parts", {
rn = dir(dirname,full.names = TRUE)
load(rn[1])
expect_true(file.exists(vis_sleep_file))
expect_that(round(nightsummary$SptDuration[1], digits = 4), equals(18.075))
expect_equal(round(nightsummary$SptDuration[1], digits = 4), 18.0792, tolerance = 0.0005)
expect_true(as.logical(nightsummary$acc_available[1]))
expect_false(as.logical(nightsummary$sleeplog_used[1]))

Expand Down Expand Up @@ -386,7 +386,7 @@ test_that("chainof5parts", {
load(rn[1])
expect_true(dir.exists(dirname))
expect_that(round(nightsummary$number_sib_wakinghours[1], digits = 4), equals(6))
expect_that(round(nightsummary$SptDuration[1], digits = 4), equals(13.075))
expect_equal(round(nightsummary$SptDuration[1], digits = 4), 13.0792)
#---------------------
# Part 1 with external function:
exampleExtFunction = function(data=c(), parameters=c()) {
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test_recordingEndSleepHour.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ test_that("recordingEndSleepHour works as expected", {
expect_equal(nrow(p4full), 3) # Night 3 is not in the part 4 reports
expect_equal(sum(p4$sleeponset), 62.77)
expect_equal(sum(p4$wakeup), 93.505)
expect_equal(sum(p4$guider_onset), 62.778)
expect_equal(sum(p4$guider_wakeup), 93.511)
expect_equal(sum(p4$guider_onset), 62.775)
expect_equal(sum(p4$guider_wakeup), 93.506)
expect_equal(sum(p4$number_sib_sleepperiod), 114)
expect_true(all(is.na(p4$longitudinal_axis)))

Expand Down Expand Up @@ -95,8 +95,8 @@ test_that("recordingEndSleepHour works as expected", {
expect_equal(nrow(p4full), 3) # Night 3 is not in the part 4 reports
expect_equal(sum(p4$sleeponset), 62.1)
expect_equal(sum(p4$wakeup), 81.096)
expect_equal(sum(p4$guider_inbedStart), 53.171)
expect_equal(sum(p4$guider_inbedEnd), 86.853)
expect_equal(sum(p4$guider_inbedStart), 53.17, tolerance = 0.005)
expect_equal(sum(p4$guider_inbedEnd), 86.85, tolerance = 0.005)
expect_equal(sum(p4$number_sib_sleepperiod), 24)
expect_equal(sum(p4$sleepefficiency), 0.501)
expect_equal(sum(p4$longitudinal_axis), 9)
Expand Down

0 comments on commit e98af24

Please sign in to comment.