name instead of year; ipynb generator debugged, with logging
[talweg.git] / pkg / R / J_Persistence.R
CommitLineData
e030a6e3 1#' Obtain jump forecast by the Persistence method
3d69ff21 2#'
99f83c9a 3#' @inheritParams computeForecast
e030a6e3
BA
4#' @inheritParams getZeroJumpPredict
5getPersistenceJumpPredict = function(data, today, memory, horizon, params, ...)
3d69ff21 6{
09cf9c19
BA
7 #return gap between end of similar day curve and first day of tomorrow (in the past)
8 first_day = max(1, today-memory)
e5aa669a
BA
9 same_day = ifelse(hasArg("same_day"), list(...)$same_day, TRUE)
10 index = today - ifelse(same_day,7,1)
09cf9c19
BA
11 repeat
12 {
13 {
e5aa669a
BA
14 last_serie_end = tail( data$getSerie(index), 1)
15 last_tomorrow_begin = data$getSerie(index+1)[1]
16 index = index - ifelse(same_day,7,1)
09cf9c19 17 };
e5aa669a
BA
18 if (!is.na(last_serie_end) && !is.na(last_tomorrow_begin))
19 return (last_tomorrow_begin - last_serie_end);
09cf9c19
BA
20 if (index < first_day)
21 return (NA)
22 }
3d69ff21 23}