3 #' Data encapsulation, in the form of a few lists (time-series + exogenous variables).
5 #' The private field .tvp is a list where each cell contains the hourly variables for a
6 #' period of time of 24 hours, from 1am to next midnight. The other lists contain
7 #' informations on series' levels and exogenous variables (both measured and predicted).
11 #' @field .tvp List of "time-values"; in each cell:
13 #' \item time: vector of times
14 #' \item serie: (measured) serie
15 #' \item level_hat: predicted level for current day
17 #' @field .level Vector of measured levels
18 #' @field .exo List of measured exogenous variables, cell = numerical vector.
19 #' @field .exo_hat List of predicted exogenous variables, cell = numerical vector.
23 #' \item{\code{getSize()}}{
24 #' Number of series in dataset.}
25 #' \item{\code{append(time, value, level_hat, exo, exo_hat)}}{
26 #' Measured data for given vector of times + exogenous predictions from
28 #' \item{\code{getTime(index)}}{
29 #' Times (vector) at specified index.}
30 #' \item{\code{getSerie(index)}}{
31 #' Serie (centered+level) at specified index.}
32 #' \item{\code{getSeries(indices)}}{
33 #' Series at specified indices (in columns).}
34 #' \item{\code{getLevel(index)}}{
35 #' Measured level at specified index.}
36 #' \item{\code{getLevelHat(index)}}{
37 #' Predicted level vector at specified index (by hour).}
38 #' \item{\code{getCenteredSerie(index)}}{
39 #' Centered serie at specified index.}
40 #' \item{\code{getCenteredSeries(indices)}}{
41 #' Centered series at specified indices (in columns).}
42 #' \item{\code{getExo(index)}}{
43 #' Measured exogenous variables at specified index.}
44 #' \item{\code{getExoHat(index)}}{
45 #' Predicted exogenous variables at specified index.}
51 Data = R6::R6Class("Data",
54 .level = vector("double",0),
62 append = function(time=NULL, value=NULL, level_hat=NULL, exo=NULL, exo_hat=NULL)
64 if (!is.null(time) && !is.null(value) && !is.null(level_hat))
66 L = length(private$.tvp)
67 if (L == 0 || strftime( tail(private$.tvp[[L]]$time,1),
68 format="%H:%M:%S", tz="GMT" ) == "00:00:00")
71 private$.tvp[[L+1]] <- list("time"=time, "serie"=value, "level_hat"=level_hat)
75 # Complete current cell
76 private$.tvp[[L]]$time <- c(private$.tvp[[L]]$time, time)
77 private$.tvp[[L]]$serie <- c(private$.tvp[[L]]$serie, value)
78 private$.tvp[[L]]$level_hat <- c(private$.tvp[[L]]$level_hat, level_hat)
81 if (strftime( tail(private$.tvp[[length(private$.tvp)]]$time,1),
82 format="%H:%M:%S", tz="GMT" ) == "00:00:00")
84 private$.level = c(private$.level,
85 mean(private$.tvp[[length(private$.tvp)]]$serie, na.rm=TRUE))
88 private$.exo[[length(private$.exo)+1]] = exo
89 if (!is.null(exo_hat))
90 private$.exo_hat[[length(private$.exo_hat)+1]] = exo_hat
92 getTime = function(index)
94 index = dateIndexToInteger(index, self)
95 private$.tvp[[index]]$time
97 getSerie = function(index)
99 index = dateIndexToInteger(index, self)
100 private$.tvp[[index]]$serie
102 getSeries = function(indices)
103 sapply(indices, function(i) self$getSerie(i))
105 getLevel = function(index)
107 index = dateIndexToInteger(index, self)
108 private$.level[index]
110 getLevelHat = function(index)
112 index = dateIndexToInteger(index, self)
113 private$.tvp[[index]]$level_hat
115 getCenteredSerie = function(index)
117 index = dateIndexToInteger(index, self)
118 private$.tvp[[index]]$serie - private$.level[index]
120 getCenteredSeries = function(indices)
121 sapply(indices, function(i) self$getCenteredSerie(i))
123 getExo = function(index)
125 index = dateIndexToInteger(index, self)
126 private$.exo[[index]]
128 getExoHat = function(index)
130 index = dateIndexToInteger(index, self)
131 private$.exo_hat[[index]]