Mercurial > gemma
annotate pkg/imports/gm.go @ 1879:9a2fbeaabd52 dev-pdf-generation
merging in from branch default
author | Bernhard Reiter <bernhard@intevation.de> |
---|---|
date | Tue, 15 Jan 2019 10:07:10 +0100 |
parents | 48791416bea5 |
children | 15af36e41f27 |
rev | line source |
---|---|
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
2 // without warranty, see README.md and license for details. |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
3 // |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
6 // |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
7 // Copyright (C) 2018 by via donau |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
9 // Software engineering by Intevation GmbH |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
10 // |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
11 // Author(s): |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
12 // * Raimund Renkert <raimund.renkert@intevation.de> |
1694
4a2fad8f57de
Imports: Resolved golint issues unrelated to exported symbols commenting.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1688
diff
changeset
|
13 |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
14 package imports |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
15 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
16 import ( |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
17 "context" |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
18 "database/sql" |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
19 "errors" |
1772
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
20 "fmt" |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
21 "strings" |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
22 "time" |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
23 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
24 "gemma.intevation.de/gemma/pkg/common" |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
25 "gemma.intevation.de/gemma/pkg/models" |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
26 "gemma.intevation.de/gemma/pkg/soap/nts" |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
27 ) |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
28 |
1696
ad5e1cddaa09
Imports: Resolved the remaining golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1694
diff
changeset
|
29 // GaugeMeasurement is an import job to import |
ad5e1cddaa09
Imports: Resolved the remaining golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1694
diff
changeset
|
30 // gauges measurement data from a NtS SOAP service. |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
31 type GaugeMeasurement struct { |
1696
ad5e1cddaa09
Imports: Resolved the remaining golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1694
diff
changeset
|
32 // URL is the URL of the SOAP service. |
ad5e1cddaa09
Imports: Resolved the remaining golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1694
diff
changeset
|
33 URL string `json:"url"` |
ad5e1cddaa09
Imports: Resolved the remaining golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1694
diff
changeset
|
34 // Insecure indicates if HTTPS traffic |
ad5e1cddaa09
Imports: Resolved the remaining golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1694
diff
changeset
|
35 // should validate certificates or not. |
ad5e1cddaa09
Imports: Resolved the remaining golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1694
diff
changeset
|
36 Insecure bool `json:"insecure"` |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
37 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
38 |
1696
ad5e1cddaa09
Imports: Resolved the remaining golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1694
diff
changeset
|
39 // GMJobKind is the import queue type identifier. |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
40 const GMJobKind JobKind = "gm" |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
41 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
42 const ( |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
43 listGaugesSQL = ` |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
44 SELECT |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
45 (location).country_code, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
46 (location).locode, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
47 (location).fairway_section, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
48 (location).orc, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
49 (location).hectometre |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
50 FROM waterway.gauges |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
51 WHERE (location).country_code = users.current_user_country()` |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
52 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
53 insertGMSQL = ` |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
54 INSERT INTO waterway.gauge_measurements ( |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
55 fk_gauge_id, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
56 measure_date, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
57 sender, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
58 language_code, |
1766
e51db2a365a2
Insert country code in gm import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1761
diff
changeset
|
59 country_code, |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
60 date_issue, |
1775
fcb0106ec510
Gauge measurement import: Added reference_code column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1772
diff
changeset
|
61 reference_code, |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
62 water_level, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
63 predicted, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
64 is_waterlevel, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
65 value_min, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
66 value_max, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
67 date_info, |
1780
48791416bea5
(Approved) gauge measurement import: Fixed row level security.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1776
diff
changeset
|
68 source_organization, |
48791416bea5
(Approved) gauge measurement import: Fixed row level security.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1776
diff
changeset
|
69 staging_done |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
70 ) VALUES( |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
71 ($1, $2, $3, $4, $5), |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
72 $6, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
73 $7, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
74 $8, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
75 $9, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
76 $10, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
77 $11, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
78 $12, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
79 $13, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
80 $14, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
81 $15, |
1766
e51db2a365a2
Insert country code in gm import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1761
diff
changeset
|
82 $16, |
1775
fcb0106ec510
Gauge measurement import: Added reference_code column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1772
diff
changeset
|
83 $17, |
1780
48791416bea5
(Approved) gauge measurement import: Fixed row level security.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1776
diff
changeset
|
84 $18, |
48791416bea5
(Approved) gauge measurement import: Fixed row level security.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1776
diff
changeset
|
85 $19 |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
86 ) |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
87 RETURNING id` |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
88 ) |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
89 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
90 type gmJobCreator struct{} |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
91 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
92 func init() { |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
93 RegisterJobCreator(GMJobKind, gmJobCreator{}) |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
94 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
95 |
1646
a0982c38eac0
Import queue: Implemented email notifications.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1641
diff
changeset
|
96 func (gmJobCreator) Description() string { |
a0982c38eac0
Import queue: Implemented email notifications.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1641
diff
changeset
|
97 return "gauge measurements" |
a0982c38eac0
Import queue: Implemented email notifications.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1641
diff
changeset
|
98 } |
a0982c38eac0
Import queue: Implemented email notifications.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1641
diff
changeset
|
99 |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
100 func (gmJobCreator) Create(_ JobKind, data string) (Job, error) { |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
101 gm := new(GaugeMeasurement) |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
102 if err := common.FromJSONString(data, gm); err != nil { |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
103 return nil, err |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
104 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
105 return gm, nil |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
106 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
107 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
108 func (gmJobCreator) Depends() []string { |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
109 return []string{ |
1664
819f67c31dfb
Imports: Stripped schema prefixes from table dependencies.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1646
diff
changeset
|
110 "gauges", |
819f67c31dfb
Imports: Stripped schema prefixes from table dependencies.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1646
diff
changeset
|
111 "gauge_measurements", |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
112 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
113 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
114 |
1754
807569b08513
Import queue: Auto acceptance is now a property of the import kind itself and is not configurable any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1696
diff
changeset
|
115 func (gmJobCreator) AutoAccept() bool { return true } |
807569b08513
Import queue: Auto acceptance is now a property of the import kind itself and is not configurable any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1696
diff
changeset
|
116 |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
117 // StageDone moves the imported gauge measurement out of the staging area. |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
118 // Currently doing nothing. |
1676
4407ecaa2192
Imports: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1664
diff
changeset
|
119 func (gmJobCreator) StageDone(context.Context, *sql.Tx, int64) error { |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
120 return nil |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
121 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
122 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
123 // CleanUp of a gauge measurement import is a NOP. |
1676
4407ecaa2192
Imports: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1664
diff
changeset
|
124 func (*GaugeMeasurement) CleanUp() error { return nil } |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
125 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
126 // Do executes the actual bottleneck import. |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
127 func (gm *GaugeMeasurement) Do( |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
128 ctx context.Context, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
129 importID int64, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
130 conn *sql.Conn, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
131 feedback Feedback, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
132 ) (interface{}, error) { |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
133 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
134 // Get available gauges from database for use as filter in SOAP request |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
135 var rows *sql.Rows |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
136 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
137 rows, err := conn.QueryContext(ctx, listGaugesSQL) |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
138 if err != nil { |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
139 return nil, err |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
140 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
141 defer rows.Close() |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
142 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
143 gauges := []models.GaugeMeasurement{} |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
144 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
145 for rows.Next() { |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
146 var g models.GaugeMeasurement |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
147 if err = rows.Scan( |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
148 &g.Gauge.CountryCode, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
149 &g.Gauge.LoCode, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
150 &g.Gauge.FairwaySection, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
151 &g.Gauge.Orc, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
152 &g.Gauge.Hectometre, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
153 ); err != nil { |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
154 return nil, err |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
155 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
156 gauges = append(gauges, g) |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
157 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
158 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
159 if err = rows.Err(); err != nil { |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
160 return nil, err |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
161 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
162 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
163 // TODO get date_issue for selected gauges |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
164 gids, err := gm.doForGM(ctx, gauges, conn, feedback) |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
165 if err != nil { |
1761
0145537d5474
Gauge measument import: Die with an error if something went wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1754
diff
changeset
|
166 feedback.Error("Error processing %d gauges: %v", len(gauges), err) |
0145537d5474
Gauge measument import: Die with an error if something went wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1754
diff
changeset
|
167 return nil, err |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
168 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
169 if len(gids) == 0 { |
1638
2a35bbbb4d93
No new measurement are not an error. Fixed typos.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1637
diff
changeset
|
170 feedback.Info("No new gauge measurements found") |
2a35bbbb4d93
No new measurement are not an error. Fixed typos.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1637
diff
changeset
|
171 return nil, nil |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
172 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
173 // TODO: needs to be filled more useful. |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
174 summary := struct { |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
175 GaugeMeasuremets []string `json:"gaugeMeasurements"` |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
176 }{ |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
177 GaugeMeasuremets: gids, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
178 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
179 return &summary, err |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
180 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
181 |
1772
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
182 // rescale returns a scaling function to bring the unit all to cm. |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
183 func rescale(unit string) (func(float32) float32, error) { |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
184 |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
185 var scale float32 |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
186 |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
187 switch strings.ToLower(unit) { |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
188 case "mm": |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
189 scale = 0.1 |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
190 case "cm": |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
191 scale = 1.0 |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
192 case "dm": |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
193 scale = 10.0 |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
194 case "m": |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
195 scale = 100.0 |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
196 case "hm": |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
197 scale = 10000.0 |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
198 case "km": |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
199 scale = 100000.0 |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
200 default: |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
201 return nil, fmt.Errorf("unknown unit '%s'", unit) |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
202 } |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
203 |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
204 fn := func(x float32) float32 { return scale * x } |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
205 return fn, nil |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
206 } |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
207 |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
208 func (gm *GaugeMeasurement) doForGM( |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
209 ctx context.Context, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
210 gauges []models.GaugeMeasurement, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
211 conn *sql.Conn, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
212 feedback Feedback, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
213 ) ([]string, error) { |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
214 start := time.Now() |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
215 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
216 client := nts.NewINtSMessageService(gm.URL, gm.Insecure, nil) |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
217 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
218 var idPairs []*nts.Id_pair |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
219 for _, g := range gauges { |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
220 isrs := g.Gauge.String() |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
221 isrsID := nts.Isrs_code_type(isrs) |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
222 idPairs = append(idPairs, &nts.Id_pair{ |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
223 Id: &isrsID, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
224 }) |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
225 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
226 mt := nts.Message_type_typeWRM |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
227 req := &nts.Get_messages_query{ |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
228 Message_type: &mt, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
229 Ids: idPairs, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
230 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
231 resp, err := client.Get_messages(req) |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
232 if err != nil { |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
233 feedback.Error("%v", err) |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
234 return nil, err |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
235 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
236 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
237 if resp.Result_message == nil { |
1641
334d13e63342
Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1638
diff
changeset
|
238 err := errors.New("no gauge measurements found") |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
239 for i, e := range resp.Result_error { |
1641
334d13e63342
Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1638
diff
changeset
|
240 feedback.Error("%d: %v", i, e) |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
241 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
242 return nil, err |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
243 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
244 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
245 result := resp.Result_message |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
246 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
247 tx, err := conn.BeginTx(ctx, nil) |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
248 if err != nil { |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
249 return nil, err |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
250 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
251 defer tx.Rollback() |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
252 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
253 insertStmt, err := tx.PrepareContext(ctx, insertGMSQL) |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
254 if err != nil { |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
255 return nil, err |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
256 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
257 defer insertStmt.Close() |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
258 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
259 var gid int64 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
260 var gids []string |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
261 for _, msg := range result { |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
262 feedback.Info("Found %d gauges with measurements", len(msg.Wrm)) |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
263 for _, wrm := range msg.Wrm { |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
264 currIsrs, err := models.IsrsFromString(string(*wrm.Geo_object.Id)) |
1641
334d13e63342
Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1638
diff
changeset
|
265 if err != nil { |
334d13e63342
Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1638
diff
changeset
|
266 feedback.Warn("Invalid ISRS code %v", err) |
334d13e63342
Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1638
diff
changeset
|
267 continue |
334d13e63342
Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1638
diff
changeset
|
268 } |
1775
fcb0106ec510
Gauge measurement import: Added reference_code column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1772
diff
changeset
|
269 var referenceCode string |
fcb0106ec510
Gauge measurement import: Added reference_code column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1772
diff
changeset
|
270 if wrm.Reference_code == nil { |
fcb0106ec510
Gauge measurement import: Added reference_code column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1772
diff
changeset
|
271 feedback.Info("'Reference_code' not specified. Assuming 'ZPG'") |
fcb0106ec510
Gauge measurement import: Added reference_code column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1772
diff
changeset
|
272 referenceCode = "ZPG" |
fcb0106ec510
Gauge measurement import: Added reference_code column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1772
diff
changeset
|
273 } else { |
1776
6a902363b435
Fixed type typo.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1775
diff
changeset
|
274 referenceCode = string(*wrm.Reference_code) |
1775
fcb0106ec510
Gauge measurement import: Added reference_code column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1772
diff
changeset
|
275 } |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
276 for _, measure := range wrm.Measure { |
1772
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
277 var unit string |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
278 if measure.Unit == nil { |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
279 feedback.Info("'Unit' not specified. Assuming 'cm'") |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
280 unit = "cm" |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
281 } else { |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
282 unit = string(*measure.Unit) |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
283 } |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
284 convert, err := rescale(unit) |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
285 if err != nil { |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
286 return nil, err |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
287 } |
1641
334d13e63342
Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1638
diff
changeset
|
288 isWaterlevel := *measure.Measure_code == nts.Measure_code_enumWAL |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
289 err = insertStmt.QueryRowContext( |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
290 ctx, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
291 currIsrs.CountryCode, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
292 currIsrs.LoCode, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
293 currIsrs.FairwaySection, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
294 currIsrs.Orc, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
295 currIsrs.Hectometre, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
296 measure.Measuredate, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
297 msg.Identification.From, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
298 msg.Identification.Language_code, |
1766
e51db2a365a2
Insert country code in gm import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1761
diff
changeset
|
299 msg.Identification.Country_code, |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
300 msg.Identification.Date_issue, |
1775
fcb0106ec510
Gauge measurement import: Added reference_code column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1772
diff
changeset
|
301 referenceCode, |
1772
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
302 convert(measure.Value), |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
303 measure.Predicted, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
304 isWaterlevel, |
1772
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
305 convert(measure.Value_min), |
70c4dc694d61
Gauge measurement import: Added a rescale function that brings all numerical values into cm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1766
diff
changeset
|
306 convert(measure.Value_max), |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
307 msg.Identification.Date_issue, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
308 msg.Identification.Originator, |
1780
48791416bea5
(Approved) gauge measurement import: Fixed row level security.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1776
diff
changeset
|
309 true, // staging_done |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
310 ).Scan(&gid) |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
311 if err != nil { |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
312 return nil, err |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
313 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
314 } |
1641
334d13e63342
Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1638
diff
changeset
|
315 feedback.Info("Inserted %d measurements for %s", |
334d13e63342
Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1638
diff
changeset
|
316 len(wrm.Measure), currIsrs) |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
317 gids = append(gids, currIsrs.String()) |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
318 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
319 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
320 feedback.Info("Storing gauge measurements took %s", time.Since(start)) |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
321 if err = tx.Commit(); err == nil { |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
322 feedback.Info("Import of gauge measurements was successful") |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
323 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
324 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
325 return gids, nil |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
326 } |