'update'
[talweg.git] / pkg / R / Data.R
CommitLineData
f17665c7 1#' Data
3d69ff21 2#'
f17665c7 3#' Data encapsulation
3d69ff21 4#'
a66a84b5
BA
5#' @docType class
6#' @importFrom R6 R6Class
7#'
8#' @field .data List of \itemize{
3d69ff21
BA
9#' \item time: vector of times
10#' \item serie: centered series
11#' \item level: corresponding levels
f17665c7 12#' \item exo: exogenous variables
a66a84b5 13#' \item exo_hat: predicted exogenous variables}
f17665c7 14#'
a66a84b5
BA
15#' @section Methods: \describe{
16#' \item{\code{getSize()}}
17#' {Return number of series in dataset.}
18#' \item{\code{getStdHorizon()}}
19#' {Return number of time steps from serie[1] until midnight}
20#' \item{\code{append(new_time, new_centered_serie, new_level, new_exo, new_exo_hat)}}
21#' {Acquire a new vector of lists (time, centered_serie, level, exo, exo_hat).}
22#' \item{\code{getTime(index)}}
23#' {Get times at specified index.}
24#' \item{\code{getCenteredSerie(index)}}
25#' {Get centered serie at specified index.}
26#' \item{\code{getLevel(index)}}
27#' {Get level at specified index.}
28#' \item{\code{getSerie(index)}}
29#' {Get serie (centered+level) at specified index.}
30#' \item{\code{getExo(index)}}
31#' {Get exogenous variables at specified index.}
32#' \item{\code{getExoHat(index)}}
33#' {Get estimated exogenous variables at specified index.} }
25b75559 34Data = R6::R6Class("Data",
35eb1443 35 private = list(
25b75559 36 .data = list()
35eb1443 37 ),
f17665c7 38 public = list(
3d69ff21 39 getSize = function()
a66a84b5 40 length(private$.data)
35eb1443 41 ,
e030a6e3 42 getStdHorizon = function()
a66a84b5 43 24 - as.POSIXlt( private$.data[[1]]$time[1] )$hour + 1
35eb1443 44 ,
a66a84b5
BA
45 append = function(
46 {
47 private$.data[[length(private$.data)+1]] <- list(
48 "time"=new_time, "centered_serie"=new_centered_serie, "level"=new_level,
49 "exo"=new_exo, "exo_hat"=new_exo_hat)
50 },
3d69ff21 51 getTime = function(index)
a66a84b5
BA
52 {
53 index = dateIndexToInteger(index, self)
54 private$.data[[index]]$time
55 },
3d69ff21 56 getCenteredSerie = function(index)
a66a84b5
BA
57 {
58 index = dateIndexToInteger(index, self)
59 private$.data[[index]]$centered_serie
60 },
3d69ff21 61 getLevel = function(index)
a66a84b5
BA
62 {
63 index = dateIndexToInteger(index, self)
64 private$.data[[index]]$level
65 },
3d69ff21 66 getSerie = function(index)
a66a84b5
BA
67 {
68 index = dateIndexToInteger(index, self)
69 private$.data[[index]]$centered_serie + private$.data[[index]]$level
70 },
1e20780e 71 getExo = function(index)
a66a84b5
BA
72 {
73 index = dateIndexToInteger(index, self)
74 private$.data[[index]]$exo
75 },
66877df3 76 getExoHat = function(index)
a66a84b5
BA
77 {
78 index = dateIndexToInteger(index, self)
79 private$.data[[index]]$exo_hat
80 },
81 removeFirst = function()
82 private$.data <- private$.data[2:length(private$.data)]
83 ,
84 removeLast = function()
85 private$.data <- private$.data[1:(length(private$.data)-1)]
3d69ff21
BA
86 )
87)