6 #' @importFrom R6 R6Class
8 #' @field .data List of \itemize{
9 #' \item time: vector of times
10 #' \item serie: centered series
11 #' \item level: corresponding levels
12 #' \item exo: exogenous variables
13 #' \item exo_hat: predicted exogenous variables}
17 #' \item{\code{getSize()}}{
18 #' Return number of series in dataset.}
19 #' \item{\code{getStdHorizon()}}{
20 #' Return number of time steps from serie[1] until midnight}
21 #' \item{\code{appendHat(time, hat_serie, hat_exo)}}{
22 #' New estimated data + time.}
23 #' \item{\code{append(serie, exo)}}{
24 #' New measured data; call *after* \code{appendHat()}}
25 #' \item{\code{getTime(index)}}{
26 #' Get times at specified index.}
27 #' \item{\code{getCenteredSerie(index, hat=FALSE)}}{
28 #' Get (measured or predicted) centered serie at specified index.}
29 #' \item{\code{getCenteredSeries(indices, hat=FALSE)}}{
30 #' Get centered series at specified indices (in columns).}
31 #' \item{\code{getLevel(index, hat=FALSE)}}{
32 #' Get level at specified index.}
33 #' \item{\code{getSerie(index, hat=FALSE)}}{
34 #' Get serie (centered+level) at specified index.}
35 #' \item{\code{getSeries(indices, hat=FALSE)}}{
36 #' Get series at specified indices (in columns).}
37 #' \item{\code{getExo(index, hat=FALSE)}}{
38 #' Get exogenous variables at specified index.}
41 Data = R6::R6Class("Data",
49 getStdHorizon = function()
50 24 - as.POSIXlt( private$.data[[1]]$time[1] )$hour + 1
52 appendHat = function(time, hat_serie, hat_exo)
54 hat_level = mean(hat_serie, na.rm=TRUE)
55 hat_centered_serie = hat_serie - hat_level
56 private$.data[[length(private$.data)+1]] <- list(
57 "time"=time, "hat_centered_serie"=hat_centered_serie,
58 "hat_level"=hat_level, "hat_exo"=hat_exo )
60 append = function(serie, exo)
62 level = mean(serie, na.rm=TRUE)
63 centered_serie = serie - level
64 private$.data[[length(private$.data)]]$centered_serie <- centered_serie,
65 private$.data[[length(private$.data)]]$level <- level,
66 private$.data[[length(private$.data)]]$exo <- exo,
68 getTime = function(index)
70 index = dateIndexToInteger(index, self)
71 private$.data[[index]]$time
73 getCenteredSerie = function(index, hat=FALSE)
75 index = dateIndexToInteger(index, self)
77 private$.data[[index]]$hat_centered_serie
79 private$.data[[index]]$centered_serie
81 getCenteredSeries = function(indices, hat=FALSE)
82 sapply(indices, function(i) self$getCenteredSerie(i, hat))
84 getLevel = function(index, hat=FALSE)
86 index = dateIndexToInteger(index, self)
88 private$.data[[index]]$hat_level
90 private$.data[[index]]$level
92 getSerie = function(index, hat=FALSE)
94 index = dateIndexToInteger(index, self)
96 private$.data[[index]]$hat_centered_serie + private$.data[[index]]$hat_level
98 private$.data[[index]]$centered_serie + private$.data[[index]]$level
100 getSeries = function(indices, hat=FALSE)
101 sapply(indices, function(i) self$getSerie(i, hat))
103 getExo = function(index, hat=FALSE)
105 index = dateIndexToInteger(index, self)
107 private$.data[[index]]$hat_exo
109 private$.data[[index]]$exo
111 removeFirst = function()
112 private$.data <- private$.data[2:length(private$.data)]
114 removeLast = function()
115 private$.data <- private$.data[1:(length(private$.data)-1)]