TODO: unit tests for simil days
[talweg.git] / pkg / R / Data.R
index 53a8d5b..92ba2c1 100644 (file)
@@ -1,51 +1,57 @@
 #' Data
 #'
-#' Data encapsulation
+#' Data encapsulation as a list (days) of lists (components).
 #'
-#' @docType class
-#' @importFrom R6 R6Class
+#' The private field .data is a list where each cell contains the variables for a period
+#' of time of 24 hours, from time P+1 until P the next day where P is an integer between
+#' 0 and 23. .data[[1]] refers to the first measured data (serie and exogenous
+#' variables): the corresponding times can be accessed through the function
+#' \code{getTime()} below. Each cell .data[[i]] is itself a list containing five slots,
+#' as described in the 'field' section.
 #'
-#' @field .data List of
+#' @field .data[[i]] List of
 #' \itemize{
 #'   \item time: vector of times
-#'   \item centered_serie: centered series
-#'   \item level: corresponding levels
+#'   \item centered_serie: centered serie
+#'   \item level: corresponding level
 #'   \item exo: exogenous variables
-#'   \item exo_hat: predicted exogenous variables
+#'   \item exo_hat: predicted exogenous variables (for next day)
 #' }
 #'
 #' @section Methods:
 #' \describe{
 #' \item{\code{getSize()}}{
-#'   Return number of series in dataset.}
+#'   Number of series in dataset.}
 #' \item{\code{getStdHorizon()}}{
-#'   Return number of time steps from serie[1] until midnight}
-#' \item{\code{appendHat(time, exo_hat)}}{
-#'   New estimated exogenous variables + time}
-#' \item{\code{append(serie, exo)}}{
-#'   New measured data; call *after* \code{appendHat()}}
+#'   Number of time steps from serie[1] until midnight}
+#' \item{\code{append(time, serie, exo, exo_hat)}}{
+#'   Measured data for given vector of times + exogenous predictions from
+#'   last midgnight.}
 #' \item{\code{getTime(index)}}{
-#'   Get times at specified index.}
+#'   Times (vector) at specified index.}
 #' \item{\code{getCenteredSerie(index)}}{
-#'   Get (measured or predicted) centered serie at specified index.}
+#'   Centered serie at specified index.}
 #' \item{\code{getCenteredSeries(indices)}}{
-#'   Get centered series at specified indices (in columns).}
+#'   Centered series at specified indices (in columns).}
 #' \item{\code{getLevel(index)}}{
-#'   Get level at specified index.}
+#'   Level at specified index.}
 #' \item{\code{getSerie(index)}}{
-#'   Get serie (centered+level) at specified index.}
+#'   Serie (centered+level) at specified index.}
 #' \item{\code{getSeries(indices)}}{
-#'   Get series at specified indices (in columns).}
+#'   Series at specified indices (in columns).}
 #' \item{\code{getExoHat(index)}}{
-#'   Get predicted exogenous variables at specified index.}
+#'   Predicted exogenous variables at specified index.}
 #' \item{\code{getExo(index)}}{
-#'   Get exogenous variables at specified index.}
+#'   Measured exogenous variables at specified index.}
 #' \item{\code{removeFirst()}}{
 #'   Remove first list element (if truncated).}
 #' \item{\code{removeLast()}}{
 #'   Remove last list element (if truncated).}
 #' }
 #'
+#' @docType class
+#' @format R6 class
+#'
 Data = R6::R6Class("Data",
        private = list(
                .data = list()
@@ -57,18 +63,16 @@ Data = R6::R6Class("Data",
                getStdHorizon = function()
                        24 - as.POSIXlt( private$.data[[1]]$time[1] )$hour + 1
                ,
-               appendHat = function(time, exo_hat)
-                       private$.data[[length(private$.data)+1]] <- list("time"=time,"exo_hat"=exo_hat)
-               ,
-               append = function(time, serie, exo)
+               append = function(time, serie, exo, exo_hat)
                {
-                       index <- length(private$.data)
                        level = mean(serie, na.rm=TRUE)
                        centered_serie = serie - level
-                       private$.data[[index]]$time <- time
-                       private$.data[[index]]$centered_serie <- centered_serie
-                       private$.data[[index]]$level <- level
-                       private$.data[[index]]$exo <- exo
+                       private$.data[[length(private$.data)+1]] <- list(
+                               "time"=time, #H-24 --> H-1
+                               "centered_serie"=centered_serie, #at 'time'
+                               "level"=level, #at 'time'
+                               "exo"=exo, #at 'time' (yersteday 0am to last midnight)
+                               "exo_hat"=exo_hat) #today 0am to next midnight
                },
                getTime = function(index)
                {