Skip to content

Commit

Permalink
small improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
gisler committed Jul 26, 2020
1 parent e10294a commit 082c3a3
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 26 deletions.
4 changes: 2 additions & 2 deletions R/Swrappers.R
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
#' }
Expand Down
20 changes: 10 additions & 10 deletions R/funby.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"]]))
Expand All @@ -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
)
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion inst/tinytest/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
13 changes: 6 additions & 7 deletions inst/tinytest/test_funby.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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"]],
Expand All @@ -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"]],
Expand Down
8 changes: 4 additions & 4 deletions man/TALFs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/aggregate.DTSg.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 082c3a3

Please sign in to comment.