Mercurial > gemma
annotate pkg/imports/gm.go @ 2787:2ce5ee6d65b5
client:translations: merge translations from weblate
author | Fadi Abbud <fadi.abbud@intevation.de> |
---|---|
date | Mon, 25 Mar 2019 10:34:33 +0100 |
parents | 7d784840a9a7 |
children | b8972e4671fa |
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> |
2245
7d784840a9a7
Uploaded gauge measurements: Initial commit. TODO: Add endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2244
diff
changeset
|
13 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
1694
4a2fad8f57de
Imports: Resolved golint issues unrelated to exported symbols commenting.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1688
diff
changeset
|
14 |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
15 package imports |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
16 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
17 import ( |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
18 "context" |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
19 "database/sql" |
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" |
2242
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
21 "sort" |
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
|
22 "strings" |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
23 "time" |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
24 |
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 |
1978
0a8fa6893181
Import: Upsert gauge measurement data to avoid unique contraint violation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1954
diff
changeset
|
53 // TODO: Currently this statement updates existing data sets. In case we want |
0a8fa6893181
Import: Upsert gauge measurement data to avoid unique contraint violation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1954
diff
changeset
|
54 // 'historization' we need to develop an other mechanism to keep existing |
0a8fa6893181
Import: Upsert gauge measurement data to avoid unique contraint violation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1954
diff
changeset
|
55 // data. |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
56 insertGMSQL = ` |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
57 INSERT INTO waterway.gauge_measurements ( |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
58 fk_gauge_id, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
59 measure_date, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
60 sender, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
61 language_code, |
1766
e51db2a365a2
Insert country code in gm import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1761
diff
changeset
|
62 country_code, |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
63 date_issue, |
1775
fcb0106ec510
Gauge measurement import: Added reference_code column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1772
diff
changeset
|
64 reference_code, |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
65 water_level, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
66 predicted, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
67 is_waterlevel, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
68 value_min, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
69 value_max, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
70 date_info, |
1780
48791416bea5
(Approved) gauge measurement import: Fixed row level security.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1776
diff
changeset
|
71 source_organization, |
48791416bea5
(Approved) gauge measurement import: Fixed row level security.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1776
diff
changeset
|
72 staging_done |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
73 ) VALUES( |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
74 ($1, $2, $3, $4, $5), |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
75 $6, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
76 $7, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
77 $8, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
78 $9, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
79 $10, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
80 $11, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
81 $12, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
82 $13, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
83 $14, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
84 $15, |
1766
e51db2a365a2
Insert country code in gm import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1761
diff
changeset
|
85 $16, |
1775
fcb0106ec510
Gauge measurement import: Added reference_code column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1772
diff
changeset
|
86 $17, |
1780
48791416bea5
(Approved) gauge measurement import: Fixed row level security.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1776
diff
changeset
|
87 $18, |
48791416bea5
(Approved) gauge measurement import: Fixed row level security.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1776
diff
changeset
|
88 $19 |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
89 ) |
1978
0a8fa6893181
Import: Upsert gauge measurement data to avoid unique contraint violation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1954
diff
changeset
|
90 ON CONFLICT ON CONSTRAINT gauge_measurements_fk_gauge_id_measure_date_staging_done_key |
0a8fa6893181
Import: Upsert gauge measurement data to avoid unique contraint violation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1954
diff
changeset
|
91 DO UPDATE SET |
0a8fa6893181
Import: Upsert gauge measurement data to avoid unique contraint violation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1954
diff
changeset
|
92 country_code = EXCLUDED.country_code, |
0a8fa6893181
Import: Upsert gauge measurement data to avoid unique contraint violation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1954
diff
changeset
|
93 sender = EXCLUDED.sender, |
0a8fa6893181
Import: Upsert gauge measurement data to avoid unique contraint violation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1954
diff
changeset
|
94 language_code = EXCLUDED.language_code, |
0a8fa6893181
Import: Upsert gauge measurement data to avoid unique contraint violation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1954
diff
changeset
|
95 date_issue = EXCLUDED.date_issue, |
0a8fa6893181
Import: Upsert gauge measurement data to avoid unique contraint violation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1954
diff
changeset
|
96 reference_code= EXCLUDED.reference_code, |
0a8fa6893181
Import: Upsert gauge measurement data to avoid unique contraint violation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1954
diff
changeset
|
97 water_level = EXCLUDED.water_level, |
0a8fa6893181
Import: Upsert gauge measurement data to avoid unique contraint violation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1954
diff
changeset
|
98 predicted = EXCLUDED.predicted, |
0a8fa6893181
Import: Upsert gauge measurement data to avoid unique contraint violation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1954
diff
changeset
|
99 is_waterlevel = EXCLUDED.is_waterlevel, |
0a8fa6893181
Import: Upsert gauge measurement data to avoid unique contraint violation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1954
diff
changeset
|
100 value_min = EXCLUDED.value_min, |
0a8fa6893181
Import: Upsert gauge measurement data to avoid unique contraint violation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1954
diff
changeset
|
101 value_max = EXCLUDED.value_max, |
0a8fa6893181
Import: Upsert gauge measurement data to avoid unique contraint violation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1954
diff
changeset
|
102 date_info = EXCLUDED.date_info, |
0a8fa6893181
Import: Upsert gauge measurement data to avoid unique contraint violation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1954
diff
changeset
|
103 source_organization = EXCLUDED.source_organization |
0a8fa6893181
Import: Upsert gauge measurement data to avoid unique contraint violation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1954
diff
changeset
|
104 RETURNING id |
0a8fa6893181
Import: Upsert gauge measurement data to avoid unique contraint violation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1954
diff
changeset
|
105 ` |
1637
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 type gmJobCreator struct{} |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
109 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
110 func init() { |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
111 RegisterJobCreator(GMJobKind, gmJobCreator{}) |
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 |
2187
7c83b5277c1c
Import queue: Removed boilerplate code to deserialize jobs from JSON by making it part of the import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2168
diff
changeset
|
114 func (gmJobCreator) Description() string { return "gauge measurements" } |
1646
a0982c38eac0
Import queue: Implemented email notifications.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1641
diff
changeset
|
115 |
2187
7c83b5277c1c
Import queue: Removed boilerplate code to deserialize jobs from JSON by making it part of the import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2168
diff
changeset
|
116 func (gmJobCreator) Create() Job { return new(GaugeMeasurement) } |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
117 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
118 func (gmJobCreator) Depends() []string { |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
119 return []string{ |
1664
819f67c31dfb
Imports: Stripped schema prefixes from table dependencies.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1646
diff
changeset
|
120 "gauges", |
819f67c31dfb
Imports: Stripped schema prefixes from table dependencies.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1646
diff
changeset
|
121 "gauge_measurements", |
1637
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 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
124 |
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
|
125 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
|
126 |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
127 // 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
|
128 // Currently doing nothing. |
1676
4407ecaa2192
Imports: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1664
diff
changeset
|
129 func (gmJobCreator) StageDone(context.Context, *sql.Tx, int64) error { |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
130 return nil |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
131 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
132 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
133 // CleanUp of a gauge measurement import is a NOP. |
1676
4407ecaa2192
Imports: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1664
diff
changeset
|
134 func (*GaugeMeasurement) CleanUp() error { return nil } |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
135 |
2242
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
136 // Do executes the actual bottleneck import. |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
137 func (gm *GaugeMeasurement) Do( |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
138 ctx context.Context, |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
139 importID int64, |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
140 conn *sql.Conn, |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
141 feedback Feedback, |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
142 ) (interface{}, error) { |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
143 |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
144 fetch := func() ([]*nts.RIS_Message_Type, error) { |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
145 client := nts.NewINtSMessageService(gm.URL, gm.Insecure, nil) |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
146 |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
147 mt := nts.Message_type_typeWRM |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
148 |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
149 req := &nts.Get_messages_query{ |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
150 Message_type: &mt, |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
151 } |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
152 |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
153 resp, err := client.Get_messages(req) |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
154 if err != nil { |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
155 return nil, err |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
156 } |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
157 |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
158 result := resp.Result_message |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
159 if result == nil { |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
160 for _, e := range resp.Result_error { |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
161 if e != nil { |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
162 feedback.Error("Error code: %s", *e) |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
163 } else { |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
164 feedback.Error("Unknown error") |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
165 } |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
166 } |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
167 } |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
168 return result, nil |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
169 } |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
170 |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
171 return storeGaugeMeasurements( |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
172 ctx, |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
173 importID, |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
174 fetch, |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
175 conn, |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
176 feedback, |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
177 ) |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
178 } |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
179 |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
180 func loadGauges(ctx context.Context, tx *sql.Tx) ([]string, error) { |
2233
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
181 |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
182 rows, err := tx.QueryContext(ctx, listGaugesSQL) |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
183 if err != nil { |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
184 return nil, err |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
185 } |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
186 defer rows.Close() |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
187 |
2242
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
188 var gauges []string |
2233
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
189 |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
190 for rows.Next() { |
2242
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
191 var g models.Isrs |
2233
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
192 if err = rows.Scan( |
2242
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
193 &g.CountryCode, |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
194 &g.LoCode, |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
195 &g.FairwaySection, |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
196 &g.Orc, |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
197 &g.Hectometre, |
2233
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
198 ); err != nil { |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
199 return nil, err |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
200 } |
2242
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
201 gauges = append(gauges, g.String()) |
2233
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
202 } |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
203 |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
204 if err = rows.Err(); err != nil { |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
205 return nil, err |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
206 } |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
207 |
2242
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
208 sort.Strings(gauges) |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
209 |
2233
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
210 return gauges, nil |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
211 } |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
212 |
2242
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
213 func storeGaugeMeasurements( |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
214 ctx context.Context, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
215 importID int64, |
2242
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
216 fetch func() ([]*nts.RIS_Message_Type, error), |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
217 conn *sql.Conn, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
218 feedback Feedback, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
219 ) (interface{}, error) { |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
220 |
2233
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
221 start := time.Now() |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
222 |
2233
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
223 tx, err := conn.BeginTx(ctx, nil) |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
224 if err != nil { |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
225 return nil, err |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
226 } |
2233
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
227 defer tx.Rollback() |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
228 |
2233
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
229 // Get available gauges from database for use as filter in SOAP request |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
230 gauges, err := loadGauges(ctx, tx) |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
231 if err != nil { |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
232 return nil, err |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
233 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
234 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
235 // TODO get date_issue for selected gauges |
2242
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
236 gids, err := doForGM(ctx, gauges, fetch, tx, feedback) |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
237 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
|
238 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
|
239 return nil, err |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
240 } |
2233
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
241 |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
242 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
|
243 feedback.Info("No new gauge measurements found") |
2233
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
244 return nil, UnchangedError("No new gauge measurements found") |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
245 } |
2233
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
246 |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
247 if err = tx.Commit(); err != nil { |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
248 feedback.Info( |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
249 "Importing gauge measurements failed after %s", time.Since(start)) |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
250 return nil, err |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
251 } |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
252 feedback.Info( |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
253 "Importing gauge measurements successfully took %s", time.Since(start)) |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
254 |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
255 // TODO: needs to be filled more useful. |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
256 summary := struct { |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
257 GaugeMeasuremets []string `json:"gaugeMeasurements"` |
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 GaugeMeasuremets: gids, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
260 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
261 return &summary, err |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
262 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
263 |
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
|
264 // 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
|
265 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
|
266 |
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
|
267 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
|
268 |
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
|
269 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
|
270 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
|
271 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
|
272 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
|
273 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
|
274 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
|
275 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
|
276 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
|
277 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
|
278 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
|
279 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
|
280 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
|
281 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
|
282 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
|
283 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
|
284 } |
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 |
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 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
|
287 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
|
288 } |
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
|
289 |
2242
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
290 func doForGM( |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
291 ctx context.Context, |
2242
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
292 gauges []string, |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
293 fetch func() ([]*nts.RIS_Message_Type, error), |
2233
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
294 tx *sql.Tx, |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
295 feedback Feedback, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
296 ) ([]string, error) { |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
297 |
2234
9b2f8e94671e
Gauge measurement import: Moved preparation of insert statement out of gauge iteration loop.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2233
diff
changeset
|
298 insertStmt, err := tx.PrepareContext(ctx, insertGMSQL) |
9b2f8e94671e
Gauge measurement import: Moved preparation of insert statement out of gauge iteration loop.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2233
diff
changeset
|
299 if err != nil { |
9b2f8e94671e
Gauge measurement import: Moved preparation of insert statement out of gauge iteration loop.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2233
diff
changeset
|
300 return nil, err |
9b2f8e94671e
Gauge measurement import: Moved preparation of insert statement out of gauge iteration loop.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2233
diff
changeset
|
301 } |
9b2f8e94671e
Gauge measurement import: Moved preparation of insert statement out of gauge iteration loop.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2233
diff
changeset
|
302 defer insertStmt.Close() |
9b2f8e94671e
Gauge measurement import: Moved preparation of insert statement out of gauge iteration loop.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2233
diff
changeset
|
303 |
2242
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
304 // lookup to see if we have gauges in the database. |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
305 isKnown := func(s string) bool { |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
306 idx := sort.SearchStrings(gauges, s) |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
307 return idx < len(gauges) && gauges[idx] == s |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
308 } |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
309 |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
310 result, err := fetch() |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
311 if err != nil { |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
312 return nil, err |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
313 } |
1981
e89368aec538
Import: Make one request per gauge for gauge measurement data.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1978
diff
changeset
|
314 |
2242
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
315 var gids []string |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
316 for _, msg := range result { |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
317 var gid int64 |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
318 for _, wrm := range msg.Wrm { |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
319 curr := string(*wrm.Geo_object.Id) |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
320 currIsrs, err := models.IsrsFromString(curr) |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
321 if err != nil { |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
322 feedback.Warn("Invalid ISRS code %v", err) |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
323 continue |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
324 } |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
325 feedback.Info("Found measurements for %s", curr) |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
326 if !isKnown(curr) { |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
327 feedback.Warn("Gauge '%s' is not in database.", curr) |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
328 continue |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
329 } |
1981
e89368aec538
Import: Make one request per gauge for gauge measurement data.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1978
diff
changeset
|
330 |
2242
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
331 var referenceCode string |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
332 if wrm.Reference_code == nil { |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
333 feedback.Info("'Reference_code' not specified. Assuming 'ZPG'") |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
334 referenceCode = "ZPG" |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
335 } else { |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
336 referenceCode = string(*wrm.Reference_code) |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
337 } |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
338 for _, measure := range wrm.Measure { |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
339 var unit string |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
340 if measure.Unit == nil { |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
341 feedback.Info("'Unit' not specified. Assuming 'cm'") |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
342 unit = "cm" |
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
|
343 } else { |
2242
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
344 unit = string(*measure.Unit) |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
345 } |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
346 convert, err := rescale(unit) |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
347 if err != nil { |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
348 return nil, err |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
349 } |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
350 isWaterlevel := *measure.Measure_code == nts.Measure_code_enumWAL |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
351 err = insertStmt.QueryRowContext( |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
352 ctx, |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
353 currIsrs.CountryCode, |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
354 currIsrs.LoCode, |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
355 currIsrs.FairwaySection, |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
356 currIsrs.Orc, |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
357 currIsrs.Hectometre, |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
358 measure.Measuredate, |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
359 msg.Identification.From, |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
360 msg.Identification.Language_code, |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
361 msg.Identification.Country_code, |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
362 msg.Identification.Date_issue, |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
363 referenceCode, |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
364 convert(measure.Value), |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
365 measure.Predicted, |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
366 isWaterlevel, |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
367 convert(measure.Value_min), |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
368 convert(measure.Value_max), |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
369 msg.Identification.Date_issue, |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
370 msg.Identification.Originator, |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
371 true, // staging_done |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
372 ).Scan(&gid) |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
373 if err != nil { |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
374 return nil, err |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
375 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
376 } |
2242
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
377 feedback.Info("Inserted %d measurements for %s", |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
378 len(wrm.Measure), curr) |
786c3fb7efe1
Gauge measurements import: Re-factored to be re-usable for upcoming uploaded gauge measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2238
diff
changeset
|
379 gids = append(gids, curr) |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
380 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
381 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
382 return gids, nil |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
383 } |