Simplify plots: version OK with R6 classes
[talweg.git] / pkg / R / F_Persistence.R
1 #' @include Forecaster.R
2 #'
3 #' Persistence Forecaster
4 #'
5 #' Return the last centered (similar) day curve.
6 #' Inherits \code{\link{Forecaster}}
7 PersistenceForecaster = R6::R6Class("PersistenceForecaster",
8 inherit = Forecaster,
9
10 public = list(
11 predictShape = function(data, today, memory, horizon, ...)
12 {
13 # Return centered last (similar) day curve, avoiding NAs until memory is run
14 first_day = max(1, today-memory)
15 same_day = ifelse(hasArg("same_day"), list(...)$same_day, TRUE)
16 # If 'same_day', get the last known future of similar day: -7 + 1 == -6
17 index = today - ifelse(same_day,6,0)
18 repeat
19 {
20 {
21 last_serie = data$getCenteredSerie(index)[1:horizon]
22 index = index - ifelse(same_day,7,1)
23 };
24 if (!any(is.na(last_serie)))
25 return (last_serie);
26 if (index < first_day)
27 return (NA)
28 }
29 }
30 )
31 )