reorganize folder
[talweg.git] / pkg / R / F_Level.R
CommitLineData
e030a6e3
BA
1#' @include Forecaster.R
2#'
3#' @title Level Forecaster
4#'
e5aa669a 5#' @description Return flat serie of last observed level. Inherits \code{\link{ShapeForecaster}}
e030a6e3
BA
6LevelForecaster = setRefClass(
7 Class = "LevelForecaster",
8 contains = "Forecaster",
9
10 methods = list(
11 initialize = function(...)
12 {
13 callSuper(...)
14 },
e5aa669a 15 predict = function(today, memory, horizon, ...)
e030a6e3 16 {
e5aa669a 17 #return last day level
e030a6e3 18 first_day = max(1, today-memory)
e5aa669a
BA
19 same_day = ifelse(hasArg("same_day"), list(...)$same_day, TRUE)
20 index = today - ifelse(same_day,6,0)
e030a6e3
BA
21 repeat
22 {
23 {
e5aa669a
BA
24 last_serie = data$getSerie(index)[1:horizon]
25 index = index - ifelse(same_day,7,1)
e030a6e3
BA
26 };
27 #TODO: next test is too strict
e5aa669a
BA
28 if (!any(is.na(last_serie)))
29 return (rep(mean(last_serie), horizon));
e030a6e3 30 if (index < first_day)
e030a6e3 31 return (NA)
e030a6e3
BA
32 }
33 }
34 )
35)