e33e4809022e7875e53f88649b8431799826acb1
[talweg.git] / pkg / R / Data.R
1 #' Data
2 #'
3 #' Data encapsulation
4 #'
5 #' @docType class
6 #' @importFrom R6 R6Class
7 #'
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}
14 #'
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.}}
34 Data = R6::R6Class("Data",
35 private = list(
36 .data = list()
37 ),
38 public = list(
39 getSize = function()
40 length(private$.data)
41 ,
42 getStdHorizon = function()
43 24 - as.POSIXlt( private$.data[[1]]$time[1] )$hour + 1
44 ,
45 append = function(new_time, new_centered_serie, new_level, new_exo, new_exo_hat)
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 },
51 getTime = function(index)
52 {
53 index = dateIndexToInteger(index, self)
54 private$.data[[index]]$time
55 },
56 getCenteredSerie = function(index)
57 {
58 index = dateIndexToInteger(index, self)
59 private$.data[[index]]$centered_serie
60 },
61 getLevel = function(index)
62 {
63 index = dateIndexToInteger(index, self)
64 private$.data[[index]]$level
65 },
66 getSerie = function(index)
67 {
68 index = dateIndexToInteger(index, self)
69 private$.data[[index]]$centered_serie + private$.data[[index]]$level
70 },
71 getExo = function(index)
72 {
73 index = dateIndexToInteger(index, self)
74 private$.data[[index]]$exo
75 },
76 getExoHat = function(index)
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)]
86 )
87 )