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

Issue1211 MM window definition in part 5 #1213

Merged
merged 6 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 3 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,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
Loading