3 #' Data encapsulation as a list (days) of lists (components).
5 #' The private field .data is a list where each cell contains the variables for a period
6 #' of time of 24 hours, from time P+1 until P the next day where P is an integer between
7 #' 0 and 23. .data[[1]] refers to the first measured data (serie and exogenous
8 #' variables): the corresponding times can be accessed through the function
9 #' \code{getTime()} below. Each cell .data[[i]] is itself a list containing five slots,
10 #' as described in the 'field' section.
12 #' @field .data[[i]] List of
14 #' \item time: vector of times
15 #' \item centered_serie: centered serie
16 #' \item level: corresponding level
17 #' \item exo: exogenous variables
18 #' \item exo_hat: predicted exogenous variables (for next day)
23 #' \item{\code{getSize()}}{
24 #' Number of series in dataset.}
25 #' \item{\code{getStdHorizon()}}{
26 #' Number of time steps from serie[1] until midnight}
27 #' \item{\code{append(time, serie, exo, exo_hat)}}{
28 #' Measured data for given vector of times + exogenous predictions from
30 #' \item{\code{getTime(index)}}{
31 #' Times (vector) at specified index.}
32 #' \item{\code{getCenteredSerie(index)}}{
33 #' Centered serie at specified index.}
34 #' \item{\code{getCenteredSeries(indices)}}{
35 #' Centered series at specified indices (in columns).}
36 #' \item{\code{getLevel(index)}}{
37 #' Level at specified index.}
38 #' \item{\code{getSerie(index)}}{
39 #' Serie (centered+level) at specified index.}
40 #' \item{\code{getSeries(indices)}}{
41 #' Series at specified indices (in columns).}
42 #' \item{\code{getExoHat(index)}}{
43 #' Predicted exogenous variables at specified index.}
44 #' \item{\code{getExo(index)}}{
45 #' Measured exogenous variables at specified index.}
46 #' \item{\code{removeFirst()}}{
47 #' Remove first list element (if truncated).}
48 #' \item{\code{removeLast()}}{
49 #' Remove last list element (if truncated).}
55 Data = R6::R6Class("Data",
63 getStdHorizon = function()
64 24 - as.POSIXlt( private$.data[[1]]$time[1] )$hour + 1
66 append = function(time, serie, exo, exo_hat)
68 level = mean(serie, na.rm=TRUE)
69 centered_serie = serie - level
70 private$.data[[length(private$.data)+1]] <- list(
71 "time"=time, #H-24 --> H-1
72 "centered_serie"=centered_serie, #at 'time'
73 "level"=level, #at 'time'
74 "exo"=exo, #at 'time' (yersteday 0am to last midnight)
75 "exo_hat"=exo_hat) #today 0am to next midnight
77 getTime = function(index)
79 index = dateIndexToInteger(index, self)
80 private$.data[[index]]$time
82 getCenteredSerie = function(index)
84 index = dateIndexToInteger(index, self)
85 private$.data[[index]]$centered_serie
87 getCenteredSeries = function(indices)
88 sapply(indices, function(i) self$getCenteredSerie(i))
90 getLevel = function(index)
92 index = dateIndexToInteger(index, self)
93 private$.data[[index]]$level
95 getSerie = function(index)
97 index = dateIndexToInteger(index, self)
98 private$.data[[index]]$centered_serie + private$.data[[index]]$level
100 getSeries = function(indices)
101 sapply(indices, function(i) self$getSerie(i))
103 getExoHat = function(index)
105 index = dateIndexToInteger(index, self)
106 private$.data[[index]]$exo_hat
108 getExo = function(index)
110 index = dateIndexToInteger(index, self)
111 private$.data[[index]]$exo
113 removeFirst = function()
114 private$.data <- private$.data[2:length(private$.data)]
116 removeLast = function()
117 private$.data <- private$.data[1:(length(private$.data)-1)]