From 3130cb165799398921453fb781d216d2784024b0 Mon Sep 17 00:00:00 2001 From: Jairo H Migueles Date: Mon, 14 Oct 2024 12:35:39 +0200 Subject: [PATCH 1/4] revise MM window definition in part 5, daylight saving time days --- R/g.part5.definedays.R | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/R/g.part5.definedays.R b/R/g.part5.definedays.R index dd0fbfacc..b2e88cde3 100644 --- a/R/g.part5.definedays.R +++ b/R/g.part5.definedays.R @@ -42,24 +42,14 @@ g.part5.definedays = function(nightsi, wi, indjump, nightsi_bu, # in the data for this day. if (timewindowi == "MM") { NepochPerDay = ((24*3600) / epochSize) - # offset from prev midnight - t0 = format(ts$time[1], "%H:%M:%S") - hms = as.numeric(unlist(strsplit(t0, ":"))) - NepochFromPrevMidnight = (hms[1]*60*60 + hms[2]*60 + hms[3]) / epochSize - NepochFromDayborder2Midnight = (-dayborder*60*60) / epochSize - NepochFromPrevNight = NepochFromPrevMidnight + NepochFromDayborder2Midnight - if (NepochFromPrevNight < 0) { - NepochFromPrevNight = NepochPerDay + NepochFromPrevNight - } - if (wi == 1) { - qqq[1] = 1 - qqq[2] = NepochPerDay - NepochFromPrevNight - } else { - qqq[1] = ((wi - 1) * NepochPerDay) - NepochFromPrevNight + 1 - qqq[2] = (wi * NepochPerDay) - NepochFromPrevNight - } + # include first and last partial days in MM + if (nightsi[1] > 1) nightsi = c(1, nightsi) + if (nightsi[length(nightsi)] < nrow(ts)) nightsi = c(nightsi, nrow(ts)) + # define window + qqq[1] = nightsi[wi] + qqq[2] = nightsi[wi + 1] - 1 # is this the last day? - if (qqq[2] >= Nts) { + if (qqq[2] >= Nts - 1) { qqq[2] = Nts lastDay = TRUE } From a13f1aa9ee1f4204427670b0902b068556760ceb Mon Sep 17 00:00:00 2001 From: Jairo H Migueles Date: Mon, 14 Oct 2024 12:37:13 +0200 Subject: [PATCH 2/4] update news --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index 21ac43b1a..86429edc6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,6 +10,8 @@ - Add parameters require_complete_lastnight_part5 to control whether last window is included if last night is incomplete. #1196 + - Revise MM window definition in daylight saving time days, as it assumed fixed day duration of 24 hours #1211 + - 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 From ffc4fb3a695f387e411f17f2b9ad08618d0181bb Mon Sep 17 00:00:00 2001 From: Jairo H Migueles Date: Tue, 15 Oct 2024 13:46:13 +0200 Subject: [PATCH 3/4] identification of last timestamp in day improved if this is done in a DST day --- R/g.part5.definedays.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/R/g.part5.definedays.R b/R/g.part5.definedays.R index b2e88cde3..38e0fb8f3 100644 --- a/R/g.part5.definedays.R +++ b/R/g.part5.definedays.R @@ -78,7 +78,10 @@ g.part5.definedays = function(nightsi, wi, indjump, nightsi_bu, breaks = qwindow2timestamp(qwindow, epochSize) if (24 %in% qwindow) { # 24:00:00: probably does not exist, replace by last timestamp in a day - latest_time_in_day = max(format(ts$time[1:pmin(Nts, NepochPerDay)], format = "%H:%M:%S")) + # here, NepochPerDay + 1 extra hour just in case we are deriving this in + # a 25-hour daylight saving time day + NepochPerDayPlusOneHr = NepochPerDay + 60*60/epochSize + latest_time_in_day = max(format(ts$time[1:pmin(Nts, NepochPerDayPlusOneHr)], format = "%H:%M:%S")) breaks = gsub(pattern = "24:00:00", replacement = latest_time_in_day, x = breaks) } breaks_i = c() From 90cc7d5bcd1253dedd6f1a383138aea8ac11ea73 Mon Sep 17 00:00:00 2001 From: Vincent van Hees Date: Wed, 23 Oct 2024 14:23:31 +0200 Subject: [PATCH 4/4] minor code simplification for #1211 --- R/g.part5.definedays.R | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/R/g.part5.definedays.R b/R/g.part5.definedays.R index 38e0fb8f3..18e4b3492 100644 --- a/R/g.part5.definedays.R +++ b/R/g.part5.definedays.R @@ -41,7 +41,6 @@ g.part5.definedays = function(nightsi, wi, indjump, nightsi_bu, # Check that it is possible to find both windows (WW and MM) # in the data for this day. if (timewindowi == "MM") { - NepochPerDay = ((24*3600) / epochSize) # include first and last partial days in MM if (nightsi[1] > 1) nightsi = c(1, nightsi) if (nightsi[length(nightsi)] < nrow(ts)) nightsi = c(nightsi, nrow(ts)) @@ -78,9 +77,9 @@ g.part5.definedays = function(nightsi, wi, indjump, nightsi_bu, breaks = qwindow2timestamp(qwindow, epochSize) if (24 %in% qwindow) { # 24:00:00: probably does not exist, replace by last timestamp in a day - # here, NepochPerDay + 1 extra hour just in case we are deriving this in + # here, we consider N epochs per day plus 1 hour just in case we are deriving this in # a 25-hour daylight saving time day - NepochPerDayPlusOneHr = NepochPerDay + 60*60/epochSize + NepochPerDayPlusOneHr = ((25*3600) / epochSize) latest_time_in_day = max(format(ts$time[1:pmin(Nts, NepochPerDayPlusOneHr)], format = "%H:%M:%S")) breaks = gsub(pattern = "24:00:00", replacement = latest_time_in_day, x = breaks) }