--- /dev/null
+#' @include Forecaster.R
+#'
+#' @title Level Forecaster
+#'
+#' @description Return flat serie of last observed level (on similar day).
+#' Inherits \code{\link{ShapeForecaster}}
+LevelForecaster = setRefClass(
+ Class = "LevelForecaster",
+ contains = "Forecaster",
+
+ methods = list(
+ initialize = function(...)
+ {
+ callSuper(...)
+ },
+ predict = function(today, memory, horizon, all_memory=TRUE, ...)
+ {
+ #return last (similar) day level, or on all memory if all_memory==TRUE
+ first_day = max(1, today-memory)
+ index = today-7 + 1
+ if (all_memory)
+ {
+ sum_level = 0.
+ nb_series = 0
+ }
+ repeat
+ {
+ {
+ last_similar_serie = data$getSerie(index)[1:horizon]
+ index = index - 7
+ };
+ #TODO: next test is too strict
+ if (!any(is.na(last_similar_serie)))
+ {
+ if (all_memory)
+ {
+ sum_level = sum_level + mean(last_similar_serie)
+ nb_series = nb_series + 1
+ }
+ else
+ return (rep(mean(last_similar_serie), horizon))
+ };
+ if (index < first_day)
+ {
+ if (all_memory)
+ return (rep(sum_level / nb_series, horizon))
+ return (NA)
+ }
+ }
+ }
+ )
+)