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 last midgnight.
29 #' \item{\code{getTime(index)}}{
30 #' Times (vector) at specified index.}
31 #' \item{\code{getCenteredSerie(index)}}{
32 #' Centered serie at specified index.}
33 #' \item{\code{getCenteredSeries(indices)}}{
34 #' Centered series at specified indices (in columns).}
35 #' \item{\code{getLevel(index)}}{
36 #' Level at specified index.}
37 #' \item{\code{getSerie(index)}}{
38 #' Serie (centered+level) at specified index.}
39 #' \item{\code{getSeries(indices)}}{
40 #' Series at specified indices (in columns).}
41 #' \item{\code{getExoHat(index)}}{
42 #' Predicted exogenous variables at specified index.}
43 #' \item{\code{getExo(index)}}{
44 #' Measured exogenous variables at specified index.}
45 #' \item{\code{removeFirst()}}{
46 #' Remove first list element (if truncated).}
47 #' \item{\code{removeLast()}}{
48 #' Remove last list element (if truncated).}
54 Data = R6::R6Class("Data",
62 getStdHorizon = function()
63 24 - as.POSIXlt( private$.data[[1]]$time[1] )$hour + 1
65 append = function(time, serie, exo, exo_hat)
67 level = mean(serie, na.rm=TRUE)
68 centered_serie = serie - level
69 private$.data[[length(private$.data)+1]] <- list(
70 "time"=time, #H-24 --> H-1
71 "centered_serie"=centered_serie, #at 'time'
72 "level"=level, #at 'time'
73 "exo"=exo, #at 'time' (yersteday 0am to last midnight)
74 "exo_hat"=exo_hat) #today 0am to next midnight
76 getTime = function(index)
78 index = dateIndexToInteger(index, self)
79 private$.data[[index]]$time
81 getCenteredSerie = function(index)
83 index = dateIndexToInteger(index, self)
84 private$.data[[index]]$centered_serie
86 getCenteredSeries = function(indices)
87 sapply(indices, function(i) self$getCenteredSerie(i))
89 getLevel = function(index)
91 index = dateIndexToInteger(index, self)
92 private$.data[[index]]$level
94 getSerie = function(index)
96 index = dateIndexToInteger(index, self)
97 private$.data[[index]]$centered_serie + private$.data[[index]]$level
99 getSeries = function(indices)
100 sapply(indices, function(i) self$getSerie(i))
102 getExoHat = function(index)
104 index = dateIndexToInteger(index, self)
105 private$.data[[index]]$exo_hat
107 getExo = function(index)
109 index = dateIndexToInteger(index, self)
110 private$.data[[index]]$exo
112 removeFirst = function()
113 private$.data <- private$.data[2:length(private$.data)]
115 removeLast = function()
116 private$.data <- private$.data[1:(length(private$.data)-1)]