add realtime option, slightly refactor data acquisition
[talweg.git] / pkg / R / J_Persistence.R
index 5d156cc..4d3abd2 100644 (file)
@@ -8,12 +8,13 @@ getPersistenceJumpPredict = function(data, today, memory, 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)
+       realtime = ifelse(hasArg("realtime"), list(...)$realtime, FALSE)
        index = today - ifelse(same_day,7,1)
        repeat
        {
                {
                        last_serie_end = tail( data$getSerie(index), 1)
-                       last_tomorrow_begin = data$getSerie(index+1)[1]
+                       last_tomorrow_begin = data$getSerie(index+1,hat=(realtime && index+1==today))[1]
                        index = index - ifelse(same_day,7,1)
                };
                if (!is.na(last_serie_end) && !is.na(last_tomorrow_begin))