Commit | Line | Data |
---|---|---|
f17665c7 | 1 | #' Data |
3d69ff21 | 2 | #' |
f17665c7 | 3 | #' Data encapsulation |
3d69ff21 BA |
4 | #' |
5 | #' @field data List of | |
6 | #' \itemize{ | |
7 | #' \item time: vector of times | |
8 | #' \item serie: centered series | |
9 | #' \item level: corresponding levels | |
f17665c7 | 10 | #' \item exo: exogenous variables |
3d69ff21 | 11 | #' \item exo_hat: predicted exogenous variables |
3d69ff21 BA |
12 | #' } |
13 | #' | |
f17665c7 BA |
14 | #' @docType class |
15 | #' @importFrom R6 R6Class | |
16 | #' | |
17 | #' @export | |
18 | Data = R6Class("Data", | |
35eb1443 BA |
19 | private = list( |
20 | .data = "list" | |
21 | ), | |
f17665c7 | 22 | public = list( |
3d69ff21 | 23 | initialize = function(...) |
35eb1443 BA |
24 | initialize(self, private, ...) |
25 | , | |
3d69ff21 | 26 | getSize = function() |
35eb1443 BA |
27 | getSize() |
28 | , | |
e030a6e3 | 29 | getStdHorizon = function() |
35eb1443 BA |
30 | getStdHorizon(self, private) |
31 | , | |
dea7ff86 | 32 | append = function(new_time, new_serie, new_level, new_exo_hat, new_exo) |
35eb1443 | 33 | append(self, private, |
3d69ff21 BA |
34 | |
35 | data[[length(data)+1]] <<- list("time"=new_time,"serie"=new_serie,"level"=new_level, | |
dea7ff86 | 36 | "exo_hat"=new_exo_hat,"exo"=new_exo) |
3d69ff21 BA |
37 | }, |
38 | getTime = function(index) | |
39 | { | |
1e20780e | 40 | "Time values at specified index" |
3d69ff21 | 41 | |
09cf9c19 | 42 | index = dateIndexToInteger(index, .self) |
3d69ff21 BA |
43 | data[[index]]$time |
44 | }, | |
45 | getCenteredSerie = function(index) | |
46 | { | |
1e20780e | 47 | "Serie values (centered) at specified index" |
3d69ff21 | 48 | |
09cf9c19 | 49 | index = dateIndexToInteger(index, .self) |
3d69ff21 BA |
50 | data[[index]]$serie |
51 | }, | |
52 | getLevel = function(index) | |
53 | { | |
1e20780e | 54 | "Level of the serie at specified index" |
3d69ff21 | 55 | |
09cf9c19 | 56 | index = dateIndexToInteger(index, .self) |
3d69ff21 BA |
57 | data[[index]]$level |
58 | }, | |
59 | getSerie = function(index) | |
60 | { | |
1e20780e | 61 | "Serie values (centered+level) at specified index" |
3d69ff21 | 62 | |
09cf9c19 | 63 | index = dateIndexToInteger(index, .self) |
3d69ff21 BA |
64 | data[[index]]$serie + data[[index]]$level |
65 | }, | |
66 | getExoHat = function(index) | |
67 | { | |
1e20780e | 68 | "Exogeous predictions at specified index" |
3d69ff21 | 69 | |
09cf9c19 | 70 | index = dateIndexToInteger(index, .self) |
3d69ff21 BA |
71 | data[[index]]$exo_hat |
72 | }, | |
1e20780e | 73 | getExo = function(index) |
3d69ff21 | 74 | { |
1e20780e | 75 | "Exogenous measures at specified index" |
3d69ff21 | 76 | |
09cf9c19 | 77 | index = dateIndexToInteger(index, .self) |
dea7ff86 | 78 | data[[index]]$exo |
3d69ff21 BA |
79 | } |
80 | ) | |
81 | ) | |
35eb1443 BA |
82 | |
83 | #' Initialize empty Data object | |
84 | initialize = function(self, private, ...) | |
85 | { | |
86 | invisible(self) | |
87 | } | |
88 | ||
89 | #' Number of series in the dataset | |
90 | getSize = function(self, private) | |
91 | length(private$.data) | |
92 | ||
93 | #' 'Standard' horizon, from t+1 to midnight | |
94 | getStdHorizon = function(self, private) | |
95 | 24 - as.POSIXlt( private$.data[[1]]$time[1] )$hour + 1 | |
96 | ||
97 | #' Acquire a new vector of lists (time, centered_serie, level, exo, exo_hat) |