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