X-Git-Url: https://git.auder.net/?p=talweg.git;a=blobdiff_plain;f=pkg%2FR%2FJ_Persistence.R;fp=pkg%2FR%2FJ_Persistence.R;h=8298a892a94a8f38c0a4a73a807fe27e17a628d9;hp=9e56742680a3db4702cb535a98f5aabdadbcfded;hb=af718fd5a9a330b13b331e78824a47407a3479ae;hpb=c8a81efd2e8302cde424165539f49e4bb7466fc3 diff --git a/pkg/R/J_Persistence.R b/pkg/R/J_Persistence.R index 9e56742..8298a89 100644 --- a/pkg/R/J_Persistence.R +++ b/pkg/R/J_Persistence.R @@ -10,22 +10,25 @@ #' #' @aliases J_Persistence #' -getPersistenceJumpPredict = function(data, today, memory, horizon, params, ...) +getPersistenceJumpPredict = function(data, today, memory, predict_from, + horizon, params, ...) { #return gap between end of similar day curve and first day of tomorrow (in the past) first_day = max(1, today-memory) same_day = ifelse(hasArg("same_day"), list(...)$same_day, TRUE) - index = today - ifelse(same_day,7,1) + index <- today repeat { - { - last_serie_end = tail( data$getSerie(index), 1) - last_tomorrow_begin = head( data$getSerie(index+1), 1) - index = index - ifelse(same_day,7,1) - }; - if (!is.na(last_serie_end) && !is.na(last_tomorrow_begin)) - return (last_tomorrow_begin - last_serie_end); + # If 'same_day', get the last known future of similar day + index = index - ifelse(same_day,7,1) if (index < first_day) return (NA) + gap <- + if (predict_from >= 2) + data$getSerie(index)[predict_from] - data$getSerie(index)[predict_from-1] + else + head(data$getSerie(index),1) - tail(data$getSerie(index-1),1) + if (!is.na(gap)) + return (gap) } }