Skip to content

Commit

Permalink
Merge branch 'master' into issue967_selfreport_experimentSD
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentvanhees committed Oct 23, 2024
2 parents e734bbb + 03d89f6 commit 215ee36
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
5 changes: 3 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@

- Adjust sleeplog times to recording length in part 5 when classifying a night that was not detected in part 4. #1206

- Fixed minor bug in g.part5.addfirstwake causing the first wake not correctly being added when
no SIBs are detected from the beginning of the recording until the first detected night. #1198
- Fixed minor bug in g.part5.addfirstwake causing the first wake is not correctly added when no SIBs are detected from the beginning of the recording until the first detected night. #1198

- 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.

Expand Down
30 changes: 11 additions & 19 deletions R/g.part5.definedays.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,14 @@ 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)
# 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
}
Expand Down Expand Up @@ -88,7 +77,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, 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 = ((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)
}
breaks_i = c()
Expand Down

0 comments on commit 215ee36

Please sign in to comment.