changeset 3101:41ed69dbf9bb

Nash Sutcliffe: Optimization: When append predicted values only accept predictions where the issue date is 24/48/72h in the past of the measure date.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 25 Apr 2019 11:39:17 +0200
parents d79e6045452e
children a9c7825303b3
files pkg/controllers/gauges.go
diffstat 1 files changed, 23 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/controllers/gauges.go	Thu Apr 25 11:15:27 2019 +0200
+++ b/pkg/controllers/gauges.go	Thu Apr 25 11:39:17 2019 +0200
@@ -448,6 +448,23 @@
 	}
 	defer rows.Close()
 
+	acceptedDeltas := []time.Duration{
+		-time.Hour * 24,
+		-time.Hour * 48,
+		-time.Hour * 72,
+	}
+
+	isAccepted := func(observed, predicted time.Time) bool {
+		for _, delta := range acceptedDeltas {
+			t := observed.Add(delta)
+			d := predicted.Sub(t)
+			if -10*time.Millisecond < d && d < 10*time.Millisecond {
+				return true
+			}
+		}
+		return false
+	}
+
 	var (
 		hasCurrent bool
 		current    observedPredictedValues
@@ -491,22 +508,12 @@
 		}
 
 		if predicted {
-			current.predicted = append(
-				current.predicted,
-				common.TimedValue{When: issueDate, Value: value},
-			)
-			/*
-				// current prediction same as last two?
-				if l := len(current.predicted); l > 1 && current.predicted[l-1].Value == value && current.predicted[l-2].Value == value {
-					// only update last time.
-					current.predicted[l-1].When = issueDate
-				} else {
-					current.predicted = append(
-						current.predicted,
-						common.TimedValue{When: issueDate, Value: value},
-					)
-				}
-			*/
+			if isAccepted(measureDate, issueDate) {
+				current.predicted = append(
+					current.predicted,
+					common.TimedValue{When: issueDate, Value: value},
+				)
+			}
 		} else {
 			current.observed = value
 		}