on the way to R6 class + remove truncated days (simplifications)
[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 public = list(
20 data = "list",
21 initialize = function(...)
22 {
23 "Initialize empty Data object"
24 #TODO: continue from here
25 callSuper(...)
26 },
27 getSize = function()
28 {
29 "Number of series in the dataset"
30
31 length(data)
32 },
33 getStdHorizon = function()
34 {
35 "'Standard' horizon, from t+1 to midnight"
36
37 24 - as.POSIXlt( data[[1]]$time[1] )$hour + 1
38 },
39 append = function(new_time, new_serie, new_level, new_exo_hat, new_exo)
40 {
41 "Acquire a new vector of lists (time, serie, level, exo_hat, exo)"
42
43 data[[length(data)+1]] <<- list("time"=new_time,"serie"=new_serie,"level"=new_level,
44 "exo_hat"=new_exo_hat,"exo"=new_exo)
45 },
46 getTime = function(index)
47 {
48 "Time values at specified index"
49
50 index = dateIndexToInteger(index, .self)
51 data[[index]]$time
52 },
53 getCenteredSerie = function(index)
54 {
55 "Serie values (centered) at specified index"
56
57 index = dateIndexToInteger(index, .self)
58 data[[index]]$serie
59 },
60 getLevel = function(index)
61 {
62 "Level of the serie at specified index"
63
64 index = dateIndexToInteger(index, .self)
65 data[[index]]$level
66 },
67 getSerie = function(index)
68 {
69 "Serie values (centered+level) at specified index"
70
71 index = dateIndexToInteger(index, .self)
72 data[[index]]$serie + data[[index]]$level
73 },
74 getExoHat = function(index)
75 {
76 "Exogeous predictions at specified index"
77
78 index = dateIndexToInteger(index, .self)
79 data[[index]]$exo_hat
80 },
81 getExo = function(index)
82 {
83 "Exogenous measures at specified index"
84
85 index = dateIndexToInteger(index, .self)
86 data[[index]]$exo
87 }
88 )
89 )