Simplify plots: version OK with R6 classes
[talweg.git] / pkg / R / F_Persistence.R
CommitLineData
e030a6e3 1#' @include Forecaster.R
3d69ff21 2#'
25b75559 3#' Persistence Forecaster
3d69ff21 4#'
25b75559
BA
5#' Return the last centered (similar) day curve.
6#' Inherits \code{\link{Forecaster}}
7PersistenceForecaster = R6::R6Class("PersistenceForecaster",
a66a84b5 8 inherit = Forecaster,
3d69ff21 9
25b75559 10 public = list(
98e958ca 11 predictShape = function(data, today, memory, horizon, ...)
3d69ff21 12 {
e5aa669a 13 # Return centered last (similar) day curve, avoiding NAs until memory is run
09cf9c19 14 first_day = max(1, today-memory)
e5aa669a
BA
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)
09cf9c19
BA
18 repeat
19 {
20 {
98e958ca 21 last_serie = data$getCenteredSerie(index)[1:horizon]
e5aa669a 22 index = index - ifelse(same_day,7,1)
09cf9c19 23 };
e5aa669a
BA
24 if (!any(is.na(last_serie)))
25 return (last_serie);
09cf9c19
BA
26 if (index < first_day)
27 return (NA)
28 }
3d69ff21
BA
29 }
30 )
31)