clarify data acquisition; TODO: improve doc + usage
authorBenjamin Auder <benjamin.auder@somewhere>
Fri, 7 Apr 2017 10:01:01 +0000 (12:01 +0200)
committerBenjamin Auder <benjamin.auder@somewhere>
Fri, 7 Apr 2017 10:01:01 +0000 (12:01 +0200)
pkg/R/Data.R
pkg/R/computeForecast.R
pkg/R/getData.R

index 610c0c4..39f3837 100644 (file)
@@ -57,18 +57,16 @@ Data = R6::R6Class("Data",
                getStdHorizon = function()
                        24 - as.POSIXlt( private$.data[[1]]$time[1] )$hour + 1
                ,
-               append = function(time, exo_hat)
-                       private$.data[[length(private$.data)+1]] <- list("time"=time,"exo_hat"=exo_hat)
-               ,
-               append = function(time, serie, exo)
+               append = function(time, serie, exo, exo_hat)
                {
-                       index <- length(private$.data)
                        level = mean(serie, na.rm=TRUE)
                        centered_serie = serie - level
-                       private$.data[[index]]$time <- time
-                       private$.data[[index]]$centered_serie <- centered_serie
-                       private$.data[[index]]$level <- level
-                       private$.data[[index]]$exo <- exo
+                       private$.data[[length(private$.data)+1]] <- list(
+                               "time"=time, #H-24 --> H-1
+                               "centered_serie"=centered_serie, #at 'time'
+                               "level"=level, #at 'time'
+                               "exo"=exo, #at 'time' (yersteday 0am to last midnight)
+                               "exo_hat"=exo_hat) #today 0am to next midnight
                },
                getTime = function(index)
                {
index 53dbc14..4bab811 100644 (file)
@@ -34,8 +34,6 @@
 #'   memory=500, horizon=12, ncores=1)
 #' \dontrun{#Sketch for real-time mode:
 #' data <- Data$new()
-#' # Initialize: first day has no predictions attached
-#' data$initialize()
 #' forecaster <- MyForecaster$new(myJumpPredictFunc)
 #' repeat {
 #'   # In the morning 7am+ or afternoon 1pm+:
index 4e2e3fd..268c54a 100644 (file)
@@ -86,7 +86,11 @@ getData = function(ts_data, exo_data, input_tz="GMT", date_format="%d/%m/%Y %H:%
                }
 
                exo = as.data.frame( exo_df[i,2:(1+nb_exos)] )
-               exo_hat = as.data.frame( exo_df[i,(1+nb_exos+1):(1+2*nb_exos)] )
+               exo_hat =
+                       if (i < nrow(exo_df))
+                               as.data.frame( exo_df[i+1,(1+nb_exos+1):(1+2*nb_exos)] )
+                       else
+                               NA #exogenous prediction for next day are useless on last day
                data$append(time, serie, exo, exo_hat)
                if (i >= limit)
                        break