annotate pkg/controllers/bottlenecks.go @ 3115:524bc6545b20

Simplified code.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 28 Apr 2019 21:29:41 +0200
parents c68cef0346b7
children ff0b9a94e0e4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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>
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
13
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 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
15
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 import (
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 "database/sql"
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
18 "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
19 "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
20 "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
21 "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
22 "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
23 "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
24 "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
25
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 "gemma.intevation.de/gemma/pkg/common"
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 "github.com/gorilla/mux"
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 )
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
29
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
30 const (
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 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
32 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
33 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
34 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
35 efa.available_depth_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
36 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
37 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
38 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
39 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
40 JOIN waterway.bottlenecks bn
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 ON fa.bottleneck_id = bn.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
42 WHERE
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 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
44 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
45 efa.measure_type = 'Measured' 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
46 efa.available_depth_value IS NOT NULL 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
47 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
48 ),
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 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
50 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
51 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
52 ),
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 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
54 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
55 ),
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 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
57 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
58 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
59 )
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 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
61 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
62 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
63 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
64 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
65 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
66 `
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
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 selectGaugeLevelsSQL = `
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 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
70 grwl.depth_reference,
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 grwl.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
72 FROM waterway.gauges_reference_water_levels grwl JOIN
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 waterway.bottlenecks bns
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 ON bns.fk_g_fid = grwl.gauge_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
75 WHERE bns.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
76 grwl.depth_reference like 'HDC%' OR
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 grwl.depth_reference like 'LDC%' OR
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 grwl.depth_reference like 'MW%'
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 `
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
81 )
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
82
2967
7c301ff449bc Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2962
diff changeset
83 type (
3076
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
84 referenceValue struct {
2967
7c301ff449bc Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2962
diff changeset
85 level int
3040
a661e9b8f3b6 Fairway availability: 'virtualized' the field to classify.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3038
diff changeset
86 value float64
2967
7c301ff449bc Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2962
diff changeset
87 }
7c301ff449bc Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2962
diff changeset
88
7c301ff449bc Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2962
diff changeset
89 availMeasurement struct {
7c301ff449bc Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2962
diff changeset
90 when time.Time
7c301ff449bc Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2962
diff changeset
91 depth int
7c301ff449bc Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2962
diff changeset
92 value int
7c301ff449bc Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2962
diff changeset
93 }
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
94
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
95 availMeasurements []availMeasurement
2967
7c301ff449bc Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2962
diff changeset
96 )
7c301ff449bc Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2962
diff changeset
97
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
98 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
99 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
100 }
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
101
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 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
103 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
104 }
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
105
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
106 func (measurements availMeasurements) classifyAvailMeasurements(
2967
7c301ff449bc Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2962
diff changeset
107 from, to time.Time,
3076
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
108 classes []referenceValue,
3040
a661e9b8f3b6 Fairway availability: 'virtualized' the field to classify.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3038
diff changeset
109 access func(*availMeasurement) float64,
2967
7c301ff449bc Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2962
diff changeset
110 ) []time.Duration {
7c301ff449bc Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2962
diff changeset
111
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
112 type classValues struct {
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
113 when time.Time
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
114 kind common.ValueRangeKind
2967
7c301ff449bc Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2962
diff changeset
115 }
7c301ff449bc Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2962
diff changeset
116
3038
d47d289d6e68 Fairway availability: Fill classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3036
diff changeset
117 //var invalid time.Duration
d47d289d6e68 Fairway availability: Fill classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3036
diff changeset
118 result := make([]time.Duration, len(classes)+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
119
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
120 if len(measurements) == 0 ||
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
121 to.Before(measurements[0].when) ||
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
122 from.After(measurements[len(measurements)-1].when) {
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
123 return result
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
124 }
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
125
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
126 cvs := make([]classValues, len(classes))
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
127
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
128 classify := func(v func(float64) (time.Time, common.ValueRangeKind)) {
3038
d47d289d6e68 Fairway availability: Fill classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3036
diff changeset
129 for i := range classes {
3040
a661e9b8f3b6 Fairway availability: 'virtualized' the field to classify.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3038
diff changeset
130 cvs[i].when, cvs[i].kind = v(classes[i].value)
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
131 }
2967
7c301ff449bc Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2962
diff changeset
132 }
7c301ff449bc Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2962
diff changeset
133
3036
7f12a87c56ff Fairway availability: Set boundaries of segments correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3027
diff changeset
134 vbt := func(p1, p2 *availMeasurement) func(time.Time) (float64, common.ValueRangeKind) {
3040
a661e9b8f3b6 Fairway availability: 'virtualized' the field to classify.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3038
diff changeset
135 return common.InterpolateValueByTime(p1.when, access(p1), p2.when, access(p2))
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
136 }
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
137
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
138 pairs:
2967
7c301ff449bc Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2962
diff changeset
139 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
140 p1 := &measurements[i]
7c301ff449bc Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2962
diff changeset
141 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
142
3036
7f12a87c56ff Fairway availability: Set boundaries of segments correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3027
diff changeset
143 var start, end time.Time
7f12a87c56ff Fairway availability: Set boundaries of segments correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3027
diff changeset
144
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
145 switch {
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
146 case !p2.when.After(p2.when):
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
147 // Segment invalid
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
148 continue pairs
2967
7c301ff449bc Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2962
diff changeset
149
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
150 case p1.when.After(to) || p2.when.Before(from):
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
151 // Segment complete outside.
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
152 continue pairs
2967
7c301ff449bc Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2962
diff changeset
153
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
154 case p1.when.After(from) && p2.when.Before(to):
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
155 // (from-to) is complete inside segment.
3038
d47d289d6e68 Fairway availability: Fill classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3036
diff changeset
156 // invalid += p1.when.Sub(from)
d47d289d6e68 Fairway availability: Fill classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3036
diff changeset
157 // invalid += to.Sub(p2.when)
3036
7f12a87c56ff Fairway availability: Set boundaries of segments correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3027
diff changeset
158 v := vbt(p1, p2)
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
159 f, _ := v(from)
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
160 t, _ := v(to)
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
161 classify(common.InterpolateTimeByValue(from, f, to, t))
3036
7f12a87c56ff Fairway availability: Set boundaries of segments correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3027
diff changeset
162 start, end = from, to
2967
7c301ff449bc Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2962
diff changeset
163
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
164 case p1.when.After(from):
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
165 // from is inside segment
3038
d47d289d6e68 Fairway availability: Fill classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3036
diff changeset
166 // invalid += p1.when.Sub(from)
3036
7f12a87c56ff Fairway availability: Set boundaries of segments correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3027
diff changeset
167 f, _ := vbt(p1, p2)(from)
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
168 classify(common.InterpolateTimeByValue(
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
169 from, f,
3040
a661e9b8f3b6 Fairway availability: 'virtualized' the field to classify.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3038
diff changeset
170 p2.when, access(p2),
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
171 ))
3036
7f12a87c56ff Fairway availability: Set boundaries of segments correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3027
diff changeset
172 start, end = from, p2.when
2967
7c301ff449bc Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2962
diff changeset
173
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
174 case p2.when.Before(to):
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
175 // to is inside segment
3038
d47d289d6e68 Fairway availability: Fill classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3036
diff changeset
176 // invalid += to.Sub(p2.when)
3036
7f12a87c56ff Fairway availability: Set boundaries of segments correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3027
diff changeset
177 t, _ := vbt(p1, p2)(to)
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
178 classify(common.InterpolateTimeByValue(
3040
a661e9b8f3b6 Fairway availability: 'virtualized' the field to classify.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3038
diff changeset
179 p1.when, access(p1),
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
180 to, t,
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
181 ))
3036
7f12a87c56ff Fairway availability: Set boundaries of segments correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3027
diff changeset
182 start, end = p1.when, to
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
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
184 case !p1.when.Before(from) && !to.After(p2.when):
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
185 // Segment complete inside.
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
186 classify(common.InterpolateTimeByValue(
3040
a661e9b8f3b6 Fairway availability: 'virtualized' the field to classify.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3038
diff changeset
187 p1.when, access(p1),
a661e9b8f3b6 Fairway availability: 'virtualized' the field to classify.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3038
diff changeset
188 p2.when, access(p2),
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
189 ))
3036
7f12a87c56ff Fairway availability: Set boundaries of segments correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3027
diff changeset
190 start, end = p1.when, p2.when
7f12a87c56ff Fairway availability: Set boundaries of segments correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3027
diff changeset
191 default:
7f12a87c56ff Fairway availability: Set boundaries of segments correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3027
diff changeset
192 log.Println("warn: unexpected case. That should not happen.")
7f12a87c56ff Fairway availability: Set boundaries of segments correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3027
diff changeset
193 continue pairs
2967
7c301ff449bc Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2962
diff changeset
194 }
3038
d47d289d6e68 Fairway availability: Fill classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3036
diff changeset
195
d47d289d6e68 Fairway availability: Fill classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3036
diff changeset
196 for i := len(cvs) - 1; i >= 0; i-- {
d47d289d6e68 Fairway availability: Fill classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3036
diff changeset
197 switch cvs[i].kind {
d47d289d6e68 Fairway availability: Fill classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3036
diff changeset
198 case common.ValueAbove:
d47d289d6e68 Fairway availability: Fill classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3036
diff changeset
199 result[i+1] += end.Sub(start)
d47d289d6e68 Fairway availability: Fill classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3036
diff changeset
200 continue pairs
d47d289d6e68 Fairway availability: Fill classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3036
diff changeset
201
d47d289d6e68 Fairway availability: Fill classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3036
diff changeset
202 case common.ValueInside:
d47d289d6e68 Fairway availability: Fill classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3036
diff changeset
203 // -> split
3040
a661e9b8f3b6 Fairway availability: 'virtualized' the field to classify.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3038
diff changeset
204 if access(p1) < classes[i].value {
3038
d47d289d6e68 Fairway availability: Fill classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3036
diff changeset
205 // started below -> second part above
d47d289d6e68 Fairway availability: Fill classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3036
diff changeset
206 result[i+1] = end.Sub(cvs[i].when)
d47d289d6e68 Fairway availability: Fill classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3036
diff changeset
207 end = cvs[i].when
d47d289d6e68 Fairway availability: Fill classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3036
diff changeset
208 } else {
d47d289d6e68 Fairway availability: Fill classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3036
diff changeset
209 // started above -> first part above
d47d289d6e68 Fairway availability: Fill classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3036
diff changeset
210 result[i+1] = cvs[i].when.Sub(start)
d47d289d6e68 Fairway availability: Fill classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3036
diff changeset
211 start = cvs[i].when
d47d289d6e68 Fairway availability: Fill classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3036
diff changeset
212 }
d47d289d6e68 Fairway availability: Fill classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3036
diff changeset
213 }
d47d289d6e68 Fairway availability: Fill classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3036
diff changeset
214 }
d47d289d6e68 Fairway availability: Fill classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3036
diff changeset
215 result[0] += end.Sub(start)
2967
7c301ff449bc Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2962
diff changeset
216 }
7c301ff449bc Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2962
diff changeset
217
3038
d47d289d6e68 Fairway availability: Fill classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3036
diff changeset
218 return result
2967
7c301ff449bc Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2962
diff changeset
219 }
7c301ff449bc Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2962
diff changeset
220
3076
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
221 func durationsToPercentage(from, to time.Time, classes []time.Duration) []float64 {
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
222 percents := make([]float64, len(classes))
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
223 total := 100 / to.Sub(from).Seconds()
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
224 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
225 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
226 }
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
227 return percents
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
228 }
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
229
3115
524bc6545b20 Simplified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3114
diff changeset
230 func parseTime(s, what string) (time.Time, error) {
524bc6545b20 Simplified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3114
diff changeset
231 var t time.Time
524bc6545b20 Simplified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3114
diff changeset
232 var err error
524bc6545b20 Simplified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3114
diff changeset
233 if t, err = time.Parse(common.TimeFormat, s); err != nil {
524bc6545b20 Simplified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3114
diff changeset
234 return time.Time{}, JSONError{
524bc6545b20 Simplified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3114
diff changeset
235 Code: http.StatusBadRequest,
524bc6545b20 Simplified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3114
diff changeset
236 Message: fmt.Sprintf(
524bc6545b20 Simplified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3114
diff changeset
237 "Invalid time format for '%s' field: %v", what, err),
524bc6545b20 Simplified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3114
diff changeset
238 }
524bc6545b20 Simplified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3114
diff changeset
239 }
524bc6545b20 Simplified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3114
diff changeset
240 return t.UTC(), nil
524bc6545b20 Simplified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3114
diff changeset
241 }
524bc6545b20 Simplified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3114
diff changeset
242
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
243 func bottleneckAvailabilty(
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
244 _ interface{},
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
245 req *http.Request,
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
246 conn *sql.Conn,
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
247 ) (jr JSONResult, err error) {
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
248 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
249
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
250 if bn == "" {
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
251 err = JSONError{
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
252 Code: http.StatusBadRequest,
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
253 Message: "Missing objnam of bottleneck",
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
254 }
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
255 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
256 }
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
257
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
258 var from, to time.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
259
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
260 if f := req.FormValue("from"); f != "" {
3115
524bc6545b20 Simplified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3114
diff changeset
261 if from, err = parseTime(f, "from"); 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
262 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
263 }
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
264 } else {
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
265 from = time.Now().AddDate(-1, 0, 0).UTC()
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
266 }
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
267
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
268 if t := req.FormValue("to"); t != "" {
3115
524bc6545b20 Simplified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3114
diff changeset
269 if to, err = parseTime(t, "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
270 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
271 }
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
272 } else {
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
273 to = from.AddDate(1, 0, 0).UTC()
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
274 }
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
275
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
276 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
277 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
278 }
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
279
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
280 log.Printf("info: time interval: (%v - %v)\n", 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
281
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
282 var los int
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
283 if l := req.FormValue("los"); l != "" {
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
284 if los, err = strconv.Atoi(l); err != nil {
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
285 err = JSONError{
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
286 Code: http.StatusBadRequest,
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
287 Message: fmt.Sprintf("Invalid value for field 'los': %v", err),
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
288 }
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
289 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
290 }
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
291 } else {
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
292 los = 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
293 }
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
294
3076
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
295 ctx := req.Context()
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
296
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
297 loadLNWLReferenceValues := func() ([]referenceValue, error) {
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
298 rows, err := conn.QueryContext(ctx, selectGaugeLevelsSQL, bn)
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
299 if err != nil {
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
300 return nil, err
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
301 }
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
302 defer rows.Close()
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
303
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
304 var levels []referenceValue
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
305
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
306 loop:
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
307 for rows.Next() {
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
308 var what string
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
309 var value int
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
310 if err := rows.Scan(&what, &value); err != nil {
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
311 return nil, err
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
312 }
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
313 var level int
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
314 switch {
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
315 case strings.HasPrefix(what, "LDC"):
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
316 level = 0
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
317 case strings.HasPrefix(what, "MW"):
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
318 level = 1
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
319 case strings.HasPrefix(what, "HDC"):
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
320 level = 2
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
321 default:
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
322 return nil, fmt.Errorf("Unexpected reference level type '%s'", what)
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
323 }
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
324 for i := range levels {
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
325 if levels[i].level == level {
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
326 levels[i].value = float64(value)
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
327 continue loop
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
328 }
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
329 }
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
330 levels = append(levels, referenceValue{
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
331 level: level,
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
332 value: float64(value),
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
333 })
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
334 }
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
335
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
336 if err := rows.Err(); err != nil {
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
337 return nil, err
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
338 }
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
339
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
340 sort.Slice(levels, func(i, j int) bool { return levels[i].level < levels[j].level })
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
341
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
342 return levels, nil
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
343 }
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
344
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
345 var lnwlRefs []referenceValue
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
346 if lnwlRefs, err = loadLNWLReferenceValues(); err != nil {
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
347 return
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
348 }
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
349
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
350 if len(lnwlRefs) == 0 {
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
351 err = JSONError{
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
352 Code: http.StatusNotFound,
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
353 Message: "No gauge reference values found for bottleneck",
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
354 }
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
355 }
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
356
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
357 loadDepthValues := func() (availMeasurements, error) {
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
358
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
359 rows, err := conn.QueryContext(
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
360 ctx, selectAvailableDepthSQL, bn, los, 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
361 if err != nil {
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
362 return nil, err
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
363 }
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
364 defer rows.Close()
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
365
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
366 var ms availMeasurements
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
367
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
368 for rows.Next() {
2967
7c301ff449bc Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2962
diff changeset
369 var m availMeasurement
7c301ff449bc Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2962
diff changeset
370 if err := rows.Scan(&m.when, &m.depth, &m.value); 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
371 return nil, err
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
372 }
2967
7c301ff449bc Fairway availibility: Started with class building.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2962
diff changeset
373 m.when = m.when.UTC()
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
374 ms = append(ms, m)
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
375 }
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
376
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
377 if err := rows.Err(); err != nil {
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
378 return nil, err
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
379 }
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
380
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
381 return ms, nil
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
382 }
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
383
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
384 var ms availMeasurements
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
385 if ms, err = loadDepthValues(); err != nil {
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
386 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
387 }
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
388
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
389 if len(ms) == 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
390 err = JSONError{
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
391 Code: http.StatusNotFound,
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
392 Message: "No available fairway depth values found",
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
393 }
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
394 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
395 }
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
396
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
397 lnwl := ms.classifyAvailMeasurements(
3038
d47d289d6e68 Fairway availability: Fill classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3036
diff changeset
398 from, to,
3076
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
399 lnwlRefs,
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
400 (*availMeasurement).getValue,
3038
d47d289d6e68 Fairway availability: Fill classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3036
diff changeset
401 )
d47d289d6e68 Fairway availability: Fill classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3036
diff changeset
402
3076
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
403 afdRefs := []referenceValue{
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
404 {0, 200},
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
405 {1, 230},
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
406 {2, 250},
3038
d47d289d6e68 Fairway availability: Fill classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3036
diff changeset
407 }
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
408
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
409 afd := ms.classifyAvailMeasurements(
3076
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
410 from, to,
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
411 afdRefs,
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
412 (*availMeasurement).getDepth,
3076
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
413 )
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
414
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
415 lnwlPercents := durationsToPercentage(from, to, lnwl)
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
416 afdPercents := durationsToPercentage(from, to, afd)
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
417
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
418 type lnwlOutput struct {
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
419 Level string `json:"level"`
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
420 Value float64 `json:"value"`
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
421 Percent float64 `json:"percent"`
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
422 }
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
423
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
424 type afdOutput struct {
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
425 Value float64 `json:"value"`
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
426 Percent float64 `json:"percent"`
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
427 }
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
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 type output struct {
3076
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
430 LNWL []lnwlOutput `json:"lnwl"`
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
431 AFD []afdOutput `json:"afd"`
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
432 }
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
433
3076
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
434 out := output{}
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
435
3076
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
436 for i := range lnwlRefs {
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
437 var level string
3076
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
438 switch lnwlRefs[i].level {
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
439 case 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
440 level = "LDC"
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
441 case 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
442 level = "MW"
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 case 2:
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
444 level = "HDC"
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
445 }
3076
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
446 out.LNWL = append(out.LNWL, lnwlOutput{
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
447 Level: level,
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
448 Value: lnwlRefs[i].value,
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
449 Percent: lnwlPercents[i],
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
450 })
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
451 }
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
452
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
453 for i := range afdRefs {
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
454 out.AFD = append(out.AFD, afdOutput{
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
455 Value: afdRefs[i].value,
e0daeb05bf50 Display Available Fairway Depths vs. LNWL: Completed backend (untested).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3040
diff changeset
456 Percent: afdPercents[i],
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
457 })
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
458 }
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
459
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
460 jr = JSONResult{Result: &out}
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
461
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
462 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
463 }