new version, persistence -7 days
[talweg.git] / R / Data.R
1 #' @title Data
2 #'
3 #' @description 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_hat: predicted exogenous variables
11 #' \item exo_Dm1: List of measured exogenous variables at day minus 1
12 #' }
13 #'
14 #' @exportClass Data
15 #' @export Data
16 Data = setRefClass(
17 Class = "Data",
18
19 fields = list(
20 data = "list"
21 ),
22
23 methods = list(
24 initialize = function(...)
25 {
26 "Initialize empty Data object"
27
28 callSuper(...)
29 },
30 getSize = function()
31 {
32 "Number of series in the dataset"
33
34 length(data)
35 },
36 getStdHorizon = function()
37 {
38 "'Standard' horizon, from t+1 to midnight"
39
40 L1 = length(data[[1]]$serie)
41 L2 = length(data[[2]]$serie)
42 if (L1 < L2)
43 L2 - L1
44 else
45 L1
46 },
47 append = function(new_time, new_serie, new_level, new_exo_hat, new_exo_Dm1)
48 {
49 "Acquire a new vector of lists (time, serie, level, exo_hat, exo_Dm1)"
50
51 data[[length(data)+1]] <<- list("time"=new_time,"serie"=new_serie,"level"=new_level,
52 "exo_hat"=new_exo_hat,"exo_Dm1"=new_exo_Dm1)
53 },
54 getTime = function(index)
55 {
56 "Get time values at specified index"
57
58 index = dateIndexToInteger(index, .self)
59 data[[index]]$time
60 },
61 getCenteredSerie = function(index)
62 {
63 "Get serie values (centered) at specified index"
64
65 index = dateIndexToInteger(index, .self)
66 data[[index]]$serie
67 },
68 getLevel = function(index)
69 {
70 "Get level for the serie at specified index"
71
72 index = dateIndexToInteger(index, .self)
73 data[[index]]$level
74 },
75 getSerie = function(index)
76 {
77 "Get serie values (centered+level) at specified index"
78
79 index = dateIndexToInteger(index, .self)
80 data[[index]]$serie + data[[index]]$level
81 },
82 getExoHat = function(index)
83 {
84 "Get exogeous predictions at specified index"
85
86 index = dateIndexToInteger(index, .self)
87 data[[index]]$exo_hat
88 },
89 getExoDm1 = function(index)
90 {
91 "Get exogenous measures the day before specified index"
92
93 index = dateIndexToInteger(index, .self)
94 data[[index]]$exo_Dm1
95 }
96 )
97 )