intermediate: R6, too slow
[talweg.git] / pkg / R / Data.R
1 #' Data
2 #'
3 #' Data encapsulation
4 #'
5 #' @field data List of
6 #' \itemize{
7 #' \item time: vector of times
8 #' \item serie: centered series
9 #' \item level: corresponding levels
10 #' \item exo: exogenous variables
11 #' \item exo_hat: predicted exogenous variables
12 #' }
13 #'
14 #' @docType class
15 #' @importFrom R6 R6Class
16 #'
17 #' @export
18 Data = R6::R6Class("Data",
19 private = list(
20 .data = list()
21 ),
22 public = list(
23 getSize = function()
24 getSizeData(private)
25 ,
26 getStdHorizon = function()
27 getStdHorizonData(private)
28 ,
29 append = function(new_time, new_centered_serie, new_level, new_exo, new_exo_hat)
30 appendData(private, new_time, new_centered_serie, new_level, new_exo, new_exo_hat)
31 ,
32 getTime = function(index)
33 getTimeData(self, private, index)
34 ,
35 getCenteredSerie = function(index)
36 getCenteredSerieData(self, private, index)
37 ,
38 getLevel = function(index)
39 getLevelData(self, private, index)
40 ,
41 getSerie = function(index)
42 getSerieData(self, private, index)
43 ,
44 getExo = function(index)
45 getExoData(self, private, index)
46 ,
47 getExoHat = function(index)
48 getExoHatData(self, private, index)
49 )
50 )
51
52 #' Number of series in the dataset
53 #'
54 #' @param private List of private members in current object
55 getSizeData = function(private)
56 length(private$.data)
57
58 #' 'Standard' horizon, from t+1 to midnight
59 #'
60 #' @inheritParams getSizeData
61 getStdHorizonData = function(private)
62 24 - as.POSIXlt( private$.data[[1]]$time[1] )$hour + 1
63
64 #' Acquire a new vector of lists (time, centered_serie, level, exo, exo_hat)
65 #'
66 #' @inheritParams getSizeData
67 #' @param new_time Time
68 #' @param new_centered_serie Centered serie
69 #' @param new_level Level
70 #' @param new_exo Exogneous variables
71 #' @param new_exo_hat Predicted exogenous variables
72 appendData = function(private, new_time, new_centered_serie, new_level, new_exo, new_exo_hat)
73 {
74 private$.data[[length(private$.data)+1]] <- list("time"=new_time,
75 "centered_serie"=new_centered_serie,"level"=new_level,"exo"=new_exo,"exo_hat"=new_exo_hat)
76 }
77
78 #' Time values at specified index
79 #'
80 #' @inheritParams getSizeData
81 #' @param index Return value at this index
82 getTimeData = function(o, private, index)
83 {
84 index = dateIndexToInteger(index, o)
85 private$.data[[index]]$time
86 }
87
88 #' Centered serie values at specified index
89 #'
90 #' @inheritParams getTimeData
91 getCenteredSerieData = function(o, private, index)
92 {
93 index = dateIndexToInteger(index, o)
94 private$.data[[index]]$centered_serie
95 }
96
97 #' Level of the serie at specified index
98 #'
99 #' @inheritParams getTimeData
100 getLevelData = function(o, private, index)
101 {
102 index = dateIndexToInteger(index, o)
103 private$.data[[index]]$level
104 }
105
106 #' Serie values (centered+level) at specified index
107 #'
108 #' @inheritParams getTimeData
109 getSerieData = function(o, private, index)
110 {
111 index = dateIndexToInteger(index, o)
112 private$.data[[index]]$centered_serie + data[[index]]$level
113 }
114
115 #' Exogenous measures at specified index
116 #'
117 #' @inheritParams getTimeData
118 getExoData = function(o, private, index)
119 {
120 index = dateIndexToInteger(index, o)
121 private$.data[[index]]$exo
122 }
123
124 #' Exogeous predictions at specified index
125 #'
126 #' @inheritParams getTimeData
127 getExoHatData = function(o, private, index)
128 {
129 index = dateIndexToInteger(index, o)
130 private$.data[[index]]$exo_hat
131 }