From 082c3a31d94b3301965812d27e24d65be312394a Mon Sep 17 00:00:00 2001 From: gisler Date: Sun, 26 Jul 2020 09:50:23 +0200 Subject: [PATCH] small improvements --- R/Swrappers.R | 4 ++-- R/funby.R | 20 ++++++++++---------- inst/tinytest/data.R | 2 +- inst/tinytest/test_funby.R | 13 ++++++------- man/TALFs.Rd | 8 ++++---- man/aggregate.DTSg.Rd | 4 ++-- 6 files changed, 25 insertions(+), 26 deletions(-) diff --git a/R/Swrappers.R b/R/Swrappers.R index 7f0f8c0..51d1e96 100644 --- a/R/Swrappers.R +++ b/R/Swrappers.R @@ -114,11 +114,11 @@ NULL #' \item \code{\link{byFasttime_____S}} #' \item \code{\link{byY_____}} #' \item \code{\link{byYm____}} -#' \item \code{\link{byYmdH__}} (UTC and equivalent and all Etc/GMT only) +#' \item \code{\link{byYmdH__}} (UTC and equivalent as well as all Etc/GMT only) #' \item \code{\link{byYmdHM_}} #' \item \code{\link{byYmdHMS}} #' \item \code{\link{by_m____}} -#' \item \code{\link{by___H__}} (UTC and equivalent and all Etc/GMT only) +#' \item \code{\link{by___H__}} (UTC and equivalent as well as all Etc/GMT only) #' \item \code{\link{by____M_}} #' \item \code{\link{by_____S}} #' } diff --git a/R/funby.R b/R/funby.R index 9264b58..9fb4ecd 100644 --- a/R/funby.R +++ b/R/funby.R @@ -41,11 +41,11 @@ byFasttimeMult___H__call <- quote(fasttime::fastPOSIXct(sprintf("2199-01-01 %02d byFasttimeMult____M_call <- quote(fasttime::fastPOSIXct(sprintf("2199-01-01 00:%02d:00", minute(.dateTime) %/% .helpers[["multiplier"]] * .helpers[["multiplier"]] ), tz = .helpers[["timezone"]])) byFasttimeMult_____Scall <- quote(fasttime::fastPOSIXct(sprintf("2199-01-01 00:00:%02d", second(.dateTime) %/% .helpers[["multiplier"]] * .helpers[["multiplier"]] ), tz = .helpers[["timezone"]])) -byMultY_____call <- quote(as.POSIXct(sprintf("%04d-01-01" , year(.dateTime) %/% .helpers[["multiplier"]] * .helpers[["multiplier"]] ) , tz = .helpers[["timezone"]] )) -byMultYm____call <- quote(as.POSIXct(sprintf("%04d-%02d-01" , year(.dateTime), (month(.dateTime) - 1L) %/% .helpers[["multiplier"]] * .helpers[["multiplier"]] + 1L) , tz = .helpers[["timezone"]] )) -byMultYmdH__call <- quote(as.POSIXct(sprintf("%04d-%02d-%02d %02d:00:00" , year(.dateTime), month(.dateTime), mday(.dateTime), hour(.dateTime) %/% .helpers[["multiplier"]] * .helpers[["multiplier"]] ), tz = .helpers[["timezone"]] )) -byMultYmdHM_call <- quote(as.POSIXct(sprintf("%04d-%02d-%02d %02d:%02d:00 %s" , year(.dateTime), month(.dateTime), mday(.dateTime), hour(.dateTime), minute(.dateTime) %/% .helpers[["multiplier"]] * .helpers[["multiplier"]] , format(.dateTime, "%z")), tz = .helpers[["timezone"]], format = "%Y-%m-%d %H:%M:%S %z")) -byMultYmdHMScall <- quote(as.POSIXct(sprintf("%04d-%02d-%02d %02d:%02d:%02d %s", year(.dateTime), month(.dateTime), mday(.dateTime), hour(.dateTime), minute(.dateTime), second(.dateTime) %/% .helpers[["multiplier"]] * .helpers[["multiplier"]] , format(.dateTime, "%z")), tz = .helpers[["timezone"]], format = "%Y-%m-%d %H:%M:%S %z")) +byMultY_____call <- quote(as.POSIXct(sprintf("%04d-01-01" , year(.dateTime) %/% .helpers[["multiplier"]] * .helpers[["multiplier"]] ), tz = .helpers[["timezone"]] )) +byMultYm____call <- quote(as.POSIXct(sprintf("%04d-%02d-01" , year(.dateTime), (month(.dateTime) - 1L) %/% .helpers[["multiplier"]] * .helpers[["multiplier"]] + 1L), tz = .helpers[["timezone"]] )) +byMultYmdH__call <- quote(as.POSIXct(sprintf("%04d-%02d-%02d %02d:00:00" , year(.dateTime), month(.dateTime), mday(.dateTime), hour(.dateTime) %/% .helpers[["multiplier"]] * .helpers[["multiplier"]] ), tz = .helpers[["timezone"]] )) +byMultYmdHM_call <- quote(as.POSIXct(sprintf("%04d-%02d-%02d %02d:%02d:00 %s" , year(.dateTime), month(.dateTime), mday(.dateTime), hour(.dateTime), minute(.dateTime) %/% .helpers[["multiplier"]] * .helpers[["multiplier"]], format(.dateTime, "%z", tz = .helpers[["timezone"]])), tz = .helpers[["timezone"]], format = "%Y-%m-%d %H:%M:%S %z")) +byMultYmdHMScall <- quote(as.POSIXct(sprintf("%04d-%02d-%02d %02d:%02d:%02d %s", year(.dateTime), month(.dateTime), mday(.dateTime), hour(.dateTime), minute(.dateTime), second(.dateTime) %/% .helpers[["multiplier"]] * .helpers[["multiplier"]], format(.dateTime, "%z", tz = .helpers[["timezone"]])), tz = .helpers[["timezone"]], format = "%Y-%m-%d %H:%M:%S %z")) byMult_m____call <- quote(as.POSIXct(sprintf("2199-%02d-01" , (month(.dateTime) - 1L) %/% .helpers[["multiplier"]] * .helpers[["multiplier"]] + 1L), tz = .helpers[["timezone"]])) byMult___H__call <- quote(as.POSIXct(sprintf("2199-01-01 %02d:00:00", hour(.dateTime) %/% .helpers[["multiplier"]] * .helpers[["multiplier"]] ), tz = .helpers[["timezone"]])) @@ -67,7 +67,7 @@ to.fakeUTCdateTime <- function(.dateTime, .helpers) { } .dateTime <- seq( - as.POSIXct(as.character(from), tz = "UTC"), + as.POSIXct(as.character(from, tz = .helpers[["timezone"]]), tz = "UTC"), by = .helpers[["periodicity"]], along.with = .dateTime ) @@ -97,11 +97,11 @@ to.fakeUTCdateTime <- function(.dateTime, .helpers) { #' certain part of them (extracting family). Each family comes in two flavours: #' one using \code{\link[fasttime]{fastPOSIXct}} of \pkg{fasttime}, the other #' solely relying on base \R. The \pkg{fasttime} versions work with UTC time -#' series or time series with an equivalent time zone (execute +#' series or time series with an equivalent time zone only (execute #' \code{grep("^(Etc/)?(UCT|UTC)$|^(Etc/)?GMT(\\+|-)?0?$", OlsonNames(), -#' ignore.case = TRUE, value = TRUE)} for a full list) only and are limited to -#' dates between the years 1970 and 2199, but generally are faster for the -#' extracting family of functions. +#' ignore.case = TRUE, value = TRUE)} for a full list of supported time zones) +#' and are limited to dates between the years 1970 and 2199, but generally are +#' faster for the extracting family of functions. #' #' The truncating family sets timestamps to the lowest possible time of the #' corresponding temporal aggregation level: diff --git a/inst/tinytest/data.R b/inst/tinytest/data.R index d05c068..8c7adbd 100644 --- a/inst/tinytest/data.R +++ b/inst/tinytest/data.R @@ -112,7 +112,7 @@ CETfromDSTfractionalSecondData <- data.table( 0.5 ), value = as.numeric(seq_len(21600L)), - hour = rep(2:4 , each = 7200L), + hour = rep(1:3 , each = 7200L), minute = rep(0:179 , each = 120L), second = rep(0:10799 , each = 2L), hourMinute = rep(rep(0:59, each = 120L), 3L), diff --git a/inst/tinytest/test_funby.R b/inst/tinytest/test_funby.R index 2b0bc32..9f4b96e 100644 --- a/inst/tinytest/test_funby.R +++ b/inst/tinytest/test_funby.R @@ -276,7 +276,6 @@ expect_identical( info = '"by_____S" works as expected (CETfromDST, multiplier == 1L)' ) - #### fasttime functions (UTC, multiplier > 1L) #### if (requireNamespace("fasttime", quietly = TRUE)) { expect_identical( @@ -396,6 +395,12 @@ expect_identical( info = '"byY_____" works as expected (CETtoFromDST, multiplier > 1L)' ) +expect_identical( + DTSg$new(CEThourlyData)$aggregate(byYm____, sum, ignoreDST = TRUE, multiplier = 3L)$values(TRUE)[["value"]], + CEThourlyData[, .(value = sum(value)), by = .((yearMonth - 1L) %/% 3L * 3L + 1L)][["value"]], + info = '"byYm____" works as expected (CETtoFromDST, multiplier > 1L)' +) + expect_identical( DTSg$new(CETtoDSTfractionalSecondData)$aggregate(byYmdHM_, sum, multiplier = 5L)$values(TRUE)[["value"]], CETtoDSTfractionalSecondData[, .(value = sum(value)), by = .(minute %/% 5L * 5L)][["value"]], @@ -408,12 +413,6 @@ expect_identical( info = '"byYmdHMS" works as expected (CETtoDST, multiplier > 1L)' ) -expect_identical( - DTSg$new(CEThourlyData)$aggregate(byYm____, sum, ignoreDST = TRUE, multiplier = 3L)$values(TRUE)[["value"]], - CEThourlyData[, .(value = sum(value)), by = .((yearMonth - 1L) %/% 3L * 3L + 1L)][["value"]], - info = '"byYm____" works as expected (CETtoFromDST, multiplier > 1L)' -) - expect_identical( DTSg$new(CEThourlyData)$aggregate(by_m____, sum, ignoreDST = TRUE, multiplier = 3L)$values(TRUE)[["value"]], CEThourlyData[, .(value = sum(value)), keyby = .((month - 1L) %/% 3L * 3L + 1L)][["value"]], diff --git a/man/TALFs.Rd b/man/TALFs.Rd index 15473e7..e35a54e 100644 --- a/man/TALFs.Rd +++ b/man/TALFs.Rd @@ -104,11 +104,11 @@ There are two families of temporal aggregation level functions. The certain part of them (extracting family). Each family comes in two flavours: one using \code{\link[fasttime]{fastPOSIXct}} of \pkg{fasttime}, the other solely relying on base \R. The \pkg{fasttime} versions work with UTC time - series or time series with an equivalent time zone (execute + series or time series with an equivalent time zone only (execute \code{grep("^(Etc/)?(UCT|UTC)$|^(Etc/)?GMT(\\+|-)?0?$", OlsonNames(), - ignore.case = TRUE, value = TRUE)} for a full list) only and are limited to - dates between the years 1970 and 2199, but generally are faster for the - extracting family of functions. + ignore.case = TRUE, value = TRUE)} for a full list of supported time zones) + and are limited to dates between the years 1970 and 2199, but generally are + faster for the extracting family of functions. The truncating family sets timestamps to the lowest possible time of the corresponding temporal aggregation level: diff --git a/man/aggregate.DTSg.Rd b/man/aggregate.DTSg.Rd index b42f995..5a07890 100644 --- a/man/aggregate.DTSg.Rd +++ b/man/aggregate.DTSg.Rd @@ -143,11 +143,11 @@ The temporal aggregation level of certain \code{\link{TALFs}} can be adjusted \item \code{\link{byFasttime_____S}} \item \code{\link{byY_____}} \item \code{\link{byYm____}} - \item \code{\link{byYmdH__}} (UTC and equivalent and all Etc/GMT only) + \item \code{\link{byYmdH__}} (UTC and equivalent as well as all Etc/GMT only) \item \code{\link{byYmdHM_}} \item \code{\link{byYmdHMS}} \item \code{\link{by_m____}} - \item \code{\link{by___H__}} (UTC and equivalent and all Etc/GMT only) + \item \code{\link{by___H__}} (UTC and equivalent as well as all Etc/GMT only) \item \code{\link{by____M_}} \item \code{\link{by_____S}} }