X-Git-Url: https://git.auder.net/?p=talweg.git;a=blobdiff_plain;f=R%2FD_Persistence.R;h=979bf0533e9c45bdefde042e56d3c42828be37be;hp=2f7935a78709d80d1995ccf372cc0e8c9baeae3a;hb=09cf9c19b5c6a04bc23c58b7ac8a4bbae2c6827d;hpb=3d69ff21e577fc7bb082257280661b64536c20e8 diff --git a/R/D_Persistence.R b/R/D_Persistence.R index 2f7935a..979bf05 100644 --- a/R/D_Persistence.R +++ b/R/D_Persistence.R @@ -4,6 +4,19 @@ #' @inheritParams getZeroDeltaForecast getPersistenceDeltaForecast = function(data, today, memory, horizon, shape_params, ...) { - # Return level of last similar "tomorrow" (thus -6) computed on "horizon" - data$getSerie(today-6)[1] - tail(data$getSerie(today-7), 1) + #return gap between end of similar day curve and first day of tomorrow (in the past) + first_day = max(1, today-memory) + index = today-7 + repeat + { + { + last_similar_serie_end = tail( data$getCenteredSerie(index), 1) + last_similar_tomorrow_begin = data$getCenteredSerie(index+1)[1] + index = index - 7 + }; + if (!is.na(last_similar_serie_end) && !is.na(last_similar_tomorrow_begin)) + return (last_similar_tomorrow_begin - last_similar_serie_end); + if (index < first_day) + return (NA) + } }