add realtime option, slightly refactor data acquisition
[talweg.git] / pkg / R / F_Average.R
1 #' @include Forecaster.R
2 #'
3 #' Average Forecaster
4 #'
5 #' Return the (pointwise) average of the all the (similar) centered day curves
6 #' in the past. Inherits \code{\link{Forecaster}}
7 #'
8 AverageForecaster = R6::R6Class("AverageForecaster",
9 inherit = Forecaster,
10
11 public = list(
12 predictShape = function(data, today, memory, horizon, ...)
13 {
14 avg = rep(0., horizon)
15 first_day = max(1, today-memory)
16 index = today-7 + 1
17 nb_no_na_series = 0
18 repeat
19 {
20 {
21 serie_on_horizon = data$getCenteredSerie(index)[1:horizon]
22 index = index - 7
23 };
24 if (!any(is.na(serie_on_horizon)))
25 {
26 avg = avg + serie_on_horizon
27 nb_no_na_series = nb_no_na_series + 1
28 };
29 if (index < first_day)
30 break
31 }
32 avg / nb_no_na_series
33 }
34 )
35 )