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