3 #' Data encapsulation, in the form of a few lists (time-series + exogenous variables).
5 #' The private field .tv 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 .tv List of "time-values"; in each cell:
13 #' \item time: vector of times
14 #' \item serie: (measured) serie
16 #' @field .level Vector of measured levels
17 #' @field .level_hat Vector of predicted 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 at specified index.}
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),
55 .level_hat = vector("double",0),
63 append = function(time=NULL, value=NULL, level_hat=NULL, exo=NULL, exo_hat=NULL)
65 if (!is.null(time) && !is.null(value))
67 L = length(private$.tv)
68 if (L == 0 || strftime( tail(private$.tv[[L]]$time,1),
69 format="%H:%M:%S", tz="GMT" ) == "00:00:00")
72 private$.tv[[L+1]] <- list("time"=time, "serie"=value)
76 # Complete current cell
77 private$.tv[[L]]$time = c(private$.tv[[L]]$time, time)
78 private$.tv[[L]]$serie = c(private$.tv[[L]]$serie, value)
81 if (strftime( tail(private$.tv[[length(private$.tv)]]$time,1),
82 format="%H:%M:%S", tz="GMT" ) == "00:00:00")
84 private$.level = c(private$.level,
85 mean(private$.tv[[length(private$.tv)]]$serie, na.rm=TRUE))
87 if (!is.null(level_hat))
88 private$.level_hat = c(private$.level_hat, level_hat)
90 private$.exo[[length(private$.exo)+1]] = exo
91 if (!is.null(exo_hat))
92 private$.exo_hat[[length(private$.exo_hat)+1]] = exo_hat
94 getTime = function(index)
96 index = dateIndexToInteger(index, self)
97 private$.tv[[index]]$time
99 getSerie = function(index)
101 index = dateIndexToInteger(index, self)
102 private$.tv[[index]]$serie
104 getSeries = function(indices)
105 sapply(indices, function(i) self$getSerie(i))
107 getLevel = function(index)
109 index = dateIndexToInteger(index, self)
110 private$.level[index]
112 getLevelHat = function(index)
114 index = dateIndexToInteger(index, self)
115 private$.level_hat[index]
117 getCenteredSerie = function(index)
119 index = dateIndexToInteger(index, self)
120 private$.tv[[index]]$serie - private$.level[index]
122 getCenteredSeries = function(indices)
123 sapply(indices, function(i) self$getCenteredSerie(i))
125 getExo = function(index)
127 index = dateIndexToInteger(index, self)
128 private$.exo[[index]]
130 getExoHat = function(index)
132 index = dateIndexToInteger(index, self)
133 private$.exo_hat[[index]]