Mercurial > gemma
annotate pkg/controllers/gauges.go @ 3105:e53ff5bcc020
hgignore: added pub-config.json to hgignore to prevent accidental commits
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Thu, 25 Apr 2019 16:36:13 +0200 |
parents | 41ed69dbf9bb |
children | 54a3e40cfbed |
rev | line source |
---|---|
2694
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 // without warranty, see README.md and license for details. |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 // |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 // |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 // Copyright (C) 2019 by via donau |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 // Software engineering by Intevation GmbH |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 // |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 // Author(s): |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 package controllers |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import ( |
3088
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
17 "context" |
2741
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
18 "database/sql" |
2694
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 "encoding/csv" |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 "fmt" |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 "log" |
2878
4f66a3ba424b
Fixed selection for Nash-Sutcliffe coeff calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2861
diff
changeset
|
22 "math" |
2694
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 "net/http" |
2762
f95ec0bb565c
Added endpoint to deliver average waterlevels for a given gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2741
diff
changeset
|
24 "sort" |
2694
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 "strconv" |
2809
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
26 "strings" |
2694
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 "time" |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 "github.com/gorilla/mux" |
2826
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
30 "github.com/jackc/pgx/pgtype" |
2762
f95ec0bb565c
Added endpoint to deliver average waterlevels for a given gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2741
diff
changeset
|
31 "gonum.org/v1/gonum/stat" |
2694
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 |
2741
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
33 "gemma.intevation.de/gemma/pkg/common" |
2694
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 "gemma.intevation.de/gemma/pkg/middleware" |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 "gemma.intevation.de/gemma/pkg/models" |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 ) |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 const ( |
2741
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
39 selectPredictedObserveredSQL = ` |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
40 SELECT |
2878
4f66a3ba424b
Fixed selection for Nash-Sutcliffe coeff calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2861
diff
changeset
|
41 measure_date, |
3088
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
42 date_issue, |
2878
4f66a3ba424b
Fixed selection for Nash-Sutcliffe coeff calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2861
diff
changeset
|
43 predicted, |
4f66a3ba424b
Fixed selection for Nash-Sutcliffe coeff calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2861
diff
changeset
|
44 water_level |
4f66a3ba424b
Fixed selection for Nash-Sutcliffe coeff calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2861
diff
changeset
|
45 FROM waterway.gauge_measurements |
2741
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
46 WHERE |
2913
cf6f595af2cb
Fixed SQL statement for nash sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2884
diff
changeset
|
47 fk_gauge_id = ( |
2763
a06d11d1f0b3
Fixed gauge selection in Nash Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2762
diff
changeset
|
48 $1::char(2), |
a06d11d1f0b3
Fixed gauge selection in Nash Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2762
diff
changeset
|
49 $2::char(3), |
a06d11d1f0b3
Fixed gauge selection in Nash Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2762
diff
changeset
|
50 $3::char(5), |
a06d11d1f0b3
Fixed gauge selection in Nash Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2762
diff
changeset
|
51 $4::char(5), |
a06d11d1f0b3
Fixed gauge selection in Nash Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2762
diff
changeset
|
52 $5::int |
2741
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
53 ) AND |
2878
4f66a3ba424b
Fixed selection for Nash-Sutcliffe coeff calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2861
diff
changeset
|
54 measure_date BETWEEN |
2884
fe3d5e824ee9
calculate interval boundaries for Nash Sutcliffe in right order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2878
diff
changeset
|
55 $6::timestamp - '72hours'::interval AND $6::timestamp |
2878
4f66a3ba424b
Fixed selection for Nash-Sutcliffe coeff calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2861
diff
changeset
|
56 ORDER BY measure_date, date_issue |
2741
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
57 ` |
2694
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 selectWaterlevelsSQL = ` |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 SELECT |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 measure_date, |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 water_level, |
2783
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
62 value_min, |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
63 value_max, |
2766
1f173d1a731d
Fixed broken SQL statement.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2763
diff
changeset
|
64 predicted |
2694
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 FROM waterway.gauge_measurements |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 WHERE |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 ` |
2800
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
68 |
2826
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
69 selectAllWaterlevelsMeasuredRangeSQL = ` |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
70 SELECT |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
71 min(measure_date), |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
72 max(measure_date) |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
73 FROM waterway.gauge_measurements WHERE |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
74 fk_gauge_id = ( |
2800
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
75 $1::char(2), |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
76 $2::char(3), |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
77 $3::char(5), |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
78 $4::char(5), |
2826
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
79 $5::int |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
80 )::isrs |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
81 AND NOT predicted |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
82 AND staging_done |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
83 ` |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
84 |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
85 selectAllWaterlevelsMeasuredSQL = ` |
2809
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
86 SELECT |
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
87 extract(day from measure_date)::varchar || ':' || |
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
88 extract(month from measure_date)::varchar AS day_month, |
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
89 percentile_disc(0.25) within group (order by water_level) AS q25, |
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
90 percentile_disc(0.5) within group (order by water_level) AS median, |
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
91 percentile_disc(0.75) within group (order by water_level) AS q75, |
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
92 avg(water_level) AS mean, |
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
93 min(water_level) AS min, |
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
94 max(water_level) AS max |
2826
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
95 FROM waterway.gauge_measurements WHERE |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
96 fk_gauge_id = ( |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
97 $1::char(2), |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
98 $2::char(3), |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
99 $3::char(5), |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
100 $4::char(5), |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
101 $5::int |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
102 )::isrs |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
103 AND NOT predicted |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
104 AND staging_done |
2809
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
105 GROUP BY extract(day from measure_date)::varchar || ':' || |
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
106 extract(month from measure_date)::varchar; |
2800
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
107 ` |
2803
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
108 selectYearWaterlevelsMeasuredSQL = ` |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
109 SELECT |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
110 measure_date, |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
111 water_level |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
112 FROM waterway.gauge_measurements |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
113 WHERE |
2817
ff58440ce809
Added staging_done to the longterm waterlevels selections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2814
diff
changeset
|
114 NOT predicted AND |
ff58440ce809
Added staging_done to the longterm waterlevels selections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2814
diff
changeset
|
115 staging_done AND |
ff58440ce809
Added staging_done to the longterm waterlevels selections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2814
diff
changeset
|
116 fk_gauge_id = ( |
2803
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
117 $1::char(2), |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
118 $2::char(3), |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
119 $3::char(5), |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
120 $4::char(5), |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
121 $5::int |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
122 ) |
2806
c6374c520228
Use between filter to speed up SQL for fetching yearly waterlevels.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2803
diff
changeset
|
123 AND measure_date BETWEEN $6 AND $7 |
2803
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
124 ORDER BY measure_date |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
125 ` |
2694
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 ) |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 |
2783
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
128 func float64format(v float64) string { |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
129 return strconv.FormatFloat(v, 'f', -1, 64) |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
130 } |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
131 |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
132 func nullFloat64format(v sql.NullFloat64) string { |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
133 if v.Valid { |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
134 return float64format(v.Float64) |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
135 } |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
136 return "" |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
137 } |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
138 |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
139 func boolFormat(b bool) string { |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
140 if b { |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
141 return "t" |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
142 } |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
143 return "f" |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
144 } |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
145 |
2803
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
146 func yearWaterlevels(rw http.ResponseWriter, req *http.Request) { |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
147 |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
148 gauge := mux.Vars(req)["gauge"] |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
149 |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
150 isrs, err := models.IsrsFromString(gauge) |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
151 if err != nil { |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
152 http.Error( |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
153 rw, fmt.Sprintf("error: Invalid ISRS code: %v", err), |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
154 http.StatusBadRequest) |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
155 return |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
156 } |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
157 |
2806
c6374c520228
Use between filter to speed up SQL for fetching yearly waterlevels.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2803
diff
changeset
|
158 year, _ := strconv.Atoi(mux.Vars(req)["year"]) |
2803
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
159 |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
160 conn := middleware.GetDBConn(req) |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
161 |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
162 ctx := req.Context() |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
163 |
2806
c6374c520228
Use between filter to speed up SQL for fetching yearly waterlevels.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2803
diff
changeset
|
164 begin := time.Date(year, time.January, 1, 0, 0, 0, 0, time.UTC) |
c6374c520228
Use between filter to speed up SQL for fetching yearly waterlevels.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2803
diff
changeset
|
165 end := time.Date(year+1, time.January, 1, 0, 0, 0, 0, time.UTC).Add(-time.Microsecond) |
c6374c520228
Use between filter to speed up SQL for fetching yearly waterlevels.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2803
diff
changeset
|
166 |
c6374c520228
Use between filter to speed up SQL for fetching yearly waterlevels.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2803
diff
changeset
|
167 log.Printf("info: begin %s\n", begin) |
c6374c520228
Use between filter to speed up SQL for fetching yearly waterlevels.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2803
diff
changeset
|
168 log.Printf("info: end %s\n", end) |
c6374c520228
Use between filter to speed up SQL for fetching yearly waterlevels.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2803
diff
changeset
|
169 |
2803
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
170 rows, err := conn.QueryContext( |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
171 ctx, |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
172 selectYearWaterlevelsMeasuredSQL, |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
173 isrs.CountryCode, |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
174 isrs.LoCode, |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
175 isrs.FairwaySection, |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
176 isrs.Orc, |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
177 isrs.Hectometre, |
2806
c6374c520228
Use between filter to speed up SQL for fetching yearly waterlevels.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2803
diff
changeset
|
178 begin, |
c6374c520228
Use between filter to speed up SQL for fetching yearly waterlevels.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2803
diff
changeset
|
179 end, |
2803
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
180 ) |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
181 if err != nil { |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
182 http.Error( |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
183 rw, fmt.Sprintf("error: %v", err), |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
184 http.StatusInternalServerError) |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
185 return |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
186 } |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
187 defer rows.Close() |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
188 |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
189 var values []float64 |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
190 |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
191 lastDay, lastMonth := -1, -1 |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
192 |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
193 write := func() error { |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
194 var err error |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
195 if len(values) > 0 { |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
196 mean := stat.Mean(values, nil) |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
197 _, err = fmt.Fprintf( |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
198 rw, "%02d-%02d,%s\n", lastDay, lastMonth, |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
199 float64format(mean)) |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
200 values = values[:0] |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
201 } |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
202 return err |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
203 } |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
204 |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
205 for rows.Next() { |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
206 var when time.Time |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
207 var value float64 |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
208 if err := rows.Scan(&when, &value); err != nil { |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
209 log.Printf("error: %v", err) |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
210 // Too late for an HTTP error code. |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
211 return |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
212 } |
2807
1fa57ad05e1e
Calculate the yearly waterlevel over an UTC time interval.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2806
diff
changeset
|
213 when = when.UTC() |
2803
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
214 day, month := when.Day(), int(when.Month()) |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
215 if day != lastDay || month != lastMonth { |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
216 if err := write(); err != nil { |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
217 log.Printf("error: %v", err) |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
218 // Too late for an HTTP error code. |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
219 return |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
220 } |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
221 lastDay, lastMonth = day, month |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
222 } |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
223 values = append(values, value) |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
224 } |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
225 |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
226 if err := rows.Err(); err != nil { |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
227 log.Printf("error: %v", err) |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
228 // Too late for an HTTP error code. |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
229 return |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
230 } |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
231 |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
232 if err := write(); err != nil { |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
233 log.Printf("error: %v", err) |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
234 // Too late for an HTTP error code. |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
235 } |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
236 } |
46a9a7c1281f
Added GET /api/data/year-waterlevels/{gauge}/{year}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2800
diff
changeset
|
237 |
2800
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
238 func longtermWaterlevels(rw http.ResponseWriter, req *http.Request) { |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
239 |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
240 gauge := mux.Vars(req)["gauge"] |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
241 |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
242 isrs, err := models.IsrsFromString(gauge) |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
243 if err != nil { |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
244 http.Error( |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
245 rw, fmt.Sprintf("error: Invalid ISRS code: %v", err), |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
246 http.StatusBadRequest) |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
247 return |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
248 } |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
249 |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
250 conn := middleware.GetDBConn(req) |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
251 |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
252 ctx := req.Context() |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
253 |
2826
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
254 var begin, end pgtype.Timestamp |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
255 |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
256 err = conn.QueryRowContext( |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
257 ctx, |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
258 selectAllWaterlevelsMeasuredRangeSQL, |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
259 isrs.CountryCode, |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
260 isrs.LoCode, |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
261 isrs.FairwaySection, |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
262 isrs.Orc, |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
263 isrs.Hectometre, |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
264 ).Scan(&begin, &end) |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
265 |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
266 switch { |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
267 case err == sql.ErrNoRows || begin.Status != pgtype.Present || end.Status != pgtype.Present: |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
268 http.NotFound(rw, req) |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
269 return |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
270 case err != nil: |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
271 http.Error( |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
272 rw, fmt.Sprintf("error: %v", err), |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
273 http.StatusInternalServerError) |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
274 return |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
275 } |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
276 |
2800
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
277 rows, err := conn.QueryContext( |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
278 ctx, |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
279 selectAllWaterlevelsMeasuredSQL, |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
280 isrs.CountryCode, |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
281 isrs.LoCode, |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
282 isrs.FairwaySection, |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
283 isrs.Orc, |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
284 isrs.Hectometre, |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
285 ) |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
286 if err != nil { |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
287 http.Error( |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
288 rw, fmt.Sprintf("error: %v", err), |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
289 http.StatusInternalServerError) |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
290 return |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
291 } |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
292 defer rows.Close() |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
293 |
2809
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
294 type result struct { |
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
295 day int |
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
296 month int |
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
297 q25 float64 |
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
298 median float64 |
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
299 q75 float64 |
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
300 mean float64 |
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
301 min float64 |
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
302 max float64 |
2800
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
303 } |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
304 |
2809
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
305 results := make([]result, 0, 366) |
2800
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
306 |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
307 start := time.Now() |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
308 |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
309 for rows.Next() { |
2809
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
310 var r result |
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
311 var dayMonth string |
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
312 if err := rows.Scan( |
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
313 &dayMonth, |
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
314 &r.q25, |
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
315 &r.median, |
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
316 &r.q75, |
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
317 &r.mean, |
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
318 &r.min, |
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
319 &r.max, |
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
320 ); err != nil { |
2800
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
321 http.Error( |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
322 rw, fmt.Sprintf("error: %v", err), |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
323 http.StatusInternalServerError) |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
324 } |
2809
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
325 parts := strings.SplitN(dayMonth, ":", 2) |
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
326 r.day, _ = strconv.Atoi(parts[0]) |
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
327 r.month, _ = strconv.Atoi(parts[1]) |
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
328 results = append(results, r) |
2800
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
329 } |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
330 |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
331 if err := rows.Err(); err != nil { |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
332 http.Error( |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
333 rw, fmt.Sprintf("error: %v", err), |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
334 http.StatusInternalServerError) |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
335 return |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
336 } |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
337 |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
338 log.Printf("info: loading entries took %s\n", time.Since(start)) |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
339 |
2809
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
340 log.Printf("info: days found: %d\n", len(results)) |
2800
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
341 |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
342 sort.Slice(results, func(i, j int) bool { |
2832
b5555005f51e
cosmetics: removed superfluous casts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2826
diff
changeset
|
343 if d := results[i].month - results[j].month; d != 0 { |
2800
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
344 return d < 0 |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
345 } |
2809
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
346 return results[i].day < results[j].day |
2800
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
347 }) |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
348 |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
349 rw.Header().Add("Content-Type", "text/csv") |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
350 |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
351 out := csv.NewWriter(rw) |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
352 |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
353 record := []string{ |
2826
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
354 fmt.Sprintf("#interval: %d-%d", |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
355 begin.Time.UTC().Year(), |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
356 end.Time.UTC().Year()), |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
357 "", |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
358 "", |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
359 "", |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
360 "", |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
361 "", |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
362 "", |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
363 } |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
364 |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
365 if err := out.Write(record); err != nil { |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
366 log.Printf("error: %v\n", err) |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
367 // Too late for an HTTP error code. |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
368 return |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
369 } |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
370 |
f7ae108c2838
longterm waterlevels statistics: Generate a comment line with the interval of years.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2817
diff
changeset
|
371 record = []string{ |
2800
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
372 "#date", |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
373 "#min", |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
374 "#max", |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
375 "#mean", |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
376 "#median", |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
377 "#q25", |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
378 "#q75", |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
379 } |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
380 |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
381 if err := out.Write(record); err != nil { |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
382 log.Printf("error: %v\n", err) |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
383 // Too late for an HTTP error code. |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
384 return |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
385 } |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
386 |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
387 for i := range results { |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
388 r := &results[i] |
2809
216bc6394911
Optimized longterm waterlevel statistics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2808
diff
changeset
|
389 record[0] = fmt.Sprintf("%02d-%02d", r.day, r.month) |
2800
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
390 record[1] = float64format(r.min) |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
391 record[2] = float64format(r.max) |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
392 record[3] = float64format(r.mean) |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
393 record[4] = float64format(r.median) |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
394 record[5] = float64format(r.q25) |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
395 record[6] = float64format(r.q75) |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
396 if err := out.Write(record); err != nil { |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
397 log.Printf("error: %v\n", err) |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
398 // Too late for an HTTP error code. |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
399 return |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
400 } |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
401 } |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
402 |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
403 out.Flush() |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
404 if err := out.Error(); err != nil { |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
405 log.Printf("error: %v", err) |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
406 // Too late for an HTTP error code. |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
407 return |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
408 } |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
409 } |
db1052bc162a
Added GET /data/longterm-waterlevels/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
410 |
3088
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
411 func parseISRS(code string) (*models.Isrs, error) { |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
412 isrs, err := models.IsrsFromString(code) |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
413 if err != nil { |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
414 return nil, JSONError{ |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
415 Code: http.StatusBadRequest, |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
416 Message: fmt.Sprintf("error: Invalid ISRS code: %v", err), |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
417 } |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
418 } |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
419 return isrs, nil |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
420 } |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
421 |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
422 type observedPredictedValues struct { |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
423 when time.Time |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
424 observed float64 |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
425 predicted common.TimedValues |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
426 } |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
427 |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
428 func loadNashSutcliffeData( |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
429 ctx context.Context, |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
430 conn *sql.Conn, |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
431 gauge *models.Isrs, |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
432 when time.Time, |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
433 ) ([]observedPredictedValues, error) { |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
434 |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
435 var rows *sql.Rows |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
436 var err error |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
437 if rows, err = conn.QueryContext( |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
438 ctx, |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
439 selectPredictedObserveredSQL, |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
440 gauge.CountryCode, |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
441 gauge.LoCode, |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
442 gauge.FairwaySection, |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
443 gauge.Orc, |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
444 gauge.Hectometre, |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
445 when, |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
446 ); err != nil { |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
447 return nil, err |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
448 } |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
449 defer rows.Close() |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
450 |
3101
41ed69dbf9bb
Nash Sutcliffe: Optimization: When append predicted values only accept predictions where the issue date is 24/48/72h in the past of the measure date.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3099
diff
changeset
|
451 acceptedDeltas := []time.Duration{ |
41ed69dbf9bb
Nash Sutcliffe: Optimization: When append predicted values only accept predictions where the issue date is 24/48/72h in the past of the measure date.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3099
diff
changeset
|
452 -time.Hour * 24, |
41ed69dbf9bb
Nash Sutcliffe: Optimization: When append predicted values only accept predictions where the issue date is 24/48/72h in the past of the measure date.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3099
diff
changeset
|
453 -time.Hour * 48, |
41ed69dbf9bb
Nash Sutcliffe: Optimization: When append predicted values only accept predictions where the issue date is 24/48/72h in the past of the measure date.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3099
diff
changeset
|
454 -time.Hour * 72, |
41ed69dbf9bb
Nash Sutcliffe: Optimization: When append predicted values only accept predictions where the issue date is 24/48/72h in the past of the measure date.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3099
diff
changeset
|
455 } |
41ed69dbf9bb
Nash Sutcliffe: Optimization: When append predicted values only accept predictions where the issue date is 24/48/72h in the past of the measure date.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3099
diff
changeset
|
456 |
41ed69dbf9bb
Nash Sutcliffe: Optimization: When append predicted values only accept predictions where the issue date is 24/48/72h in the past of the measure date.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3099
diff
changeset
|
457 isAccepted := func(observed, predicted time.Time) bool { |
41ed69dbf9bb
Nash Sutcliffe: Optimization: When append predicted values only accept predictions where the issue date is 24/48/72h in the past of the measure date.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3099
diff
changeset
|
458 for _, delta := range acceptedDeltas { |
41ed69dbf9bb
Nash Sutcliffe: Optimization: When append predicted values only accept predictions where the issue date is 24/48/72h in the past of the measure date.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3099
diff
changeset
|
459 t := observed.Add(delta) |
41ed69dbf9bb
Nash Sutcliffe: Optimization: When append predicted values only accept predictions where the issue date is 24/48/72h in the past of the measure date.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3099
diff
changeset
|
460 d := predicted.Sub(t) |
41ed69dbf9bb
Nash Sutcliffe: Optimization: When append predicted values only accept predictions where the issue date is 24/48/72h in the past of the measure date.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3099
diff
changeset
|
461 if -10*time.Millisecond < d && d < 10*time.Millisecond { |
41ed69dbf9bb
Nash Sutcliffe: Optimization: When append predicted values only accept predictions where the issue date is 24/48/72h in the past of the measure date.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3099
diff
changeset
|
462 return true |
41ed69dbf9bb
Nash Sutcliffe: Optimization: When append predicted values only accept predictions where the issue date is 24/48/72h in the past of the measure date.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3099
diff
changeset
|
463 } |
41ed69dbf9bb
Nash Sutcliffe: Optimization: When append predicted values only accept predictions where the issue date is 24/48/72h in the past of the measure date.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3099
diff
changeset
|
464 } |
41ed69dbf9bb
Nash Sutcliffe: Optimization: When append predicted values only accept predictions where the issue date is 24/48/72h in the past of the measure date.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3099
diff
changeset
|
465 return false |
41ed69dbf9bb
Nash Sutcliffe: Optimization: When append predicted values only accept predictions where the issue date is 24/48/72h in the past of the measure date.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3099
diff
changeset
|
466 } |
41ed69dbf9bb
Nash Sutcliffe: Optimization: When append predicted values only accept predictions where the issue date is 24/48/72h in the past of the measure date.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3099
diff
changeset
|
467 |
3088
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
468 var ( |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
469 hasCurrent bool |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
470 current observedPredictedValues |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
471 values []observedPredictedValues |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
472 ) |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
473 |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
474 for rows.Next() { |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
475 var ( |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
476 measureDate time.Time |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
477 issueDate time.Time |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
478 predicted bool |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
479 value float64 |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
480 ) |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
481 if err := rows.Scan( |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
482 &measureDate, |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
483 &issueDate, |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
484 &predicted, |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
485 &value, |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
486 ); err != nil { |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
487 return nil, err |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
488 } |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
489 measureDate = measureDate.UTC() |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
490 issueDate = issueDate.UTC() |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
491 |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
492 if hasCurrent { |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
493 if !current.when.Equal(measureDate) { |
3097
e6ba32b060df
Nash Sutcliffe: Treat last prediction date as valid afterwards. Small optimizsations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3092
diff
changeset
|
494 if !math.IsNaN(current.observed) && len(current.predicted) > 0 { |
3088
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
495 values = append(values, current) |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
496 } |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
497 current = observedPredictedValues{ |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
498 observed: math.NaN(), |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
499 when: measureDate, |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
500 } |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
501 } |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
502 } else { |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
503 hasCurrent = true |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
504 current = observedPredictedValues{ |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
505 observed: math.NaN(), |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
506 when: measureDate, |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
507 } |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
508 } |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
509 |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
510 if predicted { |
3101
41ed69dbf9bb
Nash Sutcliffe: Optimization: When append predicted values only accept predictions where the issue date is 24/48/72h in the past of the measure date.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3099
diff
changeset
|
511 if isAccepted(measureDate, issueDate) { |
41ed69dbf9bb
Nash Sutcliffe: Optimization: When append predicted values only accept predictions where the issue date is 24/48/72h in the past of the measure date.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3099
diff
changeset
|
512 current.predicted = append( |
41ed69dbf9bb
Nash Sutcliffe: Optimization: When append predicted values only accept predictions where the issue date is 24/48/72h in the past of the measure date.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3099
diff
changeset
|
513 current.predicted, |
41ed69dbf9bb
Nash Sutcliffe: Optimization: When append predicted values only accept predictions where the issue date is 24/48/72h in the past of the measure date.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3099
diff
changeset
|
514 common.TimedValue{When: issueDate, Value: value}, |
41ed69dbf9bb
Nash Sutcliffe: Optimization: When append predicted values only accept predictions where the issue date is 24/48/72h in the past of the measure date.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3099
diff
changeset
|
515 ) |
41ed69dbf9bb
Nash Sutcliffe: Optimization: When append predicted values only accept predictions where the issue date is 24/48/72h in the past of the measure date.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3099
diff
changeset
|
516 } |
3088
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
517 } else { |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
518 current.observed = value |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
519 } |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
520 } |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
521 |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
522 if err := rows.Err(); err != nil { |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
523 return nil, err |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
524 } |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
525 |
3097
e6ba32b060df
Nash Sutcliffe: Treat last prediction date as valid afterwards. Small optimizsations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3092
diff
changeset
|
526 if hasCurrent && !math.IsNaN(current.observed) && len(current.predicted) > 0 { |
3088
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
527 values = append(values, current) |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
528 } |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
529 |
3097
e6ba32b060df
Nash Sutcliffe: Treat last prediction date as valid afterwards. Small optimizsations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3092
diff
changeset
|
530 // for i := range values { |
e6ba32b060df
Nash Sutcliffe: Treat last prediction date as valid afterwards. Small optimizsations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3092
diff
changeset
|
531 // log.Printf("%v %f %d\n", values[i].when, values[i].observed, len(values[i].predicted)) |
e6ba32b060df
Nash Sutcliffe: Treat last prediction date as valid afterwards. Small optimizsations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3092
diff
changeset
|
532 // if len(values[i].predicted) > 0 { |
e6ba32b060df
Nash Sutcliffe: Treat last prediction date as valid afterwards. Small optimizsations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3092
diff
changeset
|
533 // for j := range values[i].predicted { |
e6ba32b060df
Nash Sutcliffe: Treat last prediction date as valid afterwards. Small optimizsations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3092
diff
changeset
|
534 // log.Printf("\t%v %f\n", values[i].predicted[j].When, values[i].predicted[j].Value) |
e6ba32b060df
Nash Sutcliffe: Treat last prediction date as valid afterwards. Small optimizsations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3092
diff
changeset
|
535 // } |
e6ba32b060df
Nash Sutcliffe: Treat last prediction date as valid afterwards. Small optimizsations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3092
diff
changeset
|
536 // } |
e6ba32b060df
Nash Sutcliffe: Treat last prediction date as valid afterwards. Small optimizsations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3092
diff
changeset
|
537 // } |
e6ba32b060df
Nash Sutcliffe: Treat last prediction date as valid afterwards. Small optimizsations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3092
diff
changeset
|
538 |
3088
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
539 return values, nil |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
540 } |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
541 |
2741
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
542 func nashSutcliffe( |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
543 _ interface{}, |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
544 req *http.Request, |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
545 conn *sql.Conn, |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
546 ) (jr JSONResult, err error) { |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
547 gauge := mux.Vars(req)["gauge"] |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
548 |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
549 var isrs *models.Isrs |
3088
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
550 if isrs, err = parseISRS(gauge); err != nil { |
2741
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
551 return |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
552 } |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
553 |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
554 var when time.Time |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
555 if w := req.FormValue("when"); w != "" { |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
556 if when, err = time.Parse(models.ImportTimeFormat, w); err != nil { |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
557 err = JSONError{ |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
558 Code: http.StatusBadRequest, |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
559 Message: fmt.Sprintf("error: wrong time format: %v", err), |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
560 } |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
561 return |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
562 } |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
563 } else { |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
564 when = time.Now() |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
565 } |
3088
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
566 when = when.UTC() |
2741
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
567 |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
568 ctx := req.Context() |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
569 |
3088
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
570 var values []observedPredictedValues |
2878
4f66a3ba424b
Fixed selection for Nash-Sutcliffe coeff calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2861
diff
changeset
|
571 |
3088
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
572 if values, err = loadNashSutcliffeData(ctx, conn, isrs, when); err != nil { |
2741
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
573 return |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
574 } |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
575 |
3088
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
576 log.Printf("info: found %d value(s) for Nash Sutcliffe.\n", len(values)) |
2878
4f66a3ba424b
Fixed selection for Nash-Sutcliffe coeff calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2861
diff
changeset
|
577 |
2741
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
578 type coeff struct { |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
579 Value float64 `json:"value"` |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
580 Samples int `json:"samples"` |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
581 Hours int `json:"hours"` |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
582 } |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
583 |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
584 type coeffs struct { |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
585 When models.ImportTime `json:"when"` |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
586 Coeffs []coeff `json:"coeffs"` |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
587 } |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
588 |
3091
cec9d4af5f03
Simplified and fixed Nash Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3090
diff
changeset
|
589 var predicted, observed []float64 |
3088
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
590 |
2741
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
591 cs := make([]coeff, 3) |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
592 for i := range cs { |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
593 cs[i].Hours = (i + 1) * 24 |
3092
7dc9660df743
Fixed c&p sign error in Nash Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3091
diff
changeset
|
594 delta := -time.Duration(cs[i].Hours) * time.Hour |
3088
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
595 |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
596 for j := range values { |
3091
cec9d4af5f03
Simplified and fixed Nash Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3090
diff
changeset
|
597 when := values[j].when.Add(delta) |
3099
f516ac26f4db
"Sharp" match for predicted and measured values in nash sutcliffe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3097
diff
changeset
|
598 if p, ok := values[j].predicted.Find(when); ok { |
3091
cec9d4af5f03
Simplified and fixed Nash Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3090
diff
changeset
|
599 predicted = append(predicted, p) |
cec9d4af5f03
Simplified and fixed Nash Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3090
diff
changeset
|
600 observed = append(observed, values[j].observed) |
3088
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
601 } |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
602 } |
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
603 |
3091
cec9d4af5f03
Simplified and fixed Nash Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3090
diff
changeset
|
604 cs[i].Value = common.NashSutcliffe(predicted, observed) |
cec9d4af5f03
Simplified and fixed Nash Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3090
diff
changeset
|
605 cs[i].Samples = len(predicted) |
3088
09d1ffce3d00
Reworked Nash-Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2913
diff
changeset
|
606 |
3091
cec9d4af5f03
Simplified and fixed Nash Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3090
diff
changeset
|
607 predicted = predicted[:0] |
cec9d4af5f03
Simplified and fixed Nash Sutcliffe calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3090
diff
changeset
|
608 observed = observed[:0] |
2741
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
609 } |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
610 |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
611 jr = JSONResult{ |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
612 Result: &coeffs{ |
3089
813309225e35
Made 'go vet' happy again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3088
diff
changeset
|
613 When: models.ImportTime{Time: when}, |
2741
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
614 Coeffs: cs, |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
615 }, |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
616 } |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
617 return |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
618 } |
87aed4f9b1b8
Added calculation of Nash Sutcliffe efficiency coefficents.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2694
diff
changeset
|
619 |
2694
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
620 func waterlevels(rw http.ResponseWriter, req *http.Request) { |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
621 gauge := mux.Vars(req)["gauge"] |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
622 |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
623 isrs, err := models.IsrsFromString(gauge) |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
624 if err != nil { |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
625 http.Error( |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
626 rw, fmt.Sprintf("error: Invalid ISRS code: %v", err), |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
627 http.StatusBadRequest) |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
628 return |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
629 } |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
630 |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
631 var fb filterBuilder |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
632 fb.stmt.WriteString(selectWaterlevelsSQL) |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
633 |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
634 fb.cond( |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
635 " fk_gauge_id = ($%d::char(2), $%d::char(3), $%d::char(5), $%d::char(5), $%d::int) ", |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
636 isrs.CountryCode, |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
637 isrs.LoCode, |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
638 isrs.FairwaySection, |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
639 isrs.Orc, |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
640 isrs.Hectometre, |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
641 ) |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
642 |
2858
401bca8eaafb
Filter predicted values for waterlevels.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2832
diff
changeset
|
643 fb.cond( |
2861
e6dc09896a4d
Fixed selection of predicted for waterlevel endpoint.
Sascha Wilde <wilde@intevation.de>
parents:
2858
diff
changeset
|
644 `(NOT predicted |
2858
401bca8eaafb
Filter predicted values for waterlevels.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2832
diff
changeset
|
645 OR ( |
401bca8eaafb
Filter predicted values for waterlevels.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2832
diff
changeset
|
646 date_issue = ( |
2861
e6dc09896a4d
Fixed selection of predicted for waterlevel endpoint.
Sascha Wilde <wilde@intevation.de>
parents:
2858
diff
changeset
|
647 SELECT max(date_issue) FROM waterway.gauge_measurements |
2858
401bca8eaafb
Filter predicted values for waterlevels.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2832
diff
changeset
|
648 WHERE fk_gauge_id = ($%d::char(2), $%d::char(3), $%d::char(5), $%d::char(5), $%d::int) |
401bca8eaafb
Filter predicted values for waterlevels.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2832
diff
changeset
|
649 ) |
2861
e6dc09896a4d
Fixed selection of predicted for waterlevel endpoint.
Sascha Wilde <wilde@intevation.de>
parents:
2858
diff
changeset
|
650 ))`, |
2858
401bca8eaafb
Filter predicted values for waterlevels.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2832
diff
changeset
|
651 isrs.CountryCode, |
401bca8eaafb
Filter predicted values for waterlevels.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2832
diff
changeset
|
652 isrs.LoCode, |
401bca8eaafb
Filter predicted values for waterlevels.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2832
diff
changeset
|
653 isrs.FairwaySection, |
401bca8eaafb
Filter predicted values for waterlevels.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2832
diff
changeset
|
654 isrs.Orc, |
401bca8eaafb
Filter predicted values for waterlevels.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2832
diff
changeset
|
655 isrs.Hectometre, |
401bca8eaafb
Filter predicted values for waterlevels.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2832
diff
changeset
|
656 ) |
401bca8eaafb
Filter predicted values for waterlevels.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2832
diff
changeset
|
657 |
2694
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
658 if from := req.FormValue("from"); from != "" { |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
659 fromTime, err := time.Parse(models.ImportTimeFormat, from) |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
660 if err != nil { |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
661 http.Error( |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
662 rw, fmt.Sprintf("error: Invalid from time: %v", err), |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
663 http.StatusBadRequest) |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
664 return |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
665 } |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
666 fb.cond("measure_date >= $%d", fromTime) |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
667 } |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
668 |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
669 if to := req.FormValue("to"); to != "" { |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
670 toTime, err := time.Parse(models.ImportTimeFormat, to) |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
671 if err != nil { |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
672 http.Error( |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
673 rw, fmt.Sprintf("error: Invalid from time: %v", err), |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
674 http.StatusBadRequest) |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
675 return |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
676 } |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
677 fb.cond("measure_date <= $%d", toTime) |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
678 } |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
679 |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
680 conn := middleware.GetDBConn(req) |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
681 |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
682 ctx := req.Context() |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
683 |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
684 rows, err := conn.QueryContext(ctx, fb.stmt.String(), fb.args...) |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
685 if err != nil { |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
686 http.Error( |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
687 rw, fmt.Sprintf("error: %v", err), |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
688 http.StatusInternalServerError) |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
689 return |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
690 } |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
691 defer rows.Close() |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
692 |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
693 rw.Header().Add("Content-Type", "text/csv") |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
694 |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
695 out := csv.NewWriter(rw) |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
696 |
2783
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
697 record := []string{ |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
698 "#date", |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
699 "#water_level", |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
700 "#value_min", |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
701 "#value_max", |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
702 "#predicted", |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
703 } |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
704 |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
705 if err := out.Write(record); err != nil { |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
706 log.Printf("error: %v", err) |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
707 // Too late for an HTTP error code. |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
708 return |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
709 } |
2694
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
710 |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
711 for rows.Next() { |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
712 var ( |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
713 measureDate time.Time |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
714 waterlevel float64 |
2783
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
715 valueMin sql.NullFloat64 |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
716 valueMax sql.NullFloat64 |
2694
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
717 predicted bool |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
718 ) |
2783
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
719 if err := rows.Scan( |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
720 &measureDate, |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
721 &waterlevel, |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
722 &valueMin, |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
723 &valueMax, |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
724 &predicted, |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
725 ); err != nil { |
2694
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
726 log.Printf("error: %v\n", err) |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
727 // Too late for an HTTP error code. |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
728 return |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
729 } |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
730 record[0] = measureDate.Format(models.ImportTimeFormat) |
2783
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
731 record[1] = float64format(waterlevel) |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
732 record[2] = nullFloat64format(valueMin) |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
733 record[3] = nullFloat64format(valueMax) |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
734 record[4] = boolFormat(predicted) |
2806821cfd63
Added min and max values to CSV output of /api/data/waterlevels/{gauge} .
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2766
diff
changeset
|
735 |
2694
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
736 if err := out.Write(record); err != nil { |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
737 log.Printf("error: %v", err) |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
738 // Too late for an HTTP error code. |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
739 return |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
740 } |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
741 } |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
742 |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
743 if err := rows.Err(); err != nil { |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
744 log.Printf("error: %v", err) |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
745 // Too late for an HTTP error code. |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
746 return |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
747 } |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
748 |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
749 out.Flush() |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
750 if err := out.Error(); err != nil { |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
751 log.Printf("error: %v", err) |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
752 // Too late for an HTTP error code. |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
753 return |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
754 } |
0d7a4fdb9e12
Added GET /api/data/waterlevels/{gauge isrs}?from={time_a}&to={time_b} to fetch waterlevels of gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
755 } |