reorganize folder
[talweg.git] / pkg / R / F_Level.R
diff --git a/pkg/R/F_Level.R b/pkg/R/F_Level.R
new file mode 100644 (file)
index 0000000..a186c1a
--- /dev/null
@@ -0,0 +1,35 @@
+#' @include Forecaster.R
+#'
+#' @title Level Forecaster
+#'
+#' @description Return flat serie of last observed level. Inherits \code{\link{ShapeForecaster}}
+LevelForecaster = setRefClass(
+       Class = "LevelForecaster",
+       contains = "Forecaster",
+
+       methods = list(
+               initialize = function(...)
+               {
+                       callSuper(...)
+               },
+               predict = function(today, memory, horizon, ...)
+               {
+                       #return last day level
+                       first_day = max(1, today-memory)
+                       same_day = ifelse(hasArg("same_day"), list(...)$same_day, TRUE)
+                       index = today - ifelse(same_day,6,0)
+                       repeat
+                       {
+                               {
+                                       last_serie = data$getSerie(index)[1:horizon]
+                                       index = index - ifelse(same_day,7,1)
+                               };
+                               #TODO: next test is too strict
+                               if (!any(is.na(last_serie)))
+                                       return (rep(mean(last_serie), horizon));
+                               if (index < first_day)
+                                       return (NA)
+                       }
+               }
+       )
+)