- # Predict only on (almost) non-NAs days
- nas_in_serie = is.na(data$getSerie(today))
- if (any(nas_in_serie))
- {
- #TODO: better define "repairing" conditions (and method)
- if (sum(nas_in_serie) >= length(nas_in_serie) / 2)
- return (NA)
- for (i in seq_along(nas_in_serie))
- {
- if (nas_in_serie[i])
- {
- #look left
- left = i-1
- while (left>=1 && nas_in_serie[left])
- left = left-1
- #look right
- right = i+1
- while (right<=length(nas_in_serie) && nas_in_serie[right])
- right = right+1
- #HACK: modify by-reference Data object...
- data$data[[today]]$serie[i] <<-
- if (left==0) data$data[[today]]$serie[right]
- else if (right==0) data$data[[today]]$serie[left]
- else (data$data[[today]]$serie[left] + data$data[[today]]$serie[right]) / 2.
- }
- }
- }
+ # Do not forecast on days with NAs (TODO: softer condition...)
+ if (any(is.na(data$getCenteredSerie(today))))
+ return (NA)