changeset 3679:0227670dedd5

Use infinite validity for bottlenecks with no validity information.
author Sascha Wilde <wilde@intevation.de>
date Mon, 17 Jun 2019 18:45:48 +0200
parents 8f58851927c0
children 0300282b9537
files pkg/imports/bn.go
diffstat 1 files changed, 46 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/imports/bn.go	Mon Jun 17 17:31:35 2019 +0200
+++ b/pkg/imports/bn.go	Mon Jun 17 18:45:48 2019 +0200
@@ -296,40 +296,57 @@
 ) error {
 	feedback.Info("Processing %s (%s)", bn.OBJNAM, bn.Bottleneck_id)
 
+	var tfrom, tto pgtype.Timestamptz
+	var uBound pgtype.BoundType
+
 	if bn.AdditionalData == nil || bn.AdditionalData.KeyValuePair == nil {
-		feedback.Warn("Missing validity information")
-		return nil
-	}
-	const (
-		fromKey = "Valid_from_date"
-		toKey   = "Valid_to_date"
-	)
-	fromTo := make(map[string]time.Time)
-	for _, kv := range bn.AdditionalData.KeyValuePair {
-		k := string(kv.Key)
-		if k == fromKey || k == toKey {
-			if t, err := time.Parse(time.RFC3339, kv.Value); err != nil {
-				return err
-			} else {
-				fromTo[k] = t
+		// This is a workaround for the fact that most BN data does not
+		// contain the optional validity information.
+		//
+		// The current solution makes every change in the data an
+		// update, which might be not the best solution.  Alternative
+		// approaches could include usingthe Date Info of the data as
+		// start date, and maybe even inspecting the details of changed
+		// data for hints wether an update or historisation with a new
+		// version is advisable.
+		//
+		// Never the less, the current solution "just works" for the
+		// rtime being...  --  sw
+		feedback.Warn("No validity information, assuming infinite validity.")
+		tfrom.Set(time.Date(1970, time.January, 1, 0, 0, 0, 0, time.UTC))
+		uBound = pgtype.Unbounded
+	} else {
+		const (
+			fromKey = "Valid_from_date"
+			toKey   = "Valid_to_date"
+		)
+		fromTo := make(map[string]time.Time)
+		for _, kv := range bn.AdditionalData.KeyValuePair {
+			k := string(kv.Key)
+			if k == fromKey || k == toKey {
+				if t, err := time.Parse(time.RFC3339, kv.Value); err != nil {
+					return err
+				} else {
+					fromTo[k] = t
+				}
 			}
 		}
+
+		if t, ok := fromTo[fromKey]; ok {
+			tfrom.Set(t)
+		} else {
+			feedback.Warn("Missing start date")
+			return nil
+		}
+
+		if t, ok := fromTo[toKey]; ok {
+			tto.Set(t)
+			uBound = pgtype.Exclusive
+		} else {
+			uBound = pgtype.Unbounded
+		}
 	}
 
-	var tfrom, tto pgtype.Timestamptz
-	if t, ok := fromTo[fromKey]; ok {
-		tfrom.Set(t)
-	} else {
-		feedback.Warn("Missing start date")
-		return nil
-	}
-	var uBound pgtype.BoundType
-	if t, ok := fromTo[toKey]; ok {
-		tto.Set(t)
-		uBound = pgtype.Exclusive
-	} else {
-		uBound = pgtype.Unbounded
-	}
 	validity := pgtype.Tstzrange{
 		Lower:     tfrom,
 		Upper:     tto,