on the way back without realtime
[talweg.git] / pkg / R / F_Persistence.R
CommitLineData
25b75559 1#' Persistence Forecaster
3d69ff21 2#'
25b75559
BA
3#' Return the last centered (similar) day curve.
4#' Inherits \code{\link{Forecaster}}
546b0cb6 5#'
25b75559 6PersistenceForecaster = R6::R6Class("PersistenceForecaster",
a66a84b5 7 inherit = Forecaster,
3d69ff21 8
25b75559 9 public = list(
98e958ca 10 predictShape = function(data, today, memory, horizon, ...)
3d69ff21 11 {
e5aa669a 12 # Return centered last (similar) day curve, avoiding NAs until memory is run
09cf9c19 13 first_day = max(1, today-memory)
e5aa669a
BA
14 same_day = ifelse(hasArg("same_day"), list(...)$same_day, TRUE)
15 # If 'same_day', get the last known future of similar day: -7 + 1 == -6
16 index = today - ifelse(same_day,6,0)
09cf9c19
BA
17 repeat
18 {
19 {
2057c793 20 last_serie = data$getCenteredSerie(index)[1:horizon]
e5aa669a 21 index = index - ifelse(same_day,7,1)
09cf9c19 22 };
e5aa669a
BA
23 if (!any(is.na(last_serie)))
24 return (last_serie);
09cf9c19
BA
25 if (index < first_day)
26 return (NA)
27 }
3d69ff21
BA
28 }
29 )
30)