Mercurial > gemma
annotate pkg/models/sr.go @ 5703:d2ccf6bb6940 sr-v2
Make plane eval for z-values of triangles numerial more robust.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 19 Feb 2024 17:48:13 +0100 |
parents | 1222b777f51f |
children |
rev | line source |
---|---|
1224
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 // without warranty, see README.md and license for details. |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 // |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 // |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 // Copyright (C) 2018 by via donau |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 // Software engineering by Intevation GmbH |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 // |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 // Author(s): |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 // * Bernhard E. Reiter <bernhard.reiter@intevation.de> |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 package models |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 import ( |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 "context" |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 "database/sql" |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 "encoding/json" |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 "errors" |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 "fmt" |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 "io" |
2345
df6383831ad3
Sounding result import: Be more verbose if sounding result already exists for a bottleneck/date.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1900
diff
changeset
|
24 |
df6383831ad3
Sounding result import: Be more verbose if sounding result already exists for a bottleneck/date.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1900
diff
changeset
|
25 "gemma.intevation.de/gemma/pkg/common" |
1224
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 ) |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5585
diff
changeset
|
28 // SurveyType is the type of a survey. |
5403
85f19e924a43
Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4055
diff
changeset
|
29 type SurveyType string |
85f19e924a43
Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4055
diff
changeset
|
30 |
85f19e924a43
Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4055
diff
changeset
|
31 const ( |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5585
diff
changeset
|
32 // SurveyTypeMultiBeam is multi beam scan. |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5585
diff
changeset
|
33 SurveyTypeMultiBeam = SurveyType("multi") |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5585
diff
changeset
|
34 // SurveyTypeSingleBeam is a single beam scan. |
5403
85f19e924a43
Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4055
diff
changeset
|
35 SurveyTypeSingleBeam = SurveyType("single") |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5585
diff
changeset
|
36 // SurveyTypeMarking is a scan from a marking vessel. |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5585
diff
changeset
|
37 SurveyTypeMarking = SurveyType("marking") |
5403
85f19e924a43
Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4055
diff
changeset
|
38 ) |
85f19e924a43
Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4055
diff
changeset
|
39 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5585
diff
changeset
|
40 // SoundingResultMeta is the JSON structure of |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5585
diff
changeset
|
41 // a metadata.json file. |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5585
diff
changeset
|
42 type SoundingResultMeta struct { |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5585
diff
changeset
|
43 Date Date `json:"date"` |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5585
diff
changeset
|
44 Bottleneck string `json:"bottleneck"` |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5585
diff
changeset
|
45 EPSG uint `json:"epsg"` |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5585
diff
changeset
|
46 DepthReference string `json:"depth-reference"` |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5585
diff
changeset
|
47 SingleBeam *bool `json:"single-beam,omitempty"` // kept in for compat! |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5585
diff
changeset
|
48 SurveyType SurveyType `json:"survey-type,omitempty"` |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5585
diff
changeset
|
49 NegateZ bool `json:"negate-z,omitempty"` |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5585
diff
changeset
|
50 } |
1224
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5585
diff
changeset
|
52 // UnmarshalJSON implements the json.Unmarshaler interface. |
5403
85f19e924a43
Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4055
diff
changeset
|
53 func (st *SurveyType) UnmarshalJSON(data []byte) error { |
85f19e924a43
Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4055
diff
changeset
|
54 var s string |
85f19e924a43
Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4055
diff
changeset
|
55 if err := json.Unmarshal(data, &s); err != nil { |
85f19e924a43
Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4055
diff
changeset
|
56 return err |
85f19e924a43
Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4055
diff
changeset
|
57 } |
85f19e924a43
Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4055
diff
changeset
|
58 switch x := SurveyType(s); x { |
85f19e924a43
Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4055
diff
changeset
|
59 case SurveyTypeMultiBeam, SurveyTypeSingleBeam, SurveyTypeMarking: |
85f19e924a43
Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4055
diff
changeset
|
60 *st = x |
85f19e924a43
Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4055
diff
changeset
|
61 return nil |
85f19e924a43
Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4055
diff
changeset
|
62 default: |
85f19e924a43
Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4055
diff
changeset
|
63 return fmt.Errorf("unkown survey type '%s'", s) |
85f19e924a43
Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4055
diff
changeset
|
64 } |
85f19e924a43
Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4055
diff
changeset
|
65 } |
85f19e924a43
Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4055
diff
changeset
|
66 |
1224
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 const ( |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 checkDepthReferenceSQL = ` |
2961
5bc941d9ec43
Fix checking of depth reference for sounding result
Tom Gottfried <tom@intevation.de>
parents:
2345
diff
changeset
|
69 SELECT EXISTS(SELECT 1 |
5bc941d9ec43
Fix checking of depth reference for sounding result
Tom Gottfried <tom@intevation.de>
parents:
2345
diff
changeset
|
70 FROM waterway.bottlenecks bn |
3302
ec6163c6687d
'Historicise' gauges on import
Tom Gottfried <tom@intevation.de>
parents:
2961
diff
changeset
|
71 JOIN waterway.gauges g |
4055
98e2041c7ebf
Adapted sr-import to new historization model.
Sascha Wilde <wilde@intevation.de>
parents:
3945
diff
changeset
|
72 ON bn.gauge_location = g.location AND $3::timestamptz <@ g.validity |
3645
02951a62e8c6
'Historicise' bottlenecks on import
Tom Gottfried <tom@intevation.de>
parents:
3585
diff
changeset
|
73 JOIN waterway.gauges_reference_water_levels rl |
02951a62e8c6
'Historicise' bottlenecks on import
Tom Gottfried <tom@intevation.de>
parents:
3585
diff
changeset
|
74 ON g.location = rl.location AND g.validity = rl.validity |
5585
7e8830c808ba
Fixed SR import for use of Bottleneck_Id instead of bottlenecks objnam.
Sascha Wilde <wilde@sha-bang.de>
parents:
5427
diff
changeset
|
75 WHERE bn.bottleneck_id = $1 |
2961
5bc941d9ec43
Fix checking of depth reference for sounding result
Tom Gottfried <tom@intevation.de>
parents:
2345
diff
changeset
|
76 AND rl.depth_reference = $2)` |
1224
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 checkBottleneckSQL = ` |
5585
7e8830c808ba
Fixed SR import for use of Bottleneck_Id instead of bottlenecks objnam.
Sascha Wilde <wilde@sha-bang.de>
parents:
5427
diff
changeset
|
79 SELECT true FROM waterway.bottlenecks WHERE bottleneck_id = $1` |
1297
1c0c9190fcf2
Import sounding result: If uploading a zip with a meta.json which has
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1224
diff
changeset
|
80 |
1c0c9190fcf2
Import sounding result: If uploading a zip with a meta.json which has
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1224
diff
changeset
|
81 checkBottleneckDateUniqueSQL = ` |
1c0c9190fcf2
Import sounding result: If uploading a zip with a meta.json which has
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1224
diff
changeset
|
82 SELECT true FROM waterway.sounding_results sr JOIN |
3656
2a079d0a71c1
Ensure sounding results are associated to matching bottleneck version
Tom Gottfried <tom@intevation.de>
parents:
3645
diff
changeset
|
83 waterway.bottlenecks bn ON sr.bottleneck_id = bn.bottleneck_id |
5585
7e8830c808ba
Fixed SR import for use of Bottleneck_Id instead of bottlenecks objnam.
Sascha Wilde <wilde@sha-bang.de>
parents:
5427
diff
changeset
|
84 WHERE bn.bottleneck_id = $1 AND sr.date_info = $2` |
1224
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 ) |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5585
diff
changeset
|
87 // Decode deserializes a metadata.json and checks if |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5585
diff
changeset
|
88 // the data fields met the needed constraints. |
1224
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 func (m *SoundingResultMeta) Decode(r io.Reader) error { |
5427
235cfce555b5
Minor clean-up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5407
diff
changeset
|
90 if err := json.NewDecoder(r).Decode(m); err != nil { |
5407
850f5847d18a
Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5403
diff
changeset
|
91 return err |
850f5847d18a
Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5403
diff
changeset
|
92 } |
850f5847d18a
Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5403
diff
changeset
|
93 |
850f5847d18a
Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5403
diff
changeset
|
94 if m.EPSG == 0 { |
1224
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 m.EPSG = WGS84 |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 } |
5407
850f5847d18a
Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5403
diff
changeset
|
97 |
850f5847d18a
Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5403
diff
changeset
|
98 if m.SingleBeam != nil { |
850f5847d18a
Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5403
diff
changeset
|
99 // Check if single-beam and survey-type match. |
850f5847d18a
Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5403
diff
changeset
|
100 if m.SurveyType != "" { |
850f5847d18a
Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5403
diff
changeset
|
101 if (*m.SingleBeam && m.SurveyType != SurveyTypeSingleBeam) || |
850f5847d18a
Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5403
diff
changeset
|
102 (!*m.SingleBeam && m.SurveyType != SurveyTypeMultiBeam) { |
850f5847d18a
Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5403
diff
changeset
|
103 return errors.New("'single-beam' and 'survey-type' mismatch") |
850f5847d18a
Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5403
diff
changeset
|
104 } |
850f5847d18a
Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5403
diff
changeset
|
105 } else { // Only single-beam given |
850f5847d18a
Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5403
diff
changeset
|
106 if *m.SingleBeam { |
850f5847d18a
Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5403
diff
changeset
|
107 m.SurveyType = SurveyTypeSingleBeam |
850f5847d18a
Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5403
diff
changeset
|
108 } else { |
850f5847d18a
Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5403
diff
changeset
|
109 m.SurveyType = SurveyTypeMultiBeam |
850f5847d18a
Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5403
diff
changeset
|
110 } |
850f5847d18a
Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5403
diff
changeset
|
111 } |
850f5847d18a
Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5403
diff
changeset
|
112 // Kill single-beam |
850f5847d18a
Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5403
diff
changeset
|
113 m.SingleBeam = nil |
850f5847d18a
Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5403
diff
changeset
|
114 } |
850f5847d18a
Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5403
diff
changeset
|
115 |
850f5847d18a
Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5403
diff
changeset
|
116 if m.SurveyType == "" { // default to multi-beam |
850f5847d18a
Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5403
diff
changeset
|
117 m.SurveyType = SurveyTypeMultiBeam |
850f5847d18a
Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5403
diff
changeset
|
118 } |
5427
235cfce555b5
Minor clean-up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5407
diff
changeset
|
119 |
235cfce555b5
Minor clean-up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5407
diff
changeset
|
120 return nil |
1224
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
121 } |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
122 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5585
diff
changeset
|
123 // Validate validates the metadata.json data against the |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5585
diff
changeset
|
124 // constraints in the database. |
1328
d753ce6cf588
To make golint happier made context.Context to be the first argument in all calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1297
diff
changeset
|
125 func (m *SoundingResultMeta) Validate(ctx context.Context, conn *sql.Conn) []error { |
1224
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 var errs []error |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
128 |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
129 var b bool |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
130 err := conn.QueryRowContext(ctx, |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
131 checkBottleneckSQL, |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
132 m.Bottleneck).Scan(&b) |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
133 switch { |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
134 case err == sql.ErrNoRows: |
1330
785f14264426
Follow the rules for error messages to make golint happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1328
diff
changeset
|
135 errs = append(errs, fmt.Errorf("unknown bottleneck '%s'", m.Bottleneck)) |
1224
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
136 case err != nil: |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
137 errs = append(errs, err) |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
138 case !b: |
1331
275ead19b9fd
More on following the rules for error messages to make golint happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1330
diff
changeset
|
139 errs = append(errs, errors.New("unexpected bottleneck")) |
1224
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
140 } |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 |
3895
07b2df71bb4a
Allow 'ZPG' as a depth reference system in meta.json files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3656
diff
changeset
|
142 if m.DepthReference != "ZPG" { |
07b2df71bb4a
Allow 'ZPG' as a depth reference system in meta.json files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3656
diff
changeset
|
143 err = conn.QueryRowContext(ctx, |
07b2df71bb4a
Allow 'ZPG' as a depth reference system in meta.json files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3656
diff
changeset
|
144 checkDepthReferenceSQL, |
07b2df71bb4a
Allow 'ZPG' as a depth reference system in meta.json files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3656
diff
changeset
|
145 m.Bottleneck, |
4055
98e2041c7ebf
Adapted sr-import to new historization model.
Sascha Wilde <wilde@intevation.de>
parents:
3945
diff
changeset
|
146 m.DepthReference, |
98e2041c7ebf
Adapted sr-import to new historization model.
Sascha Wilde <wilde@intevation.de>
parents:
3945
diff
changeset
|
147 m.Date.Time).Scan(&b) |
3895
07b2df71bb4a
Allow 'ZPG' as a depth reference system in meta.json files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3656
diff
changeset
|
148 switch { |
07b2df71bb4a
Allow 'ZPG' as a depth reference system in meta.json files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3656
diff
changeset
|
149 case !b: |
07b2df71bb4a
Allow 'ZPG' as a depth reference system in meta.json files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3656
diff
changeset
|
150 errs = append(errs, |
07b2df71bb4a
Allow 'ZPG' as a depth reference system in meta.json files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3656
diff
changeset
|
151 fmt.Errorf("unknown depth reference '%s'", m.DepthReference)) |
07b2df71bb4a
Allow 'ZPG' as a depth reference system in meta.json files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3656
diff
changeset
|
152 case err != nil: |
07b2df71bb4a
Allow 'ZPG' as a depth reference system in meta.json files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3656
diff
changeset
|
153 errs = append(errs, err) |
07b2df71bb4a
Allow 'ZPG' as a depth reference system in meta.json files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3656
diff
changeset
|
154 } |
2961
5bc941d9ec43
Fix checking of depth reference for sounding result
Tom Gottfried <tom@intevation.de>
parents:
2345
diff
changeset
|
155 } |
5bc941d9ec43
Fix checking of depth reference for sounding result
Tom Gottfried <tom@intevation.de>
parents:
2345
diff
changeset
|
156 |
5bc941d9ec43
Fix checking of depth reference for sounding result
Tom Gottfried <tom@intevation.de>
parents:
2345
diff
changeset
|
157 err = conn.QueryRowContext(ctx, |
1297
1c0c9190fcf2
Import sounding result: If uploading a zip with a meta.json which has
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1224
diff
changeset
|
158 checkBottleneckDateUniqueSQL, |
1c0c9190fcf2
Import sounding result: If uploading a zip with a meta.json which has
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1224
diff
changeset
|
159 m.Bottleneck, m.Date.Time).Scan(&b) |
1c0c9190fcf2
Import sounding result: If uploading a zip with a meta.json which has
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1224
diff
changeset
|
160 switch { |
1c0c9190fcf2
Import sounding result: If uploading a zip with a meta.json which has
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1224
diff
changeset
|
161 case err == sql.ErrNoRows: // good! -> unique. |
1c0c9190fcf2
Import sounding result: If uploading a zip with a meta.json which has
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1224
diff
changeset
|
162 case err != nil: |
1c0c9190fcf2
Import sounding result: If uploading a zip with a meta.json which has
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1224
diff
changeset
|
163 errs = append(errs, err) |
1c0c9190fcf2
Import sounding result: If uploading a zip with a meta.json which has
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1224
diff
changeset
|
164 case b: |
1c0c9190fcf2
Import sounding result: If uploading a zip with a meta.json which has
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1224
diff
changeset
|
165 errs = append(errs, |
2345
df6383831ad3
Sounding result import: Be more verbose if sounding result already exists for a bottleneck/date.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1900
diff
changeset
|
166 fmt.Errorf("sounding result for date %s already exists at bottleneck '%s'", |
df6383831ad3
Sounding result import: Be more verbose if sounding result already exists for a bottleneck/date.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1900
diff
changeset
|
167 m.Date.Time.Format(common.DateFormat), |
df6383831ad3
Sounding result import: Be more verbose if sounding result already exists for a bottleneck/date.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1900
diff
changeset
|
168 m.Bottleneck)) |
1297
1c0c9190fcf2
Import sounding result: If uploading a zip with a meta.json which has
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1224
diff
changeset
|
169 } |
1c0c9190fcf2
Import sounding result: If uploading a zip with a meta.json which has
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1224
diff
changeset
|
170 |
1224
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
171 return errs |
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
172 } |