Mercurial > gemma
changeset 3264:9ae43313b463
Handle some possibly missing elements in NtS response
The NtS XSD does not guarantee that value, value_min and value_max
are present in a response. This led to circumventing the NOT NULL
constraint for the waterlevel value by silently persisting missing
values as zero and filling up missing confidence interval values
especially for measurements with zeros.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Wed, 15 May 2019 12:31:57 +0200 |
parents | d23532a4d0c3 |
children | f92f7c9df392 |
files | pkg/imports/gm.go pkg/soap/nts/service.go |
diffstat | 2 files changed, 16 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/pkg/imports/gm.go Wed May 15 12:04:14 2019 +0200 +++ b/pkg/imports/gm.go Wed May 15 12:31:57 2019 +0200 @@ -188,7 +188,7 @@ } // rescale returns a scaling function to bring the unit all to cm. -func rescale(unit string) (func(float32) float32, error) { +func rescale(unit string) (func(*float32), error) { var scale float32 @@ -209,7 +209,11 @@ return nil, fmt.Errorf("unknown unit '%s'", unit) } - fn := func(x float32) float32 { return scale * x } + fn := func(x *float32) { + if x != nil { + *x = scale * *x + } + } return fn, nil } @@ -264,6 +268,10 @@ if err != nil { return nil, err } + convert(measure.Value) + convert(measure.Value_min) + convert(measure.Value_max) + isWaterlevel := *measure.Measure_code == nts.Measure_code_enumWAL err = insertStmt.QueryRowContext( ctx, @@ -278,11 +286,11 @@ msg.Identification.Country_code, msg.Identification.Date_issue, referenceCode, - convert(measure.Value), + measure.Value, measure.Predicted, isWaterlevel, - convert(measure.Value_min), - convert(measure.Value_max), + measure.Value_min, + measure.Value_max, msg.Identification.Date_issue, msg.Identification.Originator, true, // staging_done
--- a/pkg/soap/nts/service.go Wed May 15 12:04:14 2019 +0200 +++ b/pkg/soap/nts/service.go Wed May 15 12:31:57 2019 +0200 @@ -1273,13 +1273,13 @@ Measure_code *Measure_code_enum `xml:"measure_code,omitempty"` // Measured or predicted value - Value float32 `xml:"value,omitempty"` + Value *float32 `xml:"value,omitempty"` // Lowest value of confidence interval - Value_min float32 `xml:"value_min,omitempty"` + Value_min *float32 `xml:"value_min,omitempty"` // Highest value of confidence interval - Value_max float32 `xml:"value_max,omitempty"` + Value_max *float32 `xml:"value_max,omitempty"` // Unit of the water related value Unit *Unit_enum `xml:"unit,omitempty"`