intermediate: R6, too slow
[talweg.git] / data / scripts / repair_HACK.R
... / ...
CommitLineData
1 # HACK for test reports: complete some days with a few NAs, for nicer graphics
2 nas_in_serie = is.na(data$getSerie(today))
3 if (any(nas_in_serie))
4 {
5 if (sum(nas_in_serie) >= length(nas_in_serie) / 2)
6 return (NA)
7 for (i in seq_along(nas_in_serie))
8 {
9 if (nas_in_serie[i])
10 {
11 #look left
12 left = i-1
13 while (left>=1 && nas_in_serie[left])
14 left = left-1
15 #look right
16 right = i+1
17 while (right<=length(nas_in_serie) && nas_in_serie[right])
18 right = right+1
19 #HACK: modify by-reference Data object...
20 data$data[[today]]$serie[i] <<-
21 if (left==0) data$data[[today]]$serie[right]
22 else if (right==0) data$data[[today]]$serie[left]
23 else (data$data[[today]]$serie[left] + data$data[[today]]$serie[right]) / 2.
24 }
25 }
26 }
27