From: Benjamin Auder Date: Sun, 26 Feb 2017 09:48:45 +0000 (+0100) Subject: use R6 class; remove data first and last elements --> simplify X-Git-Url: https://git.auder.net/doc/html/scripts/current/git-favicon.png?a=commitdiff_plain;h=66877df35f2fc9561728537c713c963230b0de45;p=talweg.git use R6 class; remove data first and last elements --> simplify --- diff --git a/pkg/R/Data.R b/pkg/R/Data.R index 18c67dd..27aa082 100644 --- a/pkg/R/Data.R +++ b/pkg/R/Data.R @@ -24,74 +24,96 @@ Data = R6Class("Data", initialize(self, private, ...) , getSize = function() - getSize() + getSize(private) , getStdHorizon = function() - getStdHorizon(self, private) + getStdHorizon(private) + , + append = function(new_time, new_centered_serie, new_level, new_exo, new_exo_hat) + append(private, new_time, new_centered_serie, new_level, new_exo, new_exo_hat) , - append = function(new_time, new_serie, new_level, new_exo_hat, new_exo) - append(self, private, - - data[[length(data)+1]] <<- list("time"=new_time,"serie"=new_serie,"level"=new_level, - "exo_hat"=new_exo_hat,"exo"=new_exo) - }, getTime = function(index) - { - "Time values at specified index" - - index = dateIndexToInteger(index, .self) - data[[index]]$time - }, + getTime(self, private, index) + , getCenteredSerie = function(index) - { - "Serie values (centered) at specified index" - - index = dateIndexToInteger(index, .self) - data[[index]]$serie - }, + getCenteredSerie(self, private, index) + , getLevel = function(index) - { - "Level of the serie at specified index" - - index = dateIndexToInteger(index, .self) - data[[index]]$level - }, + getLevel(self, private, index) + , getSerie = function(index) - { - "Serie values (centered+level) at specified index" - - index = dateIndexToInteger(index, .self) - data[[index]]$serie + data[[index]]$level - }, - getExoHat = function(index) - { - "Exogeous predictions at specified index" - - index = dateIndexToInteger(index, .self) - data[[index]]$exo_hat - }, + getSerie(self, private, index) + , getExo = function(index) - { - "Exogenous measures at specified index" - - index = dateIndexToInteger(index, .self) - data[[index]]$exo - } + getExo(self, private, index) + , + getExoHat = function(index) + getExoHat(self, private, index) ) ) +##TODO: @param... @inheritParams... + #' Initialize empty Data object -initialize = function(self, private, ...) +initialize = function(o, private, ...) { - invisible(self) + private$.data <<- if (hasArg("data")) list(...)$data else list() + invisible(o) } #' Number of series in the dataset -getSize = function(self, private) +getSize = function(private) length(private$.data) #' 'Standard' horizon, from t+1 to midnight -getStdHorizon = function(self, private) +getStdHorizon = function(private) 24 - as.POSIXlt( private$.data[[1]]$time[1] )$hour + 1 #' Acquire a new vector of lists (time, centered_serie, level, exo, exo_hat) +append = function(private, new_time, new_centered_serie, new_level, new_exo_hat, new_exo) +{ + private$.data[[length(private$.data)+1]] <<- list("time"=new_time, + "centered_serie"=new_centered_serie,"level"=new_level,"exo"=new_exo,"exo_hat"=new_exo_hat) +} + +#' Time values at specified index +getTime = function(o, private, index) +{ + index = dateIndexToInteger(index, o) + private$.data[[index]]$time +} + +#' Centered serie values at specified index +getCenteredSerie = function(o, private, index) +{ + index = dateIndexToInteger(index, o) + private$.data[[index]]$serie +} + +#' Level of the serie at specified index +getCenteredSerie = function(o, private, index) +{ + index = dateIndexToInteger(index, o) + private$.data[[index]]$level +} + +#' Serie values (centered+level) at specified index +getCenteredSerie = function(o, private, index) +{ + index = dateIndexToInteger(index, o) + private$.data[[index]]$serie + data[[index]]$level +} + +#' Exogenous measures at specified index +getCenteredSerie = function(o, private, index) +{ + index = dateIndexToInteger(index, o) + private$.data[[index]]$exo +} + +#' Exogeous predictions at specified index +getCenteredSerie = function(o, private, index) +{ + index = dateIndexToInteger(index, o) + private$.data[[index]]$exo_hat +}