#' @docType class
#' @importFrom R6 R6Class
#'
-#' @field .data List of \itemize{
+#' @field .data List of
+#' \itemize{
#' \item time: vector of times
-#' \item serie: centered series
+#' \item centered_serie: centered series
#' \item level: corresponding levels
#' \item exo: exogenous variables
-#' \item exo_hat: predicted exogenous variables}
+#' \item exo_hat: predicted exogenous variables
+#' }
#'
#' @section Methods:
#' \describe{
#' Return number of series in dataset.}
#' \item{\code{getStdHorizon()}}{
#' Return number of time steps from serie[1] until midnight}
-#' \item{\code{appendHat(time, hat_serie, hat_exo)}}{
-#' New estimated data + time.}
+#' \item{\code{appendHat(time, exo_hat)}}{
+#' New estimated exogenous variables + time}
#' \item{\code{append(serie, exo)}}{
#' New measured data; call *after* \code{appendHat()}}
#' \item{\code{getTime(index)}}{
#' Get times at specified index.}
-#' \item{\code{getCenteredSerie(index, hat=FALSE)}}{
+#' \item{\code{getCenteredSerie(index)}}{
#' Get (measured or predicted) centered serie at specified index.}
-#' \item{\code{getCenteredSeries(indices, hat=FALSE)}}{
+#' \item{\code{getCenteredSeries(indices)}}{
#' Get centered series at specified indices (in columns).}
-#' \item{\code{getLevel(index, hat=FALSE)}}{
+#' \item{\code{getLevel(index)}}{
#' Get level at specified index.}
-#' \item{\code{getSerie(index, hat=FALSE)}}{
+#' \item{\code{getSerie(index)}}{
#' Get serie (centered+level) at specified index.}
-#' \item{\code{getSeries(indices, hat=FALSE)}}{
+#' \item{\code{getSeries(indices)}}{
#' Get series at specified indices (in columns).}
-#' \item{\code{getExo(index, hat=FALSE)}}{
+#' \item{\code{getExoHat(index)}}{
+#' Get predicted exogenous variables at specified index.}
+#' \item{\code{getExo(index)}}{
#' Get exogenous variables at specified index.}
+#' \item{\code{removeFirst()}}{
+#' Remove first list element (if truncated).}
+#' \item{\code{removeLast()}}{
+#' Remove last list element (if truncated).}
#' }
#'
Data = R6::R6Class("Data",
getStdHorizon = function()
24 - as.POSIXlt( private$.data[[1]]$time[1] )$hour + 1
,
- appendHat = function(time, hat_serie, hat_exo)
- {
- hat_level = mean(hat_serie, na.rm=TRUE)
- hat_centered_serie = hat_serie - hat_level
- private$.data[[length(private$.data)+1]] <- list(
- "time"=time, "hat_centered_serie"=hat_centered_serie,
- "hat_level"=hat_level, "hat_exo"=hat_exo )
- },
- append = function(serie, exo)
+ appendHat = function(time, exo_hat)
+ private$.data[[length(private$.data)+1]] <- list("time"=time,"exo_hat"=exo_hat)
+ ,
+ append = function(time, serie, exo)
{
+ index <- length(private$.data)
level = mean(serie, na.rm=TRUE)
centered_serie = serie - level
- private$.data[[length(private$.data)]]$centered_serie <- centered_serie,
- private$.data[[length(private$.data)]]$level <- level,
- private$.data[[length(private$.data)]]$exo <- exo,
+ private$.data[[index]]$time <- time
+ private$.data[[index]]$centered_serie <- centered_serie
+ private$.data[[index]]$level <- level
+ private$.data[[index]]$exo <- exo
},
getTime = function(index)
{
index = dateIndexToInteger(index, self)
private$.data[[index]]$time
},
- getCenteredSerie = function(index, hat=FALSE)
+ getCenteredSerie = function(index)
{
index = dateIndexToInteger(index, self)
- if (hat)
- private$.data[[index]]$hat_centered_serie
- else
- private$.data[[index]]$centered_serie
+ private$.data[[index]]$centered_serie
},
- getCenteredSeries = function(indices, hat=FALSE)
- sapply(indices, function(i) self$getCenteredSerie(i, hat))
+ getCenteredSeries = function(indices)
+ sapply(indices, function(i) self$getCenteredSerie(i))
,
- getLevel = function(index, hat=FALSE)
+ getLevel = function(index)
{
index = dateIndexToInteger(index, self)
- if (hat)
- private$.data[[index]]$hat_level
- else
- private$.data[[index]]$level
+ private$.data[[index]]$level
},
- getSerie = function(index, hat=FALSE)
+ getSerie = function(index)
{
index = dateIndexToInteger(index, self)
- if (hat)
- private$.data[[index]]$hat_centered_serie + private$.data[[index]]$hat_level
- else
- private$.data[[index]]$centered_serie + private$.data[[index]]$level
+ private$.data[[index]]$centered_serie + private$.data[[index]]$level
},
- getSeries = function(indices, hat=FALSE)
- sapply(indices, function(i) self$getSerie(i, hat))
+ getSeries = function(indices)
+ sapply(indices, function(i) self$getSerie(i))
,
- getExo = function(index, hat=FALSE)
+ getExoHat = function(index)
+ {
+ index = dateIndexToInteger(index, self)
+ private$.data[[index]]$exo_hat
+ },
+ getExo = function(index)
{
index = dateIndexToInteger(index, self)
- if (hat)
- private$.data[[index]]$hat_exo
- else
- private$.data[[index]]$exo
+ private$.data[[index]]$exo
},
removeFirst = function()
private$.data <- private$.data[2:length(private$.data)]