Mercurial > gemma
annotate pkg/imports/gm.go @ 3334:8c96b7379aea
client: fairway availability: made store action work with both types of feature objects
author | Markus Kottlaender <markus@intevation.de> |
---|---|
date | Mon, 20 May 2019 17:14:47 +0200 |
parents | ec6163c6687d |
children | 8e083b271fca |
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 // |
3176
1cb6676d1510
Handle failing INSERTs gracefully during gauge measurements import
Tom Gottfried <tom@intevation.de>
parents:
2849
diff
changeset
|
7 // Copyright (C) 2018, 2019 by via donau |
1637
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> |
3176
1cb6676d1510
Handle failing INSERTs gracefully during gauge measurements import
Tom Gottfried <tom@intevation.de>
parents:
2849
diff
changeset
|
14 // * Tom Gottfried <tom.gottfried@intevation.de> |
1694
4a2fad8f57de
Imports: Resolved golint issues unrelated to exported symbols commenting.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1688
diff
changeset
|
15 |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
16 package imports |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
17 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
18 import ( |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
19 "context" |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
20 "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
|
21 "fmt" |
3301
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
22 "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
|
23 "strings" |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
24 "time" |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
25 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
26 "gemma.intevation.de/gemma/pkg/models" |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
27 "gemma.intevation.de/gemma/pkg/soap/nts" |
3277
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
28 "github.com/jackc/pgx/pgtype" |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
29 ) |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
30 |
1696
ad5e1cddaa09
Imports: Resolved the remaining golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1694
diff
changeset
|
31 // 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
|
32 // gauges measurement data from a NtS SOAP service. |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
33 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
|
34 // 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
|
35 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
|
36 // 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
|
37 // 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
|
38 Insecure bool `json:"insecure"` |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
39 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
40 |
1696
ad5e1cddaa09
Imports: Resolved the remaining golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1694
diff
changeset
|
41 // GMJobKind is the import queue type identifier. |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
42 const GMJobKind JobKind = "gm" |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
43 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
44 const ( |
3301
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
45 listGaugesSQL = ` |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
46 SELECT |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
47 (location).country_code, |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
48 (location).locode, |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
49 (location).fairway_section, |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
50 (location).orc, |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
51 (location).hectometre |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
52 FROM waterway.gauges |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
53 WHERE (location).country_code = users.current_user_country() |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
54 OR pg_has_role('sys_admin', 'MEMBER') |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
55 ` |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
56 |
2849
b8972e4671fa
Preserve old predictions on raw gauge measurement import.
Sascha Wilde <wilde@intevation.de>
parents:
2245
diff
changeset
|
57 // Note: we do not expect corrections of data through this service. So |
3302
ec6163c6687d
'Historicise' gauges on import
Tom Gottfried <tom@intevation.de>
parents:
3301
diff
changeset
|
58 // any constraint conflicts are triggered by redundant data which |
2849
b8972e4671fa
Preserve old predictions on raw gauge measurement import.
Sascha Wilde <wilde@intevation.de>
parents:
2245
diff
changeset
|
59 // can be dropped. |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
60 insertGMSQL = ` |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
61 INSERT INTO waterway.gauge_measurements ( |
3302
ec6163c6687d
'Historicise' gauges on import
Tom Gottfried <tom@intevation.de>
parents:
3301
diff
changeset
|
62 location, |
ec6163c6687d
'Historicise' gauges on import
Tom Gottfried <tom@intevation.de>
parents:
3301
diff
changeset
|
63 validity, |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
64 measure_date, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
65 sender, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
66 language_code, |
1766
e51db2a365a2
Insert country code in gm import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1761
diff
changeset
|
67 country_code, |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
68 date_issue, |
1775
fcb0106ec510
Gauge measurement import: Added reference_code column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1772
diff
changeset
|
69 reference_code, |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
70 water_level, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
71 date_info, |
1780
48791416bea5
(Approved) gauge measurement import: Fixed row level security.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1776
diff
changeset
|
72 source_organization, |
48791416bea5
(Approved) gauge measurement import: Fixed row level security.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1776
diff
changeset
|
73 staging_done |
3302
ec6163c6687d
'Historicise' gauges on import
Tom Gottfried <tom@intevation.de>
parents:
3301
diff
changeset
|
74 ) VALUES ( |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
75 ($1, $2, $3, $4, $5), |
3302
ec6163c6687d
'Historicise' gauges on import
Tom Gottfried <tom@intevation.de>
parents:
3301
diff
changeset
|
76 (SELECT validity FROM waterway.gauges |
ec6163c6687d
'Historicise' gauges on import
Tom Gottfried <tom@intevation.de>
parents:
3301
diff
changeset
|
77 WHERE location |
ec6163c6687d
'Historicise' gauges on import
Tom Gottfried <tom@intevation.de>
parents:
3301
diff
changeset
|
78 = ($1::char(2), $2::char(3), $3::char(5), $4::char(5), $5::int) |
ec6163c6687d
'Historicise' gauges on import
Tom Gottfried <tom@intevation.de>
parents:
3301
diff
changeset
|
79 AND validity @> CAST($6 AS timestamp with time zone)), |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
80 $6, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
81 $7, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
82 $8, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
83 $9, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
84 $10, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
85 $11, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
86 $12, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
87 $13, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
88 $14, |
3277
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
89 true |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
90 ) |
2849
b8972e4671fa
Preserve old predictions on raw gauge measurement import.
Sascha Wilde <wilde@intevation.de>
parents:
2245
diff
changeset
|
91 ON CONFLICT DO NOTHING |
3277
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
92 RETURNING 1 |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
93 ` |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
94 |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
95 insertGPSQL = ` |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
96 INSERT INTO waterway.gauge_predictions ( |
3302
ec6163c6687d
'Historicise' gauges on import
Tom Gottfried <tom@intevation.de>
parents:
3301
diff
changeset
|
97 location, |
ec6163c6687d
'Historicise' gauges on import
Tom Gottfried <tom@intevation.de>
parents:
3301
diff
changeset
|
98 validity, |
3277
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
99 measure_date, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
100 sender, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
101 language_code, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
102 country_code, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
103 date_issue, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
104 reference_code, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
105 water_level, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
106 conf_interval, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
107 date_info, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
108 source_organization |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
109 ) VALUES( |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
110 ($1, $2, $3, $4, $5), |
3302
ec6163c6687d
'Historicise' gauges on import
Tom Gottfried <tom@intevation.de>
parents:
3301
diff
changeset
|
111 (SELECT validity FROM waterway.gauges |
ec6163c6687d
'Historicise' gauges on import
Tom Gottfried <tom@intevation.de>
parents:
3301
diff
changeset
|
112 WHERE location |
ec6163c6687d
'Historicise' gauges on import
Tom Gottfried <tom@intevation.de>
parents:
3301
diff
changeset
|
113 = ($1::char(2), $2::char(3), $3::char(5), $4::char(5), $5::int) |
ec6163c6687d
'Historicise' gauges on import
Tom Gottfried <tom@intevation.de>
parents:
3301
diff
changeset
|
114 AND validity @> CAST($6 AS timestamp with time zone)), |
3277
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
115 $6, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
116 $7, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
117 $8, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
118 $9, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
119 $10, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
120 $11, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
121 $12, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
122 $13, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
123 $14, |
3278
831193935739
Avoid storing of NtS messages other than water level
Tom Gottfried <tom@intevation.de>
parents:
3277
diff
changeset
|
124 $15 |
3277
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
125 ) |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
126 ON CONFLICT DO NOTHING |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
127 RETURNING 1 |
1978
0a8fa6893181
Import: Upsert gauge measurement data to avoid unique contraint violation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1954
diff
changeset
|
128 ` |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
129 ) |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
130 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
131 type gmJobCreator struct{} |
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 func init() { |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
134 RegisterJobCreator(GMJobKind, gmJobCreator{}) |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
135 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
136 |
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
|
137 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
|
138 |
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
|
139 func (gmJobCreator) Create() Job { return new(GaugeMeasurement) } |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
140 |
3219
4acbee65275d
Import queue: Split locked dependencies in exclusively and multiple uses.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3176
diff
changeset
|
141 func (gmJobCreator) Depends() [2][]string { |
4acbee65275d
Import queue: Split locked dependencies in exclusively and multiple uses.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3176
diff
changeset
|
142 return [2][]string{ |
4acbee65275d
Import queue: Split locked dependencies in exclusively and multiple uses.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3176
diff
changeset
|
143 {"gauge_measurements"}, |
4acbee65275d
Import queue: Split locked dependencies in exclusively and multiple uses.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3176
diff
changeset
|
144 {"gauges"}, |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
145 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
146 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
147 |
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
|
148 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
|
149 |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
150 // 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
|
151 // Currently doing nothing. |
1676
4407ecaa2192
Imports: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1664
diff
changeset
|
152 func (gmJobCreator) StageDone(context.Context, *sql.Tx, int64) error { |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
153 return nil |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
154 } |
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 // CleanUp of a gauge measurement import is a NOP. |
1676
4407ecaa2192
Imports: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1664
diff
changeset
|
157 func (*GaugeMeasurement) CleanUp() error { return nil } |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
158 |
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
|
159 // 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
|
160 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
|
161 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
|
162 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
|
163 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
|
164 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
|
165 ) (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
|
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 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
|
168 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
|
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 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
|
171 |
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 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
|
173 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
|
174 } |
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 |
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 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
|
177 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
|
178 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
|
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 |
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
|
181 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
|
182 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
|
183 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
|
184 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
|
185 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
|
186 } 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
|
187 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
|
188 } |
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
|
189 } |
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
|
190 } |
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 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
|
192 } |
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 |
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 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
|
195 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
|
196 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
|
197 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
|
198 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
|
199 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
|
200 ) |
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 } |
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
|
202 |
3301
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
203 func loadGauges(ctx context.Context, conn *sql.Conn) ([]string, error) { |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
204 |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
205 rows, err := conn.QueryContext(ctx, listGaugesSQL) |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
206 if err != nil { |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
207 return nil, err |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
208 } |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
209 defer rows.Close() |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
210 |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
211 var gauges []string |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
212 |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
213 for rows.Next() { |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
214 var g models.Isrs |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
215 if err = rows.Scan( |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
216 &g.CountryCode, |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
217 &g.LoCode, |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
218 &g.FairwaySection, |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
219 &g.Orc, |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
220 &g.Hectometre, |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
221 ); err != nil { |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
222 return nil, err |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
223 } |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
224 gauges = append(gauges, g.String()) |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
225 } |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
226 |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
227 if err = rows.Err(); err != nil { |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
228 return nil, err |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
229 } |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
230 |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
231 if len(gauges) == 0 { |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
232 return nil, UnchangedError( |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
233 "No gauges for which measurements can be imported in database") |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
234 } |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
235 |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
236 sort.Strings(gauges) |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
237 |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
238 return gauges, nil |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
239 } |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
240 |
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
|
241 func storeGaugeMeasurements( |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
242 ctx context.Context, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
243 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
|
244 fetch func() ([]*nts.RIS_Message_Type, error), |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
245 conn *sql.Conn, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
246 feedback Feedback, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
247 ) (interface{}, error) { |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
248 |
2233
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
249 start := time.Now() |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
250 |
3301
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
251 // Get gauges from database, for which user is allowed to import data |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
252 gauges, err := loadGauges(ctx, conn) |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
253 if err != nil { |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
254 return nil, err |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
255 } |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
256 |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
257 gids, err := doForGM(ctx, gauges, fetch, conn, feedback) |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
258 if err != nil { |
3176
1cb6676d1510
Handle failing INSERTs gracefully during gauge measurements import
Tom Gottfried <tom@intevation.de>
parents:
2849
diff
changeset
|
259 feedback.Error("Error processing gauges: %v", err) |
1761
0145537d5474
Gauge measument import: Die with an error if something went wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1754
diff
changeset
|
260 return nil, err |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
261 } |
2233
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
262 |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
263 if len(gids) == 0 { |
2233
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
264 return nil, UnchangedError("No new gauge measurements found") |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
265 } |
2233
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
266 |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
267 feedback.Info( |
3176
1cb6676d1510
Handle failing INSERTs gracefully during gauge measurements import
Tom Gottfried <tom@intevation.de>
parents:
2849
diff
changeset
|
268 "Importing gauge measurements took %s", time.Since(start)) |
2233
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
269 |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
270 // TODO: needs to be filled more useful. |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
271 summary := struct { |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
272 GaugeMeasuremets []string `json:"gaugeMeasurements"` |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
273 }{ |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
274 GaugeMeasuremets: gids, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
275 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
276 return &summary, err |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
277 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
278 |
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
|
279 // rescale returns a scaling function to bring the unit all to cm. |
3264
9ae43313b463
Handle some possibly missing elements in NtS response
Tom Gottfried <tom@intevation.de>
parents:
3219
diff
changeset
|
280 func rescale(unit string) (func(*float32), error) { |
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
|
281 |
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 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
|
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 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
|
285 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
|
286 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
|
287 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
|
288 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
|
289 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
|
290 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
|
291 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
|
292 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
|
293 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
|
294 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
|
295 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
|
296 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
|
297 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
|
298 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
|
299 } |
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
|
300 |
3264
9ae43313b463
Handle some possibly missing elements in NtS response
Tom Gottfried <tom@intevation.de>
parents:
3219
diff
changeset
|
301 fn := func(x *float32) { |
9ae43313b463
Handle some possibly missing elements in NtS response
Tom Gottfried <tom@intevation.de>
parents:
3219
diff
changeset
|
302 if x != nil { |
3266
3dee5cf16a58
Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3264
diff
changeset
|
303 *x *= scale |
3264
9ae43313b463
Handle some possibly missing elements in NtS response
Tom Gottfried <tom@intevation.de>
parents:
3219
diff
changeset
|
304 } |
9ae43313b463
Handle some possibly missing elements in NtS response
Tom Gottfried <tom@intevation.de>
parents:
3219
diff
changeset
|
305 } |
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
|
306 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
|
307 } |
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
|
308 |
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
|
309 func doForGM( |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
310 ctx context.Context, |
3301
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
311 gauges []string, |
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
|
312 fetch func() ([]*nts.RIS_Message_Type, error), |
3176
1cb6676d1510
Handle failing INSERTs gracefully during gauge measurements import
Tom Gottfried <tom@intevation.de>
parents:
2849
diff
changeset
|
313 conn *sql.Conn, |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
314 feedback Feedback, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
315 ) ([]string, error) { |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
316 |
3277
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
317 insertGPStmt, err := conn.PrepareContext(ctx, insertGPSQL) |
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
|
318 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
|
319 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
|
320 } |
3277
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
321 defer insertGPStmt.Close() |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
322 |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
323 insertGMStmt, err := conn.PrepareContext(ctx, insertGMSQL) |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
324 if err != nil { |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
325 return nil, err |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
326 } |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
327 defer insertGMStmt.Close() |
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
|
328 |
3301
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
329 // lookup to see if data can be imported for gauge |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
330 isKnown := func(s string) bool { |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
331 idx := sort.SearchStrings(gauges, s) |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
332 return idx < len(gauges) && gauges[idx] == s |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
333 } |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
334 |
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
|
335 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
|
336 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
|
337 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
|
338 } |
1981
e89368aec538
Import: Make one request per gauge for gauge measurement data.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1978
diff
changeset
|
339 |
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
|
340 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
|
341 for _, msg := range result { |
3277
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
342 var dummy int |
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
|
343 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
|
344 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
|
345 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
|
346 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
|
347 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
|
348 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
|
349 } |
3277
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
350 feedback.Info("Found measurements/predictions for %s", curr) |
3301
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
351 if !isKnown(curr) { |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
352 feedback.Warn("Cannot import data for %s", curr) |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
353 continue |
6514b943654e
Re-enable checking of gauge availability
Tom Gottfried <tom@intevation.de>
parents:
3284
diff
changeset
|
354 } |
1981
e89368aec538
Import: Make one request per gauge for gauge measurement data.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1978
diff
changeset
|
355 |
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
|
356 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
|
357 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
|
358 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
|
359 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
|
360 } 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
|
361 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
|
362 } |
2849
b8972e4671fa
Preserve old predictions on raw gauge measurement import.
Sascha Wilde <wilde@intevation.de>
parents:
2245
diff
changeset
|
363 |
3277
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
364 newM, newP := 0, 0 |
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
|
365 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
|
366 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
|
367 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
|
368 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
|
369 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
|
370 } 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
|
371 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
|
372 } |
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 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
|
374 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
|
375 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
|
376 } |
3264
9ae43313b463
Handle some possibly missing elements in NtS response
Tom Gottfried <tom@intevation.de>
parents:
3219
diff
changeset
|
377 convert(measure.Value) |
9ae43313b463
Handle some possibly missing elements in NtS response
Tom Gottfried <tom@intevation.de>
parents:
3219
diff
changeset
|
378 convert(measure.Value_min) |
9ae43313b463
Handle some possibly missing elements in NtS response
Tom Gottfried <tom@intevation.de>
parents:
3219
diff
changeset
|
379 convert(measure.Value_max) |
9ae43313b463
Handle some possibly missing elements in NtS response
Tom Gottfried <tom@intevation.de>
parents:
3219
diff
changeset
|
380 |
3278
831193935739
Avoid storing of NtS messages other than water level
Tom Gottfried <tom@intevation.de>
parents:
3277
diff
changeset
|
381 if *measure.Measure_code != nts.Measure_code_enumWAL { |
831193935739
Avoid storing of NtS messages other than water level
Tom Gottfried <tom@intevation.de>
parents:
3277
diff
changeset
|
382 feedback.Warn("Ignored message with measure_code %s", |
831193935739
Avoid storing of NtS messages other than water level
Tom Gottfried <tom@intevation.de>
parents:
3277
diff
changeset
|
383 *measure.Measure_code) |
831193935739
Avoid storing of NtS messages other than water level
Tom Gottfried <tom@intevation.de>
parents:
3277
diff
changeset
|
384 continue |
831193935739
Avoid storing of NtS messages other than water level
Tom Gottfried <tom@intevation.de>
parents:
3277
diff
changeset
|
385 } |
3277
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
386 |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
387 if measure.Predicted { |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
388 var confInterval pgtype.Numrange |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
389 if measure.Value_min != nil && measure.Value_max != nil { |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
390 var valueMin, valueMax pgtype.Numeric |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
391 valueMin.Set(measure.Value_min) |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
392 valueMax.Set(measure.Value_max) |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
393 confInterval = pgtype.Numrange{ |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
394 Lower: valueMin, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
395 Upper: valueMax, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
396 LowerType: pgtype.Inclusive, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
397 UpperType: pgtype.Inclusive, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
398 Status: pgtype.Present, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
399 } |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
400 } |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
401 err = insertGPStmt.QueryRowContext( |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
402 ctx, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
403 currIsrs.CountryCode, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
404 currIsrs.LoCode, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
405 currIsrs.FairwaySection, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
406 currIsrs.Orc, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
407 currIsrs.Hectometre, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
408 measure.Measuredate, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
409 msg.Identification.From, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
410 msg.Identification.Language_code, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
411 msg.Identification.Country_code, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
412 msg.Identification.Date_issue, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
413 referenceCode, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
414 measure.Value, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
415 &confInterval, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
416 msg.Identification.Date_issue, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
417 msg.Identification.Originator, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
418 ).Scan(&dummy) |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
419 switch { |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
420 case err == sql.ErrNoRows: |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
421 // thats expected, nothing to do |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
422 case err != nil: |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
423 feedback.Warn(handleError(err).Error()) |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
424 default: |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
425 newP++ |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
426 } |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
427 } else { |
3284
7ae1892773a2
Avoid trying to insert explicit missing values received from NtS
Tom Gottfried <tom@intevation.de>
parents:
3278
diff
changeset
|
428 if measure.Value == nil { |
7ae1892773a2
Avoid trying to insert explicit missing values received from NtS
Tom Gottfried <tom@intevation.de>
parents:
3278
diff
changeset
|
429 feedback.Info("Missing value at %s. Ignored", |
7ae1892773a2
Avoid trying to insert explicit missing values received from NtS
Tom Gottfried <tom@intevation.de>
parents:
3278
diff
changeset
|
430 measure.Measuredate.Format(time.RFC3339)) |
7ae1892773a2
Avoid trying to insert explicit missing values received from NtS
Tom Gottfried <tom@intevation.de>
parents:
3278
diff
changeset
|
431 continue |
7ae1892773a2
Avoid trying to insert explicit missing values received from NtS
Tom Gottfried <tom@intevation.de>
parents:
3278
diff
changeset
|
432 } |
3277
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
433 err = insertGMStmt.QueryRowContext( |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
434 ctx, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
435 currIsrs.CountryCode, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
436 currIsrs.LoCode, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
437 currIsrs.FairwaySection, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
438 currIsrs.Orc, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
439 currIsrs.Hectometre, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
440 measure.Measuredate, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
441 msg.Identification.From, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
442 msg.Identification.Language_code, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
443 msg.Identification.Country_code, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
444 msg.Identification.Date_issue, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
445 referenceCode, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
446 measure.Value, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
447 msg.Identification.Date_issue, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
448 msg.Identification.Originator, |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
449 ).Scan(&dummy) |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
450 switch { |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
451 case err == sql.ErrNoRows: |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
452 // thats expected, nothing to do |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
453 case err != nil: |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
454 feedback.Warn(handleError(err).Error()) |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
455 default: |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
456 newM++ |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
457 } |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
458 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
459 } |
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
|
460 feedback.Info("Inserted %d measurements for %s", |
3277
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
461 newM, curr) |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
462 feedback.Info("Inserted %d predictions for %s", |
232fc90e6ee2
Disentangle gauge measurements and predictions
Tom Gottfried <tom@intevation.de>
parents:
3266
diff
changeset
|
463 newP, curr) |
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
|
464 gids = append(gids, curr) |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
465 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
466 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
467 return gids, nil |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
468 } |