Mercurial > gemma
annotate pkg/controllers/bottlenecks.go @ 5096:f64ff954ee31 queued-stage-done
Added new reviewed state.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 24 Mar 2020 12:53:45 +0100 |
parents | 1a9e3e5feaa7 |
children | d6710d29516b |
rev | line source |
---|---|
2962
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 // without warranty, see README.md and license for details. |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 // |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 // |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 // Copyright (C) 2019 by via donau |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 // Software engineering by Intevation GmbH |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 // |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 // Author(s): |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
4343
63c25eb9c07c
FA: be optimistic about missing data.
Sascha Wilde <wilde@intevation.de>
parents:
4149
diff
changeset
|
13 // * Sascha Wilde <wilde@intevation.de> |
2962
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 package controllers |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 import ( |
3116
ff0b9a94e0e4
Simpified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3115
diff
changeset
|
18 "context" |
2962
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 "database/sql" |
3119
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
20 "encoding/csv" |
2962
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 "fmt" |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 "log" |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 "net/http" |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 "sort" |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 "strconv" |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 "strings" |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 "time" |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 |
3117
6b5132fd385e
Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3116
diff
changeset
|
29 "github.com/gorilla/mux" |
6b5132fd385e
Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3116
diff
changeset
|
30 |
2962
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 "gemma.intevation.de/gemma/pkg/common" |
3119
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
32 "gemma.intevation.de/gemma/pkg/middleware" |
2962
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 ) |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 const ( |
3392
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
36 selectLimitingSQL = ` |
3689
268348a58c9c
Fixed SQL in bottleneck/fairway-depth api.
Sascha Wilde <wilde@intevation.de>
parents:
3666
diff
changeset
|
37 SELECT limiting FROM waterway.bottlenecks bn |
3666
db87f34805fb
Align bottleneck validity at gauges
Tom Gottfried <tom@intevation.de>
parents:
3645
diff
changeset
|
38 WHERE bn.validity @> current_timestamp AND objnam = $1 |
db87f34805fb
Align bottleneck validity at gauges
Tom Gottfried <tom@intevation.de>
parents:
3645
diff
changeset
|
39 ` |
3392
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
40 |
2962
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 selectAvailableDepthSQL = ` |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 WITH data AS ( |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 SELECT |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 efa.measure_date, |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 efa.available_depth_value, |
3392
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
46 efa.available_width_value, |
2962
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 efa.water_level_value |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 FROM waterway.effective_fairway_availability efa |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 JOIN waterway.fairway_availability fa |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 ON efa.fairway_availability_id = fa.id |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 JOIN waterway.bottlenecks bn |
4073
21854740f433
Adapted fwa calculations (for diagrams) to new historization model.
Sascha Wilde <wilde@intevation.de>
parents:
4052
diff
changeset
|
52 ON fa.bottleneck_id = bn.bottleneck_id |
2962
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 WHERE |
3666
db87f34805fb
Align bottleneck validity at gauges
Tom Gottfried <tom@intevation.de>
parents:
3645
diff
changeset
|
54 bn.validity @> current_timestamp AND |
2962
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 bn.objnam = $1 AND |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 efa.level_of_service = $2 AND |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 efa.measure_type = 'Measured' AND |
3392
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
58 (efa.available_depth_value IS NOT NULL OR |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
59 efa.available_width_value IS NOT NULL) AND |
2962
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 efa.water_level_value IS NOT NULL |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 ), |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 before AS ( |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 SELECT * FROM data WHERE measure_date < $3 |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 ORDER BY measure_date DESC LIMIT 1 |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 ), |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 inside AS ( |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 SELECT * FROM data WHERE measure_date BETWEEN $3 AND $4 |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 ), |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 after AS ( |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 SELECT * FROM data WHERE measure_date > $4 |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 ORDER BY measure_date LIMIT 1 |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 ) |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 SELECT * FROM before |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 UNION ALL |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 SELECT * FROM inside |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 UNION ALL |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 SELECT * FROM after |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 ORDER BY measure_date |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 ` |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 |
3119
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
81 selectGaugeLDCSQL = ` |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
82 SELECT |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
83 grwl.value |
3302
ec6163c6687d
'Historicise' gauges on import
Tom Gottfried <tom@intevation.de>
parents:
3208
diff
changeset
|
84 FROM waterway.gauges_reference_water_levels grwl |
ec6163c6687d
'Historicise' gauges on import
Tom Gottfried <tom@intevation.de>
parents:
3208
diff
changeset
|
85 JOIN waterway.bottlenecks bns |
ec6163c6687d
'Historicise' gauges on import
Tom Gottfried <tom@intevation.de>
parents:
3208
diff
changeset
|
86 ON grwl.location = bns.gauge_location |
4700
a0c320d89682
FA diagram: take latest available LDC.
Sascha Wilde <wilde@intevation.de>
parents:
4354
diff
changeset
|
87 AND grwl.validity @> COALESCE(upper(bns.validity), current_timestamp) |
a0c320d89682
FA diagram: take latest available LDC.
Sascha Wilde <wilde@intevation.de>
parents:
4354
diff
changeset
|
88 WHERE lower(bns.validity) = (SELECT max(lower(validity)) |
a0c320d89682
FA diagram: take latest available LDC.
Sascha Wilde <wilde@intevation.de>
parents:
4354
diff
changeset
|
89 FROM waterway.bottlenecks WHERE objnam = $1) |
3666
db87f34805fb
Align bottleneck validity at gauges
Tom Gottfried <tom@intevation.de>
parents:
3645
diff
changeset
|
90 AND bns.objnam = $1 |
db87f34805fb
Align bottleneck validity at gauges
Tom Gottfried <tom@intevation.de>
parents:
3645
diff
changeset
|
91 AND grwl.depth_reference like 'LDC%' |
3119
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
92 ` |
2962
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 ) |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 |
2967
7c301ff449bc
Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2962
diff
changeset
|
95 type ( |
7c301ff449bc
Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2962
diff
changeset
|
96 availMeasurement struct { |
7c301ff449bc
Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2962
diff
changeset
|
97 when time.Time |
3392
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
98 depth int16 |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
99 width int16 |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
100 value int16 |
2967
7c301ff449bc
Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2962
diff
changeset
|
101 } |
3114
c68cef0346b7
Display Available Fairway Depths: Introduced type to re-use code from Available Fairway Depths vs. LNWL.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3076
diff
changeset
|
102 |
c68cef0346b7
Display Available Fairway Depths: Introduced type to re-use code from Available Fairway Depths vs. LNWL.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3076
diff
changeset
|
103 availMeasurements []availMeasurement |
2967
7c301ff449bc
Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2962
diff
changeset
|
104 ) |
7c301ff449bc
Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2962
diff
changeset
|
105 |
3118
4dcbf9e9013c
Added stub for GET /api/data/fairway-depth/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3117
diff
changeset
|
106 // afdRefs are the typical available fairway depth reference values. |
3424
0a666ba899fa
fairway availabilty: removed level from class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3412
diff
changeset
|
107 var afdRefs = []float64{ |
0a666ba899fa
fairway availabilty: removed level from class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3412
diff
changeset
|
108 230, |
0a666ba899fa
fairway availabilty: removed level from class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3412
diff
changeset
|
109 250, |
3118
4dcbf9e9013c
Added stub for GET /api/data/fairway-depth/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3117
diff
changeset
|
110 } |
4dcbf9e9013c
Added stub for GET /api/data/fairway-depth/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3117
diff
changeset
|
111 |
3114
c68cef0346b7
Display Available Fairway Depths: Introduced type to re-use code from Available Fairway Depths vs. LNWL.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3076
diff
changeset
|
112 func (measurement *availMeasurement) getDepth() float64 { |
c68cef0346b7
Display Available Fairway Depths: Introduced type to re-use code from Available Fairway Depths vs. LNWL.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3076
diff
changeset
|
113 return float64(measurement.depth) |
c68cef0346b7
Display Available Fairway Depths: Introduced type to re-use code from Available Fairway Depths vs. LNWL.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3076
diff
changeset
|
114 } |
c68cef0346b7
Display Available Fairway Depths: Introduced type to re-use code from Available Fairway Depths vs. LNWL.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3076
diff
changeset
|
115 |
c68cef0346b7
Display Available Fairway Depths: Introduced type to re-use code from Available Fairway Depths vs. LNWL.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3076
diff
changeset
|
116 func (measurement *availMeasurement) getValue() float64 { |
c68cef0346b7
Display Available Fairway Depths: Introduced type to re-use code from Available Fairway Depths vs. LNWL.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3076
diff
changeset
|
117 return float64(measurement.value) |
c68cef0346b7
Display Available Fairway Depths: Introduced type to re-use code from Available Fairway Depths vs. LNWL.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3076
diff
changeset
|
118 } |
c68cef0346b7
Display Available Fairway Depths: Introduced type to re-use code from Available Fairway Depths vs. LNWL.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3076
diff
changeset
|
119 |
3392
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
120 func (measurement *availMeasurement) getWidth() float64 { |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
121 return float64(measurement.width) |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
122 } |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
123 |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
124 func limitingFactor(limiting string) func(*availMeasurement) float64 { |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
125 switch limiting { |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
126 case "depth": |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
127 return (*availMeasurement).getDepth |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
128 case "width": |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
129 return (*availMeasurement).getWidth |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
130 default: |
3393
cf0b5274698a
Cosmetics: Forgot a newline in logging.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3392
diff
changeset
|
131 log.Printf("warn: unknown limitation '%s'. default to 'depth'\n", limiting) |
3392
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
132 return (*availMeasurement).getDepth |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
133 } |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
134 } |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
135 |
4343
63c25eb9c07c
FA: be optimistic about missing data.
Sascha Wilde <wilde@intevation.de>
parents:
4149
diff
changeset
|
136 // According to clarification, it has to be assumed, that at times |
63c25eb9c07c
FA: be optimistic about missing data.
Sascha Wilde <wilde@intevation.de>
parents:
4149
diff
changeset
|
137 // with no data, the best case (which by convention is the highest |
63c25eb9c07c
FA: be optimistic about missing data.
Sascha Wilde <wilde@intevation.de>
parents:
4149
diff
changeset
|
138 // class created by classify()) should be assumed. That is due to the |
4344
6ac94171a994
Fixed typos, tightened code removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4343
diff
changeset
|
139 // fact, that at times where bottlenecks are not a limiting factor on |
6ac94171a994
Fixed typos, tightened code removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4343
diff
changeset
|
140 // the waterway, services don't provide any data for the bottleneck in |
4343
63c25eb9c07c
FA: be optimistic about missing data.
Sascha Wilde <wilde@intevation.de>
parents:
4149
diff
changeset
|
141 // question. |
63c25eb9c07c
FA: be optimistic about missing data.
Sascha Wilde <wilde@intevation.de>
parents:
4149
diff
changeset
|
142 // |
4344
6ac94171a994
Fixed typos, tightened code removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4343
diff
changeset
|
143 // FIXME: A potential improvement could be to intersect the time |
4343
63c25eb9c07c
FA: be optimistic about missing data.
Sascha Wilde <wilde@intevation.de>
parents:
4149
diff
changeset
|
144 // ranges with the time ranges where bottlenecks were "active" (this |
4344
6ac94171a994
Fixed typos, tightened code removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4343
diff
changeset
|
145 // _might_ be derivable from the validity periods in the bottleneck |
4343
63c25eb9c07c
FA: be optimistic about missing data.
Sascha Wilde <wilde@intevation.de>
parents:
4149
diff
changeset
|
146 // data. So it _might_ be possible do detect actual missing data (BN |
63c25eb9c07c
FA: be optimistic about missing data.
Sascha Wilde <wilde@intevation.de>
parents:
4149
diff
changeset
|
147 // valid, but no data from FA service). Anyway, this is left out for |
4344
6ac94171a994
Fixed typos, tightened code removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4343
diff
changeset
|
148 // now, as many clarification regarding the base assumtions would be |
4343
63c25eb9c07c
FA: be optimistic about missing data.
Sascha Wilde <wilde@intevation.de>
parents:
4149
diff
changeset
|
149 // needed and the results still might be unrelyable. |
63c25eb9c07c
FA: be optimistic about missing data.
Sascha Wilde <wilde@intevation.de>
parents:
4149
diff
changeset
|
150 func optimisticPadClassification( |
63c25eb9c07c
FA: be optimistic about missing data.
Sascha Wilde <wilde@intevation.de>
parents:
4149
diff
changeset
|
151 from, to time.Time, |
63c25eb9c07c
FA: be optimistic about missing data.
Sascha Wilde <wilde@intevation.de>
parents:
4149
diff
changeset
|
152 classified []time.Duration, |
63c25eb9c07c
FA: be optimistic about missing data.
Sascha Wilde <wilde@intevation.de>
parents:
4149
diff
changeset
|
153 ) []time.Duration { |
4344
6ac94171a994
Fixed typos, tightened code removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4343
diff
changeset
|
154 |
4343
63c25eb9c07c
FA: be optimistic about missing data.
Sascha Wilde <wilde@intevation.de>
parents:
4149
diff
changeset
|
155 var actualDuration time.Duration |
4344
6ac94171a994
Fixed typos, tightened code removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4343
diff
changeset
|
156 for _, v := range classified { |
6ac94171a994
Fixed typos, tightened code removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4343
diff
changeset
|
157 actualDuration += v |
4343
63c25eb9c07c
FA: be optimistic about missing data.
Sascha Wilde <wilde@intevation.de>
parents:
4149
diff
changeset
|
158 } |
63c25eb9c07c
FA: be optimistic about missing data.
Sascha Wilde <wilde@intevation.de>
parents:
4149
diff
changeset
|
159 |
4344
6ac94171a994
Fixed typos, tightened code removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4343
diff
changeset
|
160 // If the actual duration is smaller than the length |
6ac94171a994
Fixed typos, tightened code removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4343
diff
changeset
|
161 // of the classifaction interval extend the |
6ac94171a994
Fixed typos, tightened code removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4343
diff
changeset
|
162 // time spend in the highest class by the difference. |
6ac94171a994
Fixed typos, tightened code removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4343
diff
changeset
|
163 if delta := to.Sub(from) - actualDuration; delta > 0 { |
6ac94171a994
Fixed typos, tightened code removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4343
diff
changeset
|
164 classified[len(classified)-1] += delta |
4343
63c25eb9c07c
FA: be optimistic about missing data.
Sascha Wilde <wilde@intevation.de>
parents:
4149
diff
changeset
|
165 } |
4344
6ac94171a994
Fixed typos, tightened code removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4343
diff
changeset
|
166 |
4343
63c25eb9c07c
FA: be optimistic about missing data.
Sascha Wilde <wilde@intevation.de>
parents:
4149
diff
changeset
|
167 return classified |
63c25eb9c07c
FA: be optimistic about missing data.
Sascha Wilde <wilde@intevation.de>
parents:
4149
diff
changeset
|
168 } |
63c25eb9c07c
FA: be optimistic about missing data.
Sascha Wilde <wilde@intevation.de>
parents:
4149
diff
changeset
|
169 |
3367
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
170 func (measurements availMeasurements) classify( |
2967
7c301ff449bc
Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2962
diff
changeset
|
171 from, to time.Time, |
3424
0a666ba899fa
fairway availabilty: removed level from class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3412
diff
changeset
|
172 breaks []float64, |
3040
a661e9b8f3b6
Fairway availability: 'virtualized' the field to classify.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3038
diff
changeset
|
173 access func(*availMeasurement) float64, |
2967
7c301ff449bc
Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2962
diff
changeset
|
174 ) []time.Duration { |
7c301ff449bc
Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2962
diff
changeset
|
175 |
3367
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
176 if len(breaks) == 0 { |
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
177 return []time.Duration{} |
3114
c68cef0346b7
Display Available Fairway Depths: Introduced type to re-use code from Available Fairway Depths vs. LNWL.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3076
diff
changeset
|
178 } |
c68cef0346b7
Display Available Fairway Depths: Introduced type to re-use code from Available Fairway Depths vs. LNWL.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3076
diff
changeset
|
179 |
3367
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
180 result := make([]time.Duration, len(breaks)+1) |
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
181 classes := make([]float64, len(breaks)+2) |
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
182 values := make([]time.Time, len(classes)) |
3027
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2967
diff
changeset
|
183 |
3367
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
184 // Add sentinels |
3424
0a666ba899fa
fairway availabilty: removed level from class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3412
diff
changeset
|
185 classes[0] = breaks[0] - 9999 |
0a666ba899fa
fairway availabilty: removed level from class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3412
diff
changeset
|
186 classes[len(classes)-1] = breaks[len(breaks)-1] + 9999 |
3367
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
187 for i := range breaks { |
3424
0a666ba899fa
fairway availabilty: removed level from class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3412
diff
changeset
|
188 classes[i+1] = breaks[i] |
2967
7c301ff449bc
Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2962
diff
changeset
|
189 } |
7c301ff449bc
Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2962
diff
changeset
|
190 |
3378
ff79a9b6707f
waterlevel classification: Re-enable finding a good starting points for classification intervals.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3374
diff
changeset
|
191 idx := sort.Search(len(measurements), func(i int) bool { |
ff79a9b6707f
waterlevel classification: Re-enable finding a good starting points for classification intervals.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3374
diff
changeset
|
192 // All values before from can be ignored. |
ff79a9b6707f
waterlevel classification: Re-enable finding a good starting points for classification intervals.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3374
diff
changeset
|
193 return !measurements[i].when.Before(from) |
ff79a9b6707f
waterlevel classification: Re-enable finding a good starting points for classification intervals.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3374
diff
changeset
|
194 }) |
ff79a9b6707f
waterlevel classification: Re-enable finding a good starting points for classification intervals.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3374
diff
changeset
|
195 |
ff79a9b6707f
waterlevel classification: Re-enable finding a good starting points for classification intervals.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3374
diff
changeset
|
196 if idx >= len(measurements) { |
4343
63c25eb9c07c
FA: be optimistic about missing data.
Sascha Wilde <wilde@intevation.de>
parents:
4149
diff
changeset
|
197 return optimisticPadClassification(from, to, result) |
3378
ff79a9b6707f
waterlevel classification: Re-enable finding a good starting points for classification intervals.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3374
diff
changeset
|
198 } |
ff79a9b6707f
waterlevel classification: Re-enable finding a good starting points for classification intervals.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3374
diff
changeset
|
199 |
ff79a9b6707f
waterlevel classification: Re-enable finding a good starting points for classification intervals.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3374
diff
changeset
|
200 // Be safe for interpolation. |
ff79a9b6707f
waterlevel classification: Re-enable finding a good starting points for classification intervals.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3374
diff
changeset
|
201 if idx > 0 { |
ff79a9b6707f
waterlevel classification: Re-enable finding a good starting points for classification intervals.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3374
diff
changeset
|
202 idx-- |
ff79a9b6707f
waterlevel classification: Re-enable finding a good starting points for classification intervals.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3374
diff
changeset
|
203 } |
ff79a9b6707f
waterlevel classification: Re-enable finding a good starting points for classification intervals.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3374
diff
changeset
|
204 |
ff79a9b6707f
waterlevel classification: Re-enable finding a good starting points for classification intervals.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3374
diff
changeset
|
205 measurements = measurements[idx:] |
3374
7d8c41cc50f5
Added TODO in waterlevel classifcation to find a good starting point.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3373
diff
changeset
|
206 |
2967
7c301ff449bc
Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2962
diff
changeset
|
207 for i := 0; i < len(measurements)-1; i++ { |
7c301ff449bc
Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2962
diff
changeset
|
208 p1 := &measurements[i] |
7c301ff449bc
Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2962
diff
changeset
|
209 p2 := &measurements[i+1] |
3027
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2967
diff
changeset
|
210 |
3367
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
211 if p1.when.After(to) { |
4343
63c25eb9c07c
FA: be optimistic about missing data.
Sascha Wilde <wilde@intevation.de>
parents:
4149
diff
changeset
|
212 return optimisticPadClassification(from, to, result) |
3367
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
213 } |
2967
7c301ff449bc
Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2962
diff
changeset
|
214 |
3367
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
215 if p2.when.Before(from) { |
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
216 continue |
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
217 } |
2967
7c301ff449bc
Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2962
diff
changeset
|
218 |
4860
de7aa9230837
Limit interpolation of time ranges for Available Fairway Depths to 1.5h.
Sascha Wilde <wilde@intevation.de>
parents:
4830
diff
changeset
|
219 if p2.when.Sub(p1.when).Hours() > 1.5 { |
4862 | 220 // Don't interpolate ranges bigger then one and a half hour |
4860
de7aa9230837
Limit interpolation of time ranges for Available Fairway Depths to 1.5h.
Sascha Wilde <wilde@intevation.de>
parents:
4830
diff
changeset
|
221 continue |
de7aa9230837
Limit interpolation of time ranges for Available Fairway Depths to 1.5h.
Sascha Wilde <wilde@intevation.de>
parents:
4830
diff
changeset
|
222 } |
de7aa9230837
Limit interpolation of time ranges for Available Fairway Depths to 1.5h.
Sascha Wilde <wilde@intevation.de>
parents:
4830
diff
changeset
|
223 |
3370
ac630f0f5dbf
Waterlevel classification: Handle case of same values in adjoint meassure dates correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3367
diff
changeset
|
224 lo, hi := maxTime(p1.when, from), minTime(p2.when, to) |
ac630f0f5dbf
Waterlevel classification: Handle case of same values in adjoint meassure dates correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3367
diff
changeset
|
225 |
ac630f0f5dbf
Waterlevel classification: Handle case of same values in adjoint meassure dates correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3367
diff
changeset
|
226 m1, m2 := access(p1), access(p2) |
ac630f0f5dbf
Waterlevel classification: Handle case of same values in adjoint meassure dates correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3367
diff
changeset
|
227 if m1 == m2 { // The whole interval is in only one class. |
ac630f0f5dbf
Waterlevel classification: Handle case of same values in adjoint meassure dates correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3367
diff
changeset
|
228 for j := 0; j < len(classes)-1; j++ { |
ac630f0f5dbf
Waterlevel classification: Handle case of same values in adjoint meassure dates correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3367
diff
changeset
|
229 if classes[j] <= m1 && m1 <= classes[j+1] { |
ac630f0f5dbf
Waterlevel classification: Handle case of same values in adjoint meassure dates correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3367
diff
changeset
|
230 result[j] += hi.Sub(lo) |
ac630f0f5dbf
Waterlevel classification: Handle case of same values in adjoint meassure dates correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3367
diff
changeset
|
231 break |
ac630f0f5dbf
Waterlevel classification: Handle case of same values in adjoint meassure dates correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3367
diff
changeset
|
232 } |
ac630f0f5dbf
Waterlevel classification: Handle case of same values in adjoint meassure dates correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3367
diff
changeset
|
233 } |
ac630f0f5dbf
Waterlevel classification: Handle case of same values in adjoint meassure dates correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3367
diff
changeset
|
234 continue |
ac630f0f5dbf
Waterlevel classification: Handle case of same values in adjoint meassure dates correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3367
diff
changeset
|
235 } |
ac630f0f5dbf
Waterlevel classification: Handle case of same values in adjoint meassure dates correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3367
diff
changeset
|
236 |
3367
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
237 f := common.InterpolateTime( |
3370
ac630f0f5dbf
Waterlevel classification: Handle case of same values in adjoint meassure dates correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3367
diff
changeset
|
238 p1.when, m1, |
ac630f0f5dbf
Waterlevel classification: Handle case of same values in adjoint meassure dates correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3367
diff
changeset
|
239 p2.when, m2, |
3367
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
240 ) |
3318
753e7c8e8c95
Fixed time interval handling in waterlevel classification
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3317
diff
changeset
|
241 |
3367
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
242 for j, c := range classes { |
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
243 values[j] = f(c) |
2967
7c301ff449bc
Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2962
diff
changeset
|
244 } |
3038
d47d289d6e68
Fairway availability: Fill classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3036
diff
changeset
|
245 |
3367
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
246 for j := 0; j < len(values)-1; j++ { |
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
247 start, end := orderTime(values[j], values[j+1]) |
3208
3bba82bcb6a6
Second fix to waterlevel classification. Set the bounds of the intervals correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3201
diff
changeset
|
248 |
3367
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
249 if start.After(hi) || end.Before(lo) { |
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
250 continue |
3038
d47d289d6e68
Fairway availability: Fill classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3036
diff
changeset
|
251 } |
3367
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
252 |
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
253 start, end = maxTime(start, lo), minTime(end, hi) |
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
254 result[j] += end.Sub(start) |
3038
d47d289d6e68
Fairway availability: Fill classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3036
diff
changeset
|
255 } |
2967
7c301ff449bc
Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2962
diff
changeset
|
256 } |
7c301ff449bc
Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2962
diff
changeset
|
257 |
4343
63c25eb9c07c
FA: be optimistic about missing data.
Sascha Wilde <wilde@intevation.de>
parents:
4149
diff
changeset
|
258 return optimisticPadClassification(from, to, result) |
3367
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
259 } |
3208
3bba82bcb6a6
Second fix to waterlevel classification. Set the bounds of the intervals correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3201
diff
changeset
|
260 |
3367
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
261 func orderTime(a, b time.Time) (time.Time, time.Time) { |
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
262 if a.Before(b) { |
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
263 return a, b |
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
264 } |
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
265 return b, a |
2967
7c301ff449bc
Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2962
diff
changeset
|
266 } |
7c301ff449bc
Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2962
diff
changeset
|
267 |
3337
146bf3a1752c
Fixed waterlevel classifications.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3329
diff
changeset
|
268 func minTime(a, b time.Time) time.Time { |
146bf3a1752c
Fixed waterlevel classifications.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3329
diff
changeset
|
269 if a.Before(b) { |
146bf3a1752c
Fixed waterlevel classifications.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3329
diff
changeset
|
270 return a |
146bf3a1752c
Fixed waterlevel classifications.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3329
diff
changeset
|
271 } |
146bf3a1752c
Fixed waterlevel classifications.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3329
diff
changeset
|
272 return b |
146bf3a1752c
Fixed waterlevel classifications.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3329
diff
changeset
|
273 } |
146bf3a1752c
Fixed waterlevel classifications.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3329
diff
changeset
|
274 |
146bf3a1752c
Fixed waterlevel classifications.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3329
diff
changeset
|
275 func maxTime(a, b time.Time) time.Time { |
146bf3a1752c
Fixed waterlevel classifications.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3329
diff
changeset
|
276 if a.After(b) { |
146bf3a1752c
Fixed waterlevel classifications.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3329
diff
changeset
|
277 return a |
146bf3a1752c
Fixed waterlevel classifications.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3329
diff
changeset
|
278 } |
146bf3a1752c
Fixed waterlevel classifications.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3329
diff
changeset
|
279 return b |
146bf3a1752c
Fixed waterlevel classifications.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3329
diff
changeset
|
280 } |
146bf3a1752c
Fixed waterlevel classifications.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3329
diff
changeset
|
281 |
3430
6994602d2935
fairway availibilty: Implemented for streches and sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3428
diff
changeset
|
282 func durationsToPercentage(duration time.Duration, classes []time.Duration) []float64 { |
3076
e0daeb05bf50
Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3040
diff
changeset
|
283 percents := make([]float64, len(classes)) |
3430
6994602d2935
fairway availibilty: Implemented for streches and sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3428
diff
changeset
|
284 total := 100 / duration.Seconds() |
3076
e0daeb05bf50
Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3040
diff
changeset
|
285 for i, v := range classes { |
e0daeb05bf50
Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3040
diff
changeset
|
286 percents[i] = v.Seconds() * total |
e0daeb05bf50
Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3040
diff
changeset
|
287 } |
e0daeb05bf50
Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3040
diff
changeset
|
288 return percents |
e0daeb05bf50
Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3040
diff
changeset
|
289 } |
e0daeb05bf50
Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3040
diff
changeset
|
290 |
3439
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
291 func parseFormTime( |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
292 rw http.ResponseWriter, |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
293 req *http.Request, |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
294 field string, |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
295 def time.Time, |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
296 ) (time.Time, bool) { |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
297 f := req.FormValue(field) |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
298 if f == "" { |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
299 return def.UTC(), true |
3115
524bc6545b20
Simplified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3114
diff
changeset
|
300 } |
4149
f543f9d4a0b5
Fairway avail controller for bottlenecks: Use common time parsing. An oversight from the timezone streamlining.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4073
diff
changeset
|
301 v, err := common.ParseTime(f) |
3439
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
302 if err != nil { |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
303 http.Error( |
4830
125cac3c977d
Don't reflect bad input back to client in availability controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4702
diff
changeset
|
304 rw, fmt.Sprintf("Invalid format for '%s'.", field), |
3439
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
305 http.StatusBadRequest, |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
306 ) |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
307 return time.Time{}, false |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
308 } |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
309 return v.UTC(), true |
3115
524bc6545b20
Simplified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3114
diff
changeset
|
310 } |
524bc6545b20
Simplified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3114
diff
changeset
|
311 |
3439
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
312 func parseFormInt( |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
313 rw http.ResponseWriter, |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
314 req *http.Request, |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
315 field string, |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
316 def int, |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
317 ) (int, bool) { |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
318 f := req.FormValue(field) |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
319 if f == "" { |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
320 return def, true |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
321 } |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
322 v, err := strconv.Atoi(f) |
3118
4dcbf9e9013c
Added stub for GET /api/data/fairway-depth/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3117
diff
changeset
|
323 if err != nil { |
3439
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
324 http.Error( |
4830
125cac3c977d
Don't reflect bad input back to client in availability controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4702
diff
changeset
|
325 rw, fmt.Sprintf("Invalid format for '%s'.", field), |
3439
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
326 http.StatusBadRequest, |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
327 ) |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
328 return 0, false |
3118
4dcbf9e9013c
Added stub for GET /api/data/fairway-depth/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3117
diff
changeset
|
329 } |
3439
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
330 return v, true |
3118
4dcbf9e9013c
Added stub for GET /api/data/fairway-depth/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3117
diff
changeset
|
331 } |
4dcbf9e9013c
Added stub for GET /api/data/fairway-depth/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3117
diff
changeset
|
332 |
3445
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
333 func intervalMode(mode string) int { |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
334 switch strings.ToLower(mode) { |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
335 case "monthly": |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
336 return 0 |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
337 case "quarterly": |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
338 return 1 |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
339 case "yearly": |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
340 return 2 |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
341 default: |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
342 return 0 |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
343 } |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
344 } |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
345 |
3116
ff0b9a94e0e4
Simpified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3115
diff
changeset
|
346 func loadDepthValues( |
ff0b9a94e0e4
Simpified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3115
diff
changeset
|
347 ctx context.Context, |
ff0b9a94e0e4
Simpified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3115
diff
changeset
|
348 conn *sql.Conn, |
ff0b9a94e0e4
Simpified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3115
diff
changeset
|
349 bottleneck string, |
ff0b9a94e0e4
Simpified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3115
diff
changeset
|
350 los int, |
ff0b9a94e0e4
Simpified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3115
diff
changeset
|
351 from, to time.Time, |
ff0b9a94e0e4
Simpified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3115
diff
changeset
|
352 ) (availMeasurements, error) { |
ff0b9a94e0e4
Simpified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3115
diff
changeset
|
353 |
ff0b9a94e0e4
Simpified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3115
diff
changeset
|
354 rows, err := conn.QueryContext( |
ff0b9a94e0e4
Simpified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3115
diff
changeset
|
355 ctx, selectAvailableDepthSQL, bottleneck, los, from, to) |
ff0b9a94e0e4
Simpified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3115
diff
changeset
|
356 if err != nil { |
ff0b9a94e0e4
Simpified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3115
diff
changeset
|
357 return nil, err |
ff0b9a94e0e4
Simpified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3115
diff
changeset
|
358 } |
ff0b9a94e0e4
Simpified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3115
diff
changeset
|
359 defer rows.Close() |
ff0b9a94e0e4
Simpified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3115
diff
changeset
|
360 |
ff0b9a94e0e4
Simpified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3115
diff
changeset
|
361 var ms availMeasurements |
ff0b9a94e0e4
Simpified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3115
diff
changeset
|
362 |
ff0b9a94e0e4
Simpified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3115
diff
changeset
|
363 for rows.Next() { |
ff0b9a94e0e4
Simpified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3115
diff
changeset
|
364 var m availMeasurement |
3392
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
365 if err := rows.Scan( |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
366 &m.when, |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
367 &m.depth, |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
368 &m.width, |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
369 &m.value, |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
370 ); err != nil { |
3116
ff0b9a94e0e4
Simpified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3115
diff
changeset
|
371 return nil, err |
ff0b9a94e0e4
Simpified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3115
diff
changeset
|
372 } |
ff0b9a94e0e4
Simpified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3115
diff
changeset
|
373 m.when = m.when.UTC() |
ff0b9a94e0e4
Simpified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3115
diff
changeset
|
374 ms = append(ms, m) |
ff0b9a94e0e4
Simpified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3115
diff
changeset
|
375 } |
ff0b9a94e0e4
Simpified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3115
diff
changeset
|
376 |
ff0b9a94e0e4
Simpified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3115
diff
changeset
|
377 if err := rows.Err(); err != nil { |
ff0b9a94e0e4
Simpified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3115
diff
changeset
|
378 return nil, err |
ff0b9a94e0e4
Simpified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3115
diff
changeset
|
379 } |
ff0b9a94e0e4
Simpified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3115
diff
changeset
|
380 |
ff0b9a94e0e4
Simpified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3115
diff
changeset
|
381 return ms, nil |
ff0b9a94e0e4
Simpified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3115
diff
changeset
|
382 } |
ff0b9a94e0e4
Simpified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3115
diff
changeset
|
383 |
3119
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
384 func loadLDCReferenceValue( |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
385 ctx context.Context, |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
386 conn *sql.Conn, |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
387 bottleneck string, |
3424
0a666ba899fa
fairway availabilty: removed level from class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3412
diff
changeset
|
388 ) ([]float64, error) { |
3119
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
389 var value float64 |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
390 err := conn.QueryRowContext(ctx, selectGaugeLDCSQL, bottleneck).Scan(&value) |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
391 switch { |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
392 case err == sql.ErrNoRows: |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
393 return nil, nil |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
394 case err != nil: |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
395 return nil, err |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
396 } |
3424
0a666ba899fa
fairway availabilty: removed level from class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3412
diff
changeset
|
397 return []float64{value}, nil |
3119
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
398 } |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
399 |
3424
0a666ba899fa
fairway availabilty: removed level from class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3412
diff
changeset
|
400 func breaksToReferenceValue(breaks string) []float64 { |
3385
e994565a59a1
waterlevel classification: Added 'breaks=<value 1>,<value 2>,...,<value n>' query parameter to set the class breaks for classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3378
diff
changeset
|
401 parts := strings.Split(breaks, ",") |
3424
0a666ba899fa
fairway availabilty: removed level from class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3412
diff
changeset
|
402 var values []float64 |
0a666ba899fa
fairway availabilty: removed level from class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3412
diff
changeset
|
403 |
3385
e994565a59a1
waterlevel classification: Added 'breaks=<value 1>,<value 2>,...,<value n>' query parameter to set the class breaks for classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3378
diff
changeset
|
404 for _, part := range parts { |
e994565a59a1
waterlevel classification: Added 'breaks=<value 1>,<value 2>,...,<value n>' query parameter to set the class breaks for classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3378
diff
changeset
|
405 part = strings.TrimSpace(part) |
e994565a59a1
waterlevel classification: Added 'breaks=<value 1>,<value 2>,...,<value n>' query parameter to set the class breaks for classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3378
diff
changeset
|
406 if v, err := strconv.ParseFloat(part, 64); err == nil { |
3424
0a666ba899fa
fairway availabilty: removed level from class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3412
diff
changeset
|
407 values = append(values, v) |
3385
e994565a59a1
waterlevel classification: Added 'breaks=<value 1>,<value 2>,...,<value n>' query parameter to set the class breaks for classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3378
diff
changeset
|
408 } |
e994565a59a1
waterlevel classification: Added 'breaks=<value 1>,<value 2>,...,<value n>' query parameter to set the class breaks for classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3378
diff
changeset
|
409 } |
3424
0a666ba899fa
fairway availabilty: removed level from class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3412
diff
changeset
|
410 |
0a666ba899fa
fairway availabilty: removed level from class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3412
diff
changeset
|
411 sort.Float64s(values) |
0a666ba899fa
fairway availabilty: removed level from class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3412
diff
changeset
|
412 |
0a666ba899fa
fairway availabilty: removed level from class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3412
diff
changeset
|
413 // dedup |
0a666ba899fa
fairway availabilty: removed level from class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3412
diff
changeset
|
414 for i := 1; i < len(values); { |
0a666ba899fa
fairway availabilty: removed level from class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3412
diff
changeset
|
415 if values[i-1] == values[i] { |
0a666ba899fa
fairway availabilty: removed level from class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3412
diff
changeset
|
416 copy(values[i:], values[i+1:]) |
0a666ba899fa
fairway availabilty: removed level from class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3412
diff
changeset
|
417 values = values[:len(values)-1] |
0a666ba899fa
fairway availabilty: removed level from class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3412
diff
changeset
|
418 } else { |
0a666ba899fa
fairway availabilty: removed level from class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3412
diff
changeset
|
419 i++ |
0a666ba899fa
fairway availabilty: removed level from class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3412
diff
changeset
|
420 } |
3385
e994565a59a1
waterlevel classification: Added 'breaks=<value 1>,<value 2>,...,<value n>' query parameter to set the class breaks for classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3378
diff
changeset
|
421 } |
3424
0a666ba899fa
fairway availabilty: removed level from class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3412
diff
changeset
|
422 return values |
3385
e994565a59a1
waterlevel classification: Added 'breaks=<value 1>,<value 2>,...,<value n>' query parameter to set the class breaks for classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3378
diff
changeset
|
423 } |
e994565a59a1
waterlevel classification: Added 'breaks=<value 1>,<value 2>,...,<value n>' query parameter to set the class breaks for classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3378
diff
changeset
|
424 |
3439
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
425 func bottleneckAvailabilty(rw http.ResponseWriter, req *http.Request) { |
3430
6994602d2935
fairway availibilty: Implemented for streches and sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3428
diff
changeset
|
426 |
3439
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
427 mode := intervalMode(req.FormValue("mode")) |
2962
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
428 bn := mux.Vars(req)["objnam"] |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
429 |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
430 if bn == "" { |
3439
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
431 http.Error( |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
432 rw, |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
433 "Missing objnam of bottleneck", |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
434 http.StatusBadRequest, |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
435 ) |
2962
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
436 return |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
437 } |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
438 |
3439
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
439 from, ok := parseFormTime(rw, req, "from", time.Now().AddDate(-1, 0, 0)) |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
440 if !ok { |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
441 return |
2962
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
442 } |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
443 |
3439
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
444 to, ok := parseFormTime(rw, req, "to", from.AddDate(1, 0, 0)) |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
445 if !ok { |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
446 return |
2962
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
447 } |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
448 |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
449 if to.Before(from) { |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
450 to, from = from, to |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
451 } |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
452 |
3439
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
453 los, ok := parseFormInt(rw, req, "los", 1) |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
454 if !ok { |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
455 return |
2962
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
456 } |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
457 |
3439
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
458 conn := middleware.GetDBConn(req) |
3076
e0daeb05bf50
Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3040
diff
changeset
|
459 ctx := req.Context() |
e0daeb05bf50
Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3040
diff
changeset
|
460 |
4702
ef21c1464843
FA: fix inconsistency in access to values of LDCs and limiting value.
Sascha Wilde <wilde@intevation.de>
parents:
4700
diff
changeset
|
461 var limiting string |
ef21c1464843
FA: fix inconsistency in access to values of LDCs and limiting value.
Sascha Wilde <wilde@intevation.de>
parents:
4700
diff
changeset
|
462 err := conn.QueryRowContext(ctx, selectLimitingSQL, bn).Scan(&limiting) |
ef21c1464843
FA: fix inconsistency in access to values of LDCs and limiting value.
Sascha Wilde <wilde@intevation.de>
parents:
4700
diff
changeset
|
463 switch { |
ef21c1464843
FA: fix inconsistency in access to values of LDCs and limiting value.
Sascha Wilde <wilde@intevation.de>
parents:
4700
diff
changeset
|
464 case err == sql.ErrNoRows: |
ef21c1464843
FA: fix inconsistency in access to values of LDCs and limiting value.
Sascha Wilde <wilde@intevation.de>
parents:
4700
diff
changeset
|
465 http.Error( |
ef21c1464843
FA: fix inconsistency in access to values of LDCs and limiting value.
Sascha Wilde <wilde@intevation.de>
parents:
4700
diff
changeset
|
466 rw, fmt.Sprintf("Unknown limitation for %s.", bn), |
ef21c1464843
FA: fix inconsistency in access to values of LDCs and limiting value.
Sascha Wilde <wilde@intevation.de>
parents:
4700
diff
changeset
|
467 http.StatusNotFound) |
ef21c1464843
FA: fix inconsistency in access to values of LDCs and limiting value.
Sascha Wilde <wilde@intevation.de>
parents:
4700
diff
changeset
|
468 return |
ef21c1464843
FA: fix inconsistency in access to values of LDCs and limiting value.
Sascha Wilde <wilde@intevation.de>
parents:
4700
diff
changeset
|
469 case err != nil: |
ef21c1464843
FA: fix inconsistency in access to values of LDCs and limiting value.
Sascha Wilde <wilde@intevation.de>
parents:
4700
diff
changeset
|
470 http.Error( |
ef21c1464843
FA: fix inconsistency in access to values of LDCs and limiting value.
Sascha Wilde <wilde@intevation.de>
parents:
4700
diff
changeset
|
471 rw, fmt.Sprintf("DB error: %v.", err), |
ef21c1464843
FA: fix inconsistency in access to values of LDCs and limiting value.
Sascha Wilde <wilde@intevation.de>
parents:
4700
diff
changeset
|
472 http.StatusInternalServerError) |
ef21c1464843
FA: fix inconsistency in access to values of LDCs and limiting value.
Sascha Wilde <wilde@intevation.de>
parents:
4700
diff
changeset
|
473 return |
ef21c1464843
FA: fix inconsistency in access to values of LDCs and limiting value.
Sascha Wilde <wilde@intevation.de>
parents:
4700
diff
changeset
|
474 } |
ef21c1464843
FA: fix inconsistency in access to values of LDCs and limiting value.
Sascha Wilde <wilde@intevation.de>
parents:
4700
diff
changeset
|
475 |
ef21c1464843
FA: fix inconsistency in access to values of LDCs and limiting value.
Sascha Wilde <wilde@intevation.de>
parents:
4700
diff
changeset
|
476 access := limitingFactor(limiting) |
ef21c1464843
FA: fix inconsistency in access to values of LDCs and limiting value.
Sascha Wilde <wilde@intevation.de>
parents:
4700
diff
changeset
|
477 |
3439
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
478 ldcRefs, err := loadLDCReferenceValue(ctx, conn, bn) |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
479 if err != nil { |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
480 http.Error( |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
481 rw, |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
482 fmt.Sprintf("Internal server error: %v", err), |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
483 http.StatusInternalServerError, |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
484 ) |
3076
e0daeb05bf50
Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3040
diff
changeset
|
485 return |
e0daeb05bf50
Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3040
diff
changeset
|
486 } |
e0daeb05bf50
Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3040
diff
changeset
|
487 |
3412
5e284f39a081
fairway availibility: Reduce defaults to 230 and 250 as class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3405
diff
changeset
|
488 if len(ldcRefs) == 0 { |
3439
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
489 http.Error( |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
490 rw, |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
491 "No gauge reference values found for bottleneck", |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
492 http.StatusNotFound, |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
493 ) |
3116
ff0b9a94e0e4
Simpified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3115
diff
changeset
|
494 return |
2962
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
495 } |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
496 |
3445
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
497 var breaks []float64 |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
498 if b := req.FormValue("breaks"); b != "" { |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
499 breaks = breaksToReferenceValue(b) |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
500 } else { |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
501 breaks = afdRefs |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
502 } |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
503 |
3430
6994602d2935
fairway availibilty: Implemented for streches and sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3428
diff
changeset
|
504 log.Printf("info: time interval: (%v - %v)\n", from, to) |
6994602d2935
fairway availibilty: Implemented for streches and sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3428
diff
changeset
|
505 |
3114
c68cef0346b7
Display Available Fairway Depths: Introduced type to re-use code from Available Fairway Depths vs. LNWL.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3076
diff
changeset
|
506 var ms availMeasurements |
3116
ff0b9a94e0e4
Simpified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3115
diff
changeset
|
507 if ms, err = loadDepthValues(ctx, conn, bn, los, from, to); err != nil { |
2962
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
508 return |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
509 } |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
510 |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
511 if len(ms) == 0 { |
3439
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
512 http.Error( |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
513 rw, |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
514 "No available fairway depth values found", |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
515 http.StatusNotFound, |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
516 ) |
2962
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
517 return |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
518 } |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
519 |
3445
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
520 rw.Header().Add("Content-Type", "text/csv") |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
521 |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
522 out := csv.NewWriter(rw) |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
523 |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
524 record := make([]string, 1+2+len(breaks)+1) |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
525 record[0] = "#time" |
4354
e357730c090a
FA: Fixed units in csv headers.
Sascha Wilde <wilde@intevation.de>
parents:
4353
diff
changeset
|
526 record[1] = fmt.Sprintf("# < LDC (%.1f) [%%]", ldcRefs[0]) |
e357730c090a
FA: Fixed units in csv headers.
Sascha Wilde <wilde@intevation.de>
parents:
4353
diff
changeset
|
527 record[2] = fmt.Sprintf("# >= LDC (%.1f) [%%]", ldcRefs[0]) |
3445
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
528 for i, v := range breaks { |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
529 if i == 0 { |
3455
188b55ef814f
Slightly improved generated CSV headers, also used as legend by client.
Sascha Wilde <wilde@intevation.de>
parents:
3445
diff
changeset
|
530 record[3] = fmt.Sprintf("#d < %.1f [%%]", v) |
3445
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
531 } |
3455
188b55ef814f
Slightly improved generated CSV headers, also used as legend by client.
Sascha Wilde <wilde@intevation.de>
parents:
3445
diff
changeset
|
532 record[i+4] = fmt.Sprintf("#d >= %.1f [%%]", v) |
3445
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
533 } |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
534 |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
535 if err := out.Write(record); err != nil { |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
536 // Too late for HTTP status message. |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
537 log.Printf("error: %v\n", err) |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
538 return |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
539 } |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
540 |
3439
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
541 interval := intervals[mode](from, to) |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
542 |
4343
63c25eb9c07c
FA: be optimistic about missing data.
Sascha Wilde <wilde@intevation.de>
parents:
4149
diff
changeset
|
543 now := time.Now() |
3439
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
544 for pfrom, pto, label := interval(); label != ""; pfrom, pto, label = interval() { |
4343
63c25eb9c07c
FA: be optimistic about missing data.
Sascha Wilde <wilde@intevation.de>
parents:
4149
diff
changeset
|
545 // Don't interpolate for the future |
63c25eb9c07c
FA: be optimistic about missing data.
Sascha Wilde <wilde@intevation.de>
parents:
4149
diff
changeset
|
546 if now.Sub(pto) < 0 { |
63c25eb9c07c
FA: be optimistic about missing data.
Sascha Wilde <wilde@intevation.de>
parents:
4149
diff
changeset
|
547 pto = now |
63c25eb9c07c
FA: be optimistic about missing data.
Sascha Wilde <wilde@intevation.de>
parents:
4149
diff
changeset
|
548 } |
63c25eb9c07c
FA: be optimistic about missing data.
Sascha Wilde <wilde@intevation.de>
parents:
4149
diff
changeset
|
549 |
3439
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
550 lnwl := ms.classify( |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
551 pfrom, pto, |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
552 ldcRefs, |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
553 (*availMeasurement).getValue, |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
554 ) |
3038
d47d289d6e68
Fairway availability: Fill classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3036
diff
changeset
|
555 |
3439
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
556 afd := ms.classify( |
3468
850e81f13e96
fairway availibility: Fixed time interval for line.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3455
diff
changeset
|
557 pfrom, pto, |
3439
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
558 breaks, |
4702
ef21c1464843
FA: fix inconsistency in access to values of LDCs and limiting value.
Sascha Wilde <wilde@intevation.de>
parents:
4700
diff
changeset
|
559 access, |
3439
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
560 ) |
3076
e0daeb05bf50
Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3040
diff
changeset
|
561 |
3439
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
562 duration := pto.Sub(pfrom) |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
563 lnwlPercents := durationsToPercentage(duration, lnwl) |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
564 afdPercents := durationsToPercentage(duration, afd) |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
565 |
3445
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
566 record[0] = label |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
567 for i, v := range lnwlPercents { |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
568 record[1+i] = fmt.Sprintf("%.3f", v) |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
569 } |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
570 for i, v := range afdPercents { |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
571 record[3+i] = fmt.Sprintf("%.3f", v) |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
572 } |
3076
e0daeb05bf50
Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3040
diff
changeset
|
573 |
3445
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
574 if err := out.Write(record); err != nil { |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
575 // Too late for HTTP status message. |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
576 log.Printf("error: %v\n", err) |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
577 return |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
578 } |
2962
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
579 } |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
580 |
3445
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
581 out.Flush() |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
582 if err := out.Error(); err != nil { |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
583 // Too late for HTTP status message. |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
584 log.Printf("error: %v\n", err) |
2962
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
585 } |
8d825551bc72
Fairway availibity for bottlenecks: Started with fetchting the relevant data. TODO: Range calculations. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
586 } |
3118
4dcbf9e9013c
Added stub for GET /api/data/fairway-depth/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3117
diff
changeset
|
587 |
3119
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
588 func bottleneckAvailableFairwayDepth(rw http.ResponseWriter, req *http.Request) { |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
589 |
3405
2b5c22f6bb1f
available fairway depth: Implemented backend for sections and stretches.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3393
diff
changeset
|
590 mode := intervalMode(req.FormValue("mode")) |
2b5c22f6bb1f
available fairway depth: Implemented backend for sections and stretches.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3393
diff
changeset
|
591 |
3118
4dcbf9e9013c
Added stub for GET /api/data/fairway-depth/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3117
diff
changeset
|
592 bn := mux.Vars(req)["objnam"] |
4dcbf9e9013c
Added stub for GET /api/data/fairway-depth/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3117
diff
changeset
|
593 if bn == "" { |
3119
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
594 http.Error( |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
595 rw, "Missing objnam of bottleneck", |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
596 http.StatusBadRequest) |
3118
4dcbf9e9013c
Added stub for GET /api/data/fairway-depth/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3117
diff
changeset
|
597 return |
4dcbf9e9013c
Added stub for GET /api/data/fairway-depth/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3117
diff
changeset
|
598 } |
4dcbf9e9013c
Added stub for GET /api/data/fairway-depth/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3117
diff
changeset
|
599 |
3439
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
600 from, ok := parseFormTime(rw, req, "from", time.Now().AddDate(-1, 0, 0)) |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
601 if !ok { |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
602 return |
3118
4dcbf9e9013c
Added stub for GET /api/data/fairway-depth/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3117
diff
changeset
|
603 } |
4dcbf9e9013c
Added stub for GET /api/data/fairway-depth/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3117
diff
changeset
|
604 |
3439
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
605 to, ok := parseFormTime(rw, req, "to", from.AddDate(1, 0, 0)) |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
606 if !ok { |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
607 return |
3118
4dcbf9e9013c
Added stub for GET /api/data/fairway-depth/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3117
diff
changeset
|
608 } |
4dcbf9e9013c
Added stub for GET /api/data/fairway-depth/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3117
diff
changeset
|
609 |
4dcbf9e9013c
Added stub for GET /api/data/fairway-depth/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3117
diff
changeset
|
610 if to.Before(from) { |
4dcbf9e9013c
Added stub for GET /api/data/fairway-depth/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3117
diff
changeset
|
611 to, from = from, to |
4dcbf9e9013c
Added stub for GET /api/data/fairway-depth/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3117
diff
changeset
|
612 } |
4dcbf9e9013c
Added stub for GET /api/data/fairway-depth/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3117
diff
changeset
|
613 |
3439
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
614 los, ok := parseFormInt(rw, req, "los", 1) |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
615 if !ok { |
d7ddb21f7017
Prepared to write the fairway availibilty as CSV, too. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3430
diff
changeset
|
616 return |
3118
4dcbf9e9013c
Added stub for GET /api/data/fairway-depth/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3117
diff
changeset
|
617 } |
4dcbf9e9013c
Added stub for GET /api/data/fairway-depth/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3117
diff
changeset
|
618 |
3119
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
619 conn := middleware.GetDBConn(req) |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
620 ctx := req.Context() |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
621 |
3392
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
622 var limiting string |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
623 err := conn.QueryRowContext(ctx, selectLimitingSQL, bn).Scan(&limiting) |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
624 switch { |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
625 case err == sql.ErrNoRows: |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
626 http.Error( |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
627 rw, fmt.Sprintf("Unknown limitation for %s.", bn), |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
628 http.StatusNotFound) |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
629 return |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
630 case err != nil: |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
631 http.Error( |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
632 rw, fmt.Sprintf("DB error: %v.", err), |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
633 http.StatusInternalServerError) |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
634 return |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
635 } |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
636 |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
637 access := limitingFactor(limiting) |
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
638 |
3405
2b5c22f6bb1f
available fairway depth: Implemented backend for sections and stretches.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3393
diff
changeset
|
639 log.Printf("info: time interval: (%v - %v)\n", from, to) |
2b5c22f6bb1f
available fairway depth: Implemented backend for sections and stretches.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3393
diff
changeset
|
640 |
3119
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
641 // load the measurements |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
642 ms, err := loadDepthValues(ctx, conn, bn, los, from, to) |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
643 if err != nil { |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
644 http.Error( |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
645 rw, fmt.Sprintf("Loading measurements failed: %v.", err), |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
646 http.StatusInternalServerError) |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
647 return |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
648 } |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
649 |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
650 ldcRefs, err := loadLDCReferenceValue(ctx, conn, bn) |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
651 if err != nil { |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
652 http.Error( |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
653 rw, fmt.Sprintf("Loading LDC failed: %v.", err), |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
654 http.StatusInternalServerError) |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
655 return |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
656 } |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
657 if len(ldcRefs) == 0 { |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
658 http.Error(rw, "No LDC found", http.StatusNotFound) |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
659 return |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
660 } |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
661 |
3424
0a666ba899fa
fairway availabilty: removed level from class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3412
diff
changeset
|
662 var breaks []float64 |
3385
e994565a59a1
waterlevel classification: Added 'breaks=<value 1>,<value 2>,...,<value n>' query parameter to set the class breaks for classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3378
diff
changeset
|
663 if b := req.FormValue("breaks"); b != "" { |
e994565a59a1
waterlevel classification: Added 'breaks=<value 1>,<value 2>,...,<value n>' query parameter to set the class breaks for classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3378
diff
changeset
|
664 breaks = breaksToReferenceValue(b) |
e994565a59a1
waterlevel classification: Added 'breaks=<value 1>,<value 2>,...,<value n>' query parameter to set the class breaks for classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3378
diff
changeset
|
665 } else { |
e994565a59a1
waterlevel classification: Added 'breaks=<value 1>,<value 2>,...,<value n>' query parameter to set the class breaks for classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3378
diff
changeset
|
666 breaks = afdRefs |
e994565a59a1
waterlevel classification: Added 'breaks=<value 1>,<value 2>,...,<value n>' query parameter to set the class breaks for classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3378
diff
changeset
|
667 } |
e994565a59a1
waterlevel classification: Added 'breaks=<value 1>,<value 2>,...,<value n>' query parameter to set the class breaks for classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3378
diff
changeset
|
668 |
3119
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
669 rw.Header().Add("Content-Type", "text/csv") |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
670 |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
671 out := csv.NewWriter(rw) |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
672 |
3445
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
673 // label, ldc, classes |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
674 record := make([]string, 1+2+len(breaks)+1) |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
675 record[0] = "#time" |
4353
97312d7954ba
FA diagrams: round to full days in back end.
Sascha Wilde <wilde@intevation.de>
parents:
4344
diff
changeset
|
676 record[1] = fmt.Sprintf("# < LDC (%.1f) [d]", ldcRefs[0]) |
97312d7954ba
FA diagrams: round to full days in back end.
Sascha Wilde <wilde@intevation.de>
parents:
4344
diff
changeset
|
677 record[2] = fmt.Sprintf("# >= LDC (%.1f) [d]", ldcRefs[0]) |
3385
e994565a59a1
waterlevel classification: Added 'breaks=<value 1>,<value 2>,...,<value n>' query parameter to set the class breaks for classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3378
diff
changeset
|
678 for i, v := range breaks { |
3119
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
679 if i == 0 { |
4353
97312d7954ba
FA diagrams: round to full days in back end.
Sascha Wilde <wilde@intevation.de>
parents:
4344
diff
changeset
|
680 record[3] = fmt.Sprintf("# < %.1f [d]", v) |
3119
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
681 } |
4353
97312d7954ba
FA diagrams: round to full days in back end.
Sascha Wilde <wilde@intevation.de>
parents:
4344
diff
changeset
|
682 record[i+4] = fmt.Sprintf("# >= %.1f [d]", v) |
3119
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
683 } |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
684 |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
685 if err := out.Write(record); err != nil { |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
686 // Too late for HTTP status message. |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
687 log.Printf("error: %v\n", err) |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
688 return |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
689 } |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
690 |
3367
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
691 //log.Println(len(ms)) |
3201
d5294f1a4ad4
First fix for waterlevel classifications.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3133
diff
changeset
|
692 //for i := range ms { |
d5294f1a4ad4
First fix for waterlevel classifications.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3133
diff
changeset
|
693 // log.Println(ms[i].when, ms[i].depth) |
d5294f1a4ad4
First fix for waterlevel classifications.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3133
diff
changeset
|
694 //} |
d5294f1a4ad4
First fix for waterlevel classifications.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3133
diff
changeset
|
695 |
3367
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
696 log.Printf("info: measurements: %d\n", len(ms)) |
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
697 if len(ms) > 1 { |
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
698 log.Printf("info: first: %v\n", ms[0].when) |
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
699 log.Printf("info: last: %v\n", ms[len(ms)-1].when) |
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
700 log.Printf("info: interval: %.2f [h]\n", ms[len(ms)-1].when.Sub(ms[0].when).Hours()) |
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
701 } |
3119
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
702 |
3367
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
703 interval := intervals[mode](from, to) |
3201
d5294f1a4ad4
First fix for waterlevel classifications.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3133
diff
changeset
|
704 |
4343
63c25eb9c07c
FA: be optimistic about missing data.
Sascha Wilde <wilde@intevation.de>
parents:
4149
diff
changeset
|
705 now := time.Now() |
3119
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
706 for pfrom, pto, label := interval(); label != ""; pfrom, pto, label = interval() { |
4343
63c25eb9c07c
FA: be optimistic about missing data.
Sascha Wilde <wilde@intevation.de>
parents:
4149
diff
changeset
|
707 // Don't interpolate for the future |
63c25eb9c07c
FA: be optimistic about missing data.
Sascha Wilde <wilde@intevation.de>
parents:
4149
diff
changeset
|
708 if now.Sub(pto) < 0 { |
63c25eb9c07c
FA: be optimistic about missing data.
Sascha Wilde <wilde@intevation.de>
parents:
4149
diff
changeset
|
709 pto = now |
63c25eb9c07c
FA: be optimistic about missing data.
Sascha Wilde <wilde@intevation.de>
parents:
4149
diff
changeset
|
710 } |
3119
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
711 |
3445
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
712 ldc := ms.classify( |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
713 pfrom, pto, |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
714 ldcRefs, |
4702
ef21c1464843
FA: fix inconsistency in access to values of LDCs and limiting value.
Sascha Wilde <wilde@intevation.de>
parents:
4700
diff
changeset
|
715 (*availMeasurement).getValue, |
3445
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
716 ) |
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
717 |
3367
ecb4baa2be1a
Simplified waterlevel classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3337
diff
changeset
|
718 ranges := ms.classify( |
3119
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
719 pfrom, pto, |
3385
e994565a59a1
waterlevel classification: Added 'breaks=<value 1>,<value 2>,...,<value n>' query parameter to set the class breaks for classification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3378
diff
changeset
|
720 breaks, |
3392
96d3af15fc28
available fairway depth: Decide if width or depth is critial by looking at the bottleneck limiting factor.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3385
diff
changeset
|
721 access, |
3119
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
722 ) |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
723 |
4353
97312d7954ba
FA diagrams: round to full days in back end.
Sascha Wilde <wilde@intevation.de>
parents:
4344
diff
changeset
|
724 // Round to full days |
97312d7954ba
FA diagrams: round to full days in back end.
Sascha Wilde <wilde@intevation.de>
parents:
4344
diff
changeset
|
725 ldcRounded := common.RoundToFullDays(ldc) |
97312d7954ba
FA diagrams: round to full days in back end.
Sascha Wilde <wilde@intevation.de>
parents:
4344
diff
changeset
|
726 rangesRounded := common.RoundToFullDays(ranges) |
97312d7954ba
FA diagrams: round to full days in back end.
Sascha Wilde <wilde@intevation.de>
parents:
4344
diff
changeset
|
727 |
3119
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
728 record[0] = label |
4353
97312d7954ba
FA diagrams: round to full days in back end.
Sascha Wilde <wilde@intevation.de>
parents:
4344
diff
changeset
|
729 for i, v := range ldcRounded { |
97312d7954ba
FA diagrams: round to full days in back end.
Sascha Wilde <wilde@intevation.de>
parents:
4344
diff
changeset
|
730 record[i+1] = fmt.Sprintf("%d", v) |
3445
e07b18f2482e
Write fairway-depth as CSV, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
731 } |
3119
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
732 |
4353
97312d7954ba
FA diagrams: round to full days in back end.
Sascha Wilde <wilde@intevation.de>
parents:
4344
diff
changeset
|
733 for i, d := range rangesRounded { |
97312d7954ba
FA diagrams: round to full days in back end.
Sascha Wilde <wilde@intevation.de>
parents:
4344
diff
changeset
|
734 record[3+i] = fmt.Sprintf("%d", d) |
3119
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
735 } |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
736 |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
737 if err := out.Write(record); err != nil { |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
738 // Too late for HTTP status message. |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
739 log.Printf("error: %v\n", err) |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
740 return |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
741 } |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
742 } |
3118
4dcbf9e9013c
Added stub for GET /api/data/fairway-depth/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3117
diff
changeset
|
743 |
3119
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
744 out.Flush() |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
745 if err := out.Error(); err != nil { |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
746 // Too late for HTTP status message. |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
747 log.Printf("error: %v\n", err) |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
748 } |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
749 } |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
750 |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
751 var intervals = []func(time.Time, time.Time) func() (time.Time, time.Time, string){ |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
752 monthly, |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
753 quarterly, |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
754 yearly, |
3118
4dcbf9e9013c
Added stub for GET /api/data/fairway-depth/{gauge}
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3117
diff
changeset
|
755 } |
3119
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
756 |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
757 func monthly(from, to time.Time) func() (time.Time, time.Time, string) { |
3122
3dffeb6df4a3
Display Available Fairway Depths: Implemented monthly, quarterly and yearly stepping through the measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3119
diff
changeset
|
758 pfrom := from |
3119
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
759 return func() (time.Time, time.Time, string) { |
3122
3dffeb6df4a3
Display Available Fairway Depths: Implemented monthly, quarterly and yearly stepping through the measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3119
diff
changeset
|
760 if pfrom.After(to) { |
3dffeb6df4a3
Display Available Fairway Depths: Implemented monthly, quarterly and yearly stepping through the measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3119
diff
changeset
|
761 return time.Time{}, time.Time{}, "" |
3dffeb6df4a3
Display Available Fairway Depths: Implemented monthly, quarterly and yearly stepping through the measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3119
diff
changeset
|
762 } |
3dffeb6df4a3
Display Available Fairway Depths: Implemented monthly, quarterly and yearly stepping through the measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3119
diff
changeset
|
763 f := pfrom |
3dffeb6df4a3
Display Available Fairway Depths: Implemented monthly, quarterly and yearly stepping through the measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3119
diff
changeset
|
764 pfrom = pfrom.AddDate(0, 1, 0) |
3133
7b4092b6b51a
Fairway availability depth: Fixed SQL statement.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3122
diff
changeset
|
765 label := fmt.Sprintf("%02d-%d", f.Month(), f.Year()) |
3122
3dffeb6df4a3
Display Available Fairway Depths: Implemented monthly, quarterly and yearly stepping through the measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3119
diff
changeset
|
766 return f, f.AddDate(0, 1, 0).Add(-time.Nanosecond), label |
3119
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
767 } |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
768 } |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
769 |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
770 func quarterly(from, to time.Time) func() (time.Time, time.Time, string) { |
3122
3dffeb6df4a3
Display Available Fairway Depths: Implemented monthly, quarterly and yearly stepping through the measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3119
diff
changeset
|
771 pfrom := from |
3119
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
772 return func() (time.Time, time.Time, string) { |
3122
3dffeb6df4a3
Display Available Fairway Depths: Implemented monthly, quarterly and yearly stepping through the measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3119
diff
changeset
|
773 if pfrom.After(to) { |
3dffeb6df4a3
Display Available Fairway Depths: Implemented monthly, quarterly and yearly stepping through the measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3119
diff
changeset
|
774 return time.Time{}, time.Time{}, "" |
3dffeb6df4a3
Display Available Fairway Depths: Implemented monthly, quarterly and yearly stepping through the measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3119
diff
changeset
|
775 } |
3dffeb6df4a3
Display Available Fairway Depths: Implemented monthly, quarterly and yearly stepping through the measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3119
diff
changeset
|
776 f := pfrom |
3dffeb6df4a3
Display Available Fairway Depths: Implemented monthly, quarterly and yearly stepping through the measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3119
diff
changeset
|
777 pfrom = pfrom.AddDate(0, 3, 0) |
3373
27aca46771b5
Waterlevel calculation: fixed labels of quarters (again).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3372
diff
changeset
|
778 label := fmt.Sprintf("Q%d-%d", (int(f.Month())-1)/3+1, f.Year()) |
3122
3dffeb6df4a3
Display Available Fairway Depths: Implemented monthly, quarterly and yearly stepping through the measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3119
diff
changeset
|
779 return f, f.AddDate(0, 3, 0).Add(-time.Nanosecond), label |
3119
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
780 } |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
781 } |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
782 |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
783 func yearly(from, to time.Time) func() (time.Time, time.Time, string) { |
3122
3dffeb6df4a3
Display Available Fairway Depths: Implemented monthly, quarterly and yearly stepping through the measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3119
diff
changeset
|
784 pfrom := from |
3119
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
785 return func() (time.Time, time.Time, string) { |
3122
3dffeb6df4a3
Display Available Fairway Depths: Implemented monthly, quarterly and yearly stepping through the measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3119
diff
changeset
|
786 if pfrom.After(to) { |
3dffeb6df4a3
Display Available Fairway Depths: Implemented monthly, quarterly and yearly stepping through the measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3119
diff
changeset
|
787 return time.Time{}, time.Time{}, "" |
3dffeb6df4a3
Display Available Fairway Depths: Implemented monthly, quarterly and yearly stepping through the measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3119
diff
changeset
|
788 } |
3dffeb6df4a3
Display Available Fairway Depths: Implemented monthly, quarterly and yearly stepping through the measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3119
diff
changeset
|
789 f := pfrom |
3dffeb6df4a3
Display Available Fairway Depths: Implemented monthly, quarterly and yearly stepping through the measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3119
diff
changeset
|
790 pfrom = pfrom.AddDate(1, 0, 0) |
3133
7b4092b6b51a
Fairway availability depth: Fixed SQL statement.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3122
diff
changeset
|
791 label := fmt.Sprintf("%d", f.Year()) |
3122
3dffeb6df4a3
Display Available Fairway Depths: Implemented monthly, quarterly and yearly stepping through the measurements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3119
diff
changeset
|
792 return f, f.AddDate(1, 0, 0).Add(-time.Nanosecond), label |
3119
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
793 } |
ad5a00ccd276
Display Available Fairway Depths: More controller code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3118
diff
changeset
|
794 } |