Mercurial > gemma
annotate pkg/imports/gm.go @ 2887:83acca8937de
client: importoverview: improved log style
author | Markus Kottlaender <markus@intevation.de> |
---|---|
date | Mon, 01 Apr 2019 18:53:53 +0200 |
parents | b8972e4671fa |
children | 1cb6676d1510 |
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 |
2849
b8972e4671fa
Preserve old predictions on raw gauge measurement import.
Sascha Wilde <wilde@intevation.de>
parents:
2245
diff
changeset
|
53 // Note: we do not expect corrections of data through this service. So |
b8972e4671fa
Preserve old predictions on raw gauge measurement import.
Sascha Wilde <wilde@intevation.de>
parents:
2245
diff
changeset
|
54 // any constraint conflicts are triggered by actual redundat data which |
b8972e4671fa
Preserve old predictions on raw gauge measurement import.
Sascha Wilde <wilde@intevation.de>
parents:
2245
diff
changeset
|
55 // can be dropped. |
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 ) |
2849
b8972e4671fa
Preserve old predictions on raw gauge measurement import.
Sascha Wilde <wilde@intevation.de>
parents:
2245
diff
changeset
|
90 ON CONFLICT DO NOTHING |
1978
0a8fa6893181
Import: Upsert gauge measurement data to avoid unique contraint violation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1954
diff
changeset
|
91 RETURNING id |
0a8fa6893181
Import: Upsert gauge measurement data to avoid unique contraint violation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1954
diff
changeset
|
92 ` |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
93 ) |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
94 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
95 type gmJobCreator struct{} |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
96 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
97 func init() { |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
98 RegisterJobCreator(GMJobKind, gmJobCreator{}) |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
99 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
100 |
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
|
101 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
|
102 |
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
|
103 func (gmJobCreator) Create() Job { return new(GaugeMeasurement) } |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
104 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
105 func (gmJobCreator) Depends() []string { |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
106 return []string{ |
1664
819f67c31dfb
Imports: Stripped schema prefixes from table dependencies.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1646
diff
changeset
|
107 "gauges", |
819f67c31dfb
Imports: Stripped schema prefixes from table dependencies.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1646
diff
changeset
|
108 "gauge_measurements", |
1637
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 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
111 |
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
|
112 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
|
113 |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
114 // 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
|
115 // Currently doing nothing. |
1676
4407ecaa2192
Imports: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1664
diff
changeset
|
116 func (gmJobCreator) StageDone(context.Context, *sql.Tx, int64) error { |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
117 return nil |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
118 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
119 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
120 // CleanUp of a gauge measurement import is a NOP. |
1676
4407ecaa2192
Imports: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1664
diff
changeset
|
121 func (*GaugeMeasurement) CleanUp() error { return nil } |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
122 |
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
|
123 // 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
|
124 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
|
125 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
|
126 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
|
127 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
|
128 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
|
129 ) (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
|
130 |
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
|
131 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
|
132 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
|
133 |
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
|
134 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
|
135 |
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 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
|
137 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
|
138 } |
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 |
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 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
|
141 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
|
142 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
|
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 |
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 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
|
146 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
|
147 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
|
148 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
|
149 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
|
150 } 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
|
151 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
|
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 } |
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 } |
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 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
|
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 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
|
159 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
|
160 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
|
161 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
|
162 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
|
163 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
|
164 ) |
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 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
|
168 |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
169 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
|
170 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
|
171 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
|
172 } |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
173 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
|
174 |
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
|
175 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
|
176 |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
177 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
|
178 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
|
179 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
|
180 &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
|
181 &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
|
182 &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
|
183 &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
|
184 &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
|
185 ); err != nil { |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
186 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
|
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 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
|
189 } |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
190 |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
191 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
|
192 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
|
193 } |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
194 |
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
|
195 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
|
196 |
2233
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
197 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
|
198 } |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
199 |
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
|
200 func storeGaugeMeasurements( |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
201 ctx context.Context, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
202 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
|
203 fetch func() ([]*nts.RIS_Message_Type, error), |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
204 conn *sql.Conn, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
205 feedback Feedback, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
206 ) (interface{}, error) { |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
207 |
2233
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
208 start := time.Now() |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
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 tx, err := conn.BeginTx(ctx, nil) |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
211 if err != nil { |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
212 return nil, err |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
213 } |
2233
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
214 defer tx.Rollback() |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
215 |
2233
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
216 // 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
|
217 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
|
218 if err != nil { |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
219 return nil, err |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
220 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
221 |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
222 // 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
|
223 gids, err := doForGM(ctx, gauges, fetch, tx, feedback) |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
224 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
|
225 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
|
226 return nil, err |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
227 } |
2233
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
228 |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
229 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
|
230 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
|
231 return nil, UnchangedError("No new gauge measurements found") |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
232 } |
2233
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
233 |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
234 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
|
235 feedback.Info( |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
236 "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
|
237 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
|
238 } |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
239 feedback.Info( |
137addc77b1b
Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2187
diff
changeset
|
240 "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
|
241 |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
242 // TODO: needs to be filled more useful. |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
243 summary := struct { |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
244 GaugeMeasuremets []string `json:"gaugeMeasurements"` |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
245 }{ |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
246 GaugeMeasuremets: gids, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
247 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
248 return &summary, err |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
249 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
250 |
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
|
251 // 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
|
252 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
|
253 |
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
|
254 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
|
255 |
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
|
256 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
|
257 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
|
258 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
|
259 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
|
260 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
|
261 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
|
262 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
|
263 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
|
264 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
|
265 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
|
266 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
|
267 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
|
268 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
|
269 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
|
270 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
|
271 } |
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 |
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 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
|
274 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
|
275 } |
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 |
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
|
277 func doForGM( |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
278 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
|
279 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
|
280 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
|
281 tx *sql.Tx, |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
282 feedback Feedback, |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
283 ) ([]string, error) { |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
284 |
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
|
285 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
|
286 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
|
287 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
|
288 } |
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
|
289 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
|
290 |
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
|
291 // 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
|
292 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
|
293 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
|
294 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
|
295 } |
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
|
296 |
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
|
297 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
|
298 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
|
299 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
|
300 } |
1981
e89368aec538
Import: Make one request per gauge for gauge measurement data.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1978
diff
changeset
|
301 |
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
|
302 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
|
303 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
|
304 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
|
305 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
|
306 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
|
307 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
|
308 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
|
309 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
|
310 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
|
311 } |
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 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
|
313 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
|
314 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
|
315 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
|
316 } |
1981
e89368aec538
Import: Make one request per gauge for gauge measurement data.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1978
diff
changeset
|
317 |
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
|
318 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
|
319 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
|
320 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
|
321 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
|
322 } 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
|
323 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
|
324 } |
2849
b8972e4671fa
Preserve old predictions on raw gauge measurement import.
Sascha Wilde <wilde@intevation.de>
parents:
2245
diff
changeset
|
325 |
b8972e4671fa
Preserve old predictions on raw gauge measurement import.
Sascha Wilde <wilde@intevation.de>
parents:
2245
diff
changeset
|
326 var newCnt int = 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
|
327 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
|
328 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
|
329 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
|
330 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
|
331 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
|
332 } 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
|
333 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
|
334 } |
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 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
|
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 } |
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 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
|
340 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
|
341 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
|
342 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
|
343 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
|
344 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
|
345 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
|
346 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
|
347 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
|
348 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
|
349 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
|
350 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
|
351 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
|
352 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
|
353 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
|
354 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
|
355 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
|
356 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
|
357 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
|
358 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
|
359 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
|
360 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
|
361 ).Scan(&gid) |
2849
b8972e4671fa
Preserve old predictions on raw gauge measurement import.
Sascha Wilde <wilde@intevation.de>
parents:
2245
diff
changeset
|
362 switch { |
b8972e4671fa
Preserve old predictions on raw gauge measurement import.
Sascha Wilde <wilde@intevation.de>
parents:
2245
diff
changeset
|
363 case err == sql.ErrNoRows: |
b8972e4671fa
Preserve old predictions on raw gauge measurement import.
Sascha Wilde <wilde@intevation.de>
parents:
2245
diff
changeset
|
364 // thats expected, nothing to do |
b8972e4671fa
Preserve old predictions on raw gauge measurement import.
Sascha Wilde <wilde@intevation.de>
parents:
2245
diff
changeset
|
365 case err != nil: |
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
|
366 return nil, err |
2849
b8972e4671fa
Preserve old predictions on raw gauge measurement import.
Sascha Wilde <wilde@intevation.de>
parents:
2245
diff
changeset
|
367 default: |
b8972e4671fa
Preserve old predictions on raw gauge measurement import.
Sascha Wilde <wilde@intevation.de>
parents:
2245
diff
changeset
|
368 newCnt++ |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
369 } |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
370 } |
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 feedback.Info("Inserted %d measurements for %s", |
2849
b8972e4671fa
Preserve old predictions on raw gauge measurement import.
Sascha Wilde <wilde@intevation.de>
parents:
2245
diff
changeset
|
372 newCnt, 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
|
373 gids = append(gids, curr) |
1637
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
374 } |
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 return gids, nil |
dd31be75ce6d
Implemented gauge measurement import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
377 } |