use R6 class; remove data first and last elements --> simplify
[talweg.git] / pkg / R / Data.R
... / ...
CommitLineData
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
18Data = 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(private)
28 ,
29 getStdHorizon = function()
30 getStdHorizon(private)
31 ,
32 append = function(new_time, new_centered_serie, new_level, new_exo, new_exo_hat)
33 append(private, new_time, new_centered_serie, new_level, new_exo, new_exo_hat)
34 ,
35 getTime = function(index)
36 getTime(self, private, index)
37 ,
38 getCenteredSerie = function(index)
39 getCenteredSerie(self, private, index)
40 ,
41 getLevel = function(index)
42 getLevel(self, private, index)
43 ,
44 getSerie = function(index)
45 getSerie(self, private, index)
46 ,
47 getExo = function(index)
48 getExo(self, private, index)
49 ,
50 getExoHat = function(index)
51 getExoHat(self, private, index)
52 )
53)
54
55##TODO: @param... @inheritParams...
56
57#' Initialize empty Data object
58initialize = function(o, private, ...)
59{
60 private$.data <<- if (hasArg("data")) list(...)$data else list()
61 invisible(o)
62}
63
64#' Number of series in the dataset
65getSize = function(private)
66 length(private$.data)
67
68#' 'Standard' horizon, from t+1 to midnight
69getStdHorizon = function(private)
70 24 - as.POSIXlt( private$.data[[1]]$time[1] )$hour + 1
71
72#' Acquire a new vector of lists (time, centered_serie, level, exo, exo_hat)
73append = function(private, new_time, new_centered_serie, new_level, new_exo_hat, new_exo)
74{
75 private$.data[[length(private$.data)+1]] <<- list("time"=new_time,
76 "centered_serie"=new_centered_serie,"level"=new_level,"exo"=new_exo,"exo_hat"=new_exo_hat)
77}
78
79#' Time values at specified index
80getTime = function(o, private, index)
81{
82 index = dateIndexToInteger(index, o)
83 private$.data[[index]]$time
84}
85
86#' Centered serie values at specified index
87getCenteredSerie = function(o, private, index)
88{
89 index = dateIndexToInteger(index, o)
90 private$.data[[index]]$serie
91}
92
93#' Level of the serie at specified index
94getCenteredSerie = function(o, private, index)
95{
96 index = dateIndexToInteger(index, o)
97 private$.data[[index]]$level
98}
99
100#' Serie values (centered+level) at specified index
101getCenteredSerie = function(o, private, index)
102{
103 index = dateIndexToInteger(index, o)
104 private$.data[[index]]$serie + data[[index]]$level
105}
106
107#' Exogenous measures at specified index
108getCenteredSerie = function(o, private, index)
109{
110 index = dateIndexToInteger(index, o)
111 private$.data[[index]]$exo
112}
113
114#' Exogeous predictions at specified index
115getCenteredSerie = function(o, private, index)
116{
117 index = dateIndexToInteger(index, o)
118 private$.data[[index]]$exo_hat
119}