'update'
[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 = R6Class("Data",
19 private = list(
20 .data = "list"
21 ),
22 public = list(
23 initialize = function(...)
24 initialize(self, private, ...)
25 ,
26 getSize = function()
27 getSize()
28 ,
29 getStdHorizon = function()
30 getStdHorizon(self, private)
31 ,
32 append = function(new_time, new_serie, new_level, new_exo_hat, new_exo)
33 append(self, private,
34
35 data[[length(data)+1]] <<- list("time"=new_time,"serie"=new_serie,"level"=new_level,
36 "exo_hat"=new_exo_hat,"exo"=new_exo)
37 },
38 getTime = function(index)
39 {
40 "Time values at specified index"
41
42 index = dateIndexToInteger(index, .self)
43 data[[index]]$time
44 },
45 getCenteredSerie = function(index)
46 {
47 "Serie values (centered) at specified index"
48
49 index = dateIndexToInteger(index, .self)
50 data[[index]]$serie
51 },
52 getLevel = function(index)
53 {
54 "Level of the serie at specified index"
55
56 index = dateIndexToInteger(index, .self)
57 data[[index]]$level
58 },
59 getSerie = function(index)
60 {
61 "Serie values (centered+level) at specified index"
62
63 index = dateIndexToInteger(index, .self)
64 data[[index]]$serie + data[[index]]$level
65 },
66 getExoHat = function(index)
67 {
68 "Exogeous predictions at specified index"
69
70 index = dateIndexToInteger(index, .self)
71 data[[index]]$exo_hat
72 },
73 getExo = function(index)
74 {
75 "Exogenous measures at specified index"
76
77 index = dateIndexToInteger(index, .self)
78 data[[index]]$exo
79 }
80 )
81 )
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)