Mercurial > gemma
annotate pkg/controllers/fwa.go @ 5324:348d91848278 extented-report
Added and endpoint GET /api/data/reports to list the available report templates.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sun, 30 May 2021 01:26:36 +0200 |
parents | b3b990811f2c |
children | d71ebe576c76 |
rev | line source |
---|---|
5184
445daeefca7b
Added controller stub for new fairway availability.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
445daeefca7b
Added controller stub for new fairway availability.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 // without warranty, see README.md and license for details. |
445daeefca7b
Added controller stub for new fairway availability.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 // |
445daeefca7b
Added controller stub for new fairway availability.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
445daeefca7b
Added controller stub for new fairway availability.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
445daeefca7b
Added controller stub for new fairway availability.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 // |
445daeefca7b
Added controller stub for new fairway availability.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 // Copyright (C) 2018, 2019, 2020 by via donau |
445daeefca7b
Added controller stub for new fairway availability.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
445daeefca7b
Added controller stub for new fairway availability.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 // Software engineering by Intevation GmbH |
445daeefca7b
Added controller stub for new fairway availability.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 // |
445daeefca7b
Added controller stub for new fairway availability.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 // Author(s): |
445daeefca7b
Added controller stub for new fairway availability.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
445daeefca7b
Added controller stub for new fairway availability.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 |
445daeefca7b
Added controller stub for new fairway availability.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 package controllers |
445daeefca7b
Added controller stub for new fairway availability.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
445daeefca7b
Added controller stub for new fairway availability.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import ( |
5197
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
17 "context" |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
18 "database/sql" |
5221
6794e85dc2dd
Write headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5220
diff
changeset
|
19 "encoding/csv" |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
20 "fmt" |
5195
d6710d29516b
Started to move code around.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5184
diff
changeset
|
21 "log" |
5184
445daeefca7b
Added controller stub for new fairway availability.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 "net/http" |
5203
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
23 "sort" |
5204
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
24 "strconv" |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
25 "strings" |
5196
5bc8daa986d9
More code movement.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5195
diff
changeset
|
26 "time" |
5184
445daeefca7b
Added controller stub for new fairway availability.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 |
5197
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
28 "github.com/gorilla/mux" |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
29 |
5196
5bc8daa986d9
More code movement.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5195
diff
changeset
|
30 "gemma.intevation.de/gemma/pkg/common" |
5197
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
31 "gemma.intevation.de/gemma/pkg/middleware" |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
32 ) |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
33 |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
34 const ( |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
35 selectBottlenecksLimitingSQL = ` |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
36 SELECT |
5233
d6374435111a
Fixed order of parameters in SQL result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5232
diff
changeset
|
37 lower(validity), |
d6374435111a
Fixed order of parameters in SQL result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5232
diff
changeset
|
38 upper(validity), |
5197
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
39 limiting |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
40 FROM |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
41 waterway.bottlenecks |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
42 WHERE |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
43 bottleneck_id = $1 AND |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
44 validity && tstzrange($2, $3)` |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
45 |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
46 selectSymbolBottlenecksSQL = ` |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
47 SELECT |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
48 distinct(b.bottleneck_id) |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
49 FROM |
5246
6cbfa3c3803d
stretches und sections are in different schemata.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5245
diff
changeset
|
50 %s s, waterway.bottlenecks b |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
51 WHERE |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
52 ST_Intersects(b.area, s.area) |
5250
13e1767b63a1
Reverted: 8c44b518141a, which didn't fix anything.
Sascha Wilde <wilde@intevation.de>
parents:
5248
diff
changeset
|
53 AND s.name = $1 |
13e1767b63a1
Reverted: 8c44b518141a, which didn't fix anything.
Sascha Wilde <wilde@intevation.de>
parents:
5248
diff
changeset
|
54 AND b.validity && tstzrange($2, $3)` |
5200
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
55 |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
56 selectLDCsSQL = ` |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
57 SELECT |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
58 lower(grwl.validity), |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
59 upper(grwl.validity), |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
60 grwl.value |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
61 FROM |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
62 waterway.gauges_reference_water_levels grwl |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
63 JOIN waterway.bottlenecks bns |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
64 ON grwl.location = bns.gauge_location |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
65 WHERE |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
66 grwl.depth_reference like 'LDC%' |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
67 AND bns.bottleneck_id = $1 |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
68 AND grwl.validity && tstzrange($2, $3)` |
5202
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
69 |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
70 selectMeasurementsSQL = ` |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
71 WITH data AS ( |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
72 SELECT |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
73 efa.measure_date, |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
74 efa.available_depth_value, |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
75 efa.available_width_value, |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
76 efa.water_level_value |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
77 FROM waterway.effective_fairway_availability efa |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
78 JOIN waterway.fairway_availability fa |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
79 ON efa.fairway_availability_id = fa.id |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
80 JOIN waterway.bottlenecks bn |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
81 ON fa.bottleneck_id = bn.bottleneck_id |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
82 WHERE |
5255
256ebbeb1252
Fix FWA performance: match bottleneck validity with measure date.
wilde@azure1.rgb.intevation.de
parents:
5253
diff
changeset
|
83 bn.validity @> efa.measure_date AND |
5202
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
84 bn.bottleneck_id = $1 AND |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
85 efa.level_of_service = $2 AND |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
86 efa.measure_type = 'Measured' AND |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
87 (efa.available_depth_value IS NOT NULL OR |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
88 efa.available_width_value IS NOT NULL) AND |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
89 efa.water_level_value IS NOT NULL |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
90 ), |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
91 before AS ( |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
92 SELECT * FROM data WHERE measure_date < $3 |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
93 ORDER BY measure_date DESC LIMIT 1 |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
94 ), |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
95 inside AS ( |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
96 SELECT * FROM data WHERE measure_date BETWEEN $3 AND $4 |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
97 ), |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
98 after AS ( |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
99 SELECT * FROM data WHERE measure_date > $4 |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
100 ORDER BY measure_date LIMIT 1 |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
101 ) |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
102 SELECT * FROM before |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
103 UNION ALL |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
104 SELECT * FROM inside |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
105 UNION ALL |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
106 SELECT * FROM after |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
107 ORDER BY measure_date` |
5197
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
108 ) |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
109 |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
110 type ( |
5200
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
111 timeRange struct { |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
112 lower time.Time |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
113 upper time.Time |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
114 } |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
115 |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
116 ldc struct { |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
117 timeRange |
5203
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
118 value []float64 |
5200
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
119 } |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
120 |
5203
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
121 ldcs []*ldc |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
122 |
5210
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
123 limitingFactor int |
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
124 |
5197
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
125 limitingValidity struct { |
5200
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
126 timeRange |
5210
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
127 limiting limitingFactor |
5203
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
128 ldcs ldcs |
5197
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
129 } |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
130 |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
131 limitingValidities []limitingValidity |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
132 |
5202
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
133 availMeasurement struct { |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
134 when time.Time |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
135 depth int16 |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
136 width int16 |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
137 value int16 |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
138 } |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
139 |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
140 availMeasurements []availMeasurement |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
141 |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
142 bottleneck struct { |
5202
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
143 id string |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
144 validities limitingValidities |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
145 measurements availMeasurements |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
146 } |
5204
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
147 |
5210
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
148 bottlenecks []bottleneck |
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
149 |
5204
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
150 fwaMode int |
5184
445daeefca7b
Added controller stub for new fairway availability.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 ) |
445daeefca7b
Added controller stub for new fairway availability.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
152 |
5204
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
153 const ( |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
154 fwaMonthly fwaMode = iota |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
155 fwaQuarterly |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
156 fwaYearly |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
157 ) |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
158 |
5210
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
159 const ( |
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
160 limitingDepth limitingFactor = iota |
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
161 limitingWidth |
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
162 ) |
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
163 |
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
164 var limitingAccess = [...]func(*availMeasurement) float64{ |
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
165 limitingDepth: (*availMeasurement).getDepth, |
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
166 limitingWidth: (*availMeasurement).getWidth, |
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
167 } |
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
168 |
5204
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
169 // afdRefs are the typical available fairway depth reference values. |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
170 var afdRefs = []float64{ |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
171 230, |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
172 250, |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
173 } |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
174 |
5203
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
175 func (ls ldcs) find(from, to time.Time) *ldc { |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
176 for _, l := range ls { |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
177 if l.intersects(from, to) { |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
178 return l |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
179 } |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
180 } |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
181 return nil |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
182 } |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
183 |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
184 func fairwayAvailability(rw http.ResponseWriter, req *http.Request) { |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
185 |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
186 from, to, ok := parseFromTo(rw, req) |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
187 if !ok { |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
188 return |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
189 } |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
190 |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
191 vars := mux.Vars(req) |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
192 name := vars["name"] |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
193 if name == "" { |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
194 http.Error(rw, "missing 'name' parameter.", http.StatusBadRequest) |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
195 return |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
196 } |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
197 |
5226
755d54cd7fd0
Use LOS 3 as a default.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5225
diff
changeset
|
198 los, ok := parseFormInt(rw, req, "los", 3) |
5202
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
199 if !ok { |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
200 return |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
201 } |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
202 |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
203 ctx := req.Context() |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
204 conn := middleware.GetDBConn(req) |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
205 |
5251
1fce0fd81f46
Code simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5250
diff
changeset
|
206 var bns bottlenecks |
1fce0fd81f46
Code simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5250
diff
changeset
|
207 var err error |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
208 |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
209 switch vars["kind"] { |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
210 case "bottleneck": |
5251
1fce0fd81f46
Code simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5250
diff
changeset
|
211 bns = bottlenecks{{id: name}} |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
212 case "stretch": |
5251
1fce0fd81f46
Code simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5250
diff
changeset
|
213 bns, err = loadSymbolBottlenecks(ctx, conn, "users.stretches", name, from, to) |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
214 case "section": |
5251
1fce0fd81f46
Code simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5250
diff
changeset
|
215 bns, err = loadSymbolBottlenecks(ctx, conn, "waterway.sections", name, from, to) |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
216 default: |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
217 http.Error(rw, "Invalid kind type.", http.StatusBadRequest) |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
218 return |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
219 } |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
220 |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
221 if err != nil { |
5200
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
222 log.Printf("error: %v\n", err) |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
223 http.Error(rw, "cannot extract bottlenecks", http.StatusBadRequest) |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
224 return |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
225 } |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
226 |
5211
8d582b5ff71e
Some checks to prevent trivial errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5210
diff
changeset
|
227 // If there are no bottlenecks there is nothing to do. |
5251
1fce0fd81f46
Code simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5250
diff
changeset
|
228 if len(bns) == 0 { |
5211
8d582b5ff71e
Some checks to prevent trivial errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5210
diff
changeset
|
229 http.Error(rw, "No bottlenecks found.", http.StatusNotFound) |
8d582b5ff71e
Some checks to prevent trivial errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5210
diff
changeset
|
230 return |
8d582b5ff71e
Some checks to prevent trivial errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5210
diff
changeset
|
231 } |
8d582b5ff71e
Some checks to prevent trivial errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5210
diff
changeset
|
232 |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
233 // load validities and limiting factors |
5251
1fce0fd81f46
Code simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5250
diff
changeset
|
234 for i := range bns { |
1fce0fd81f46
Code simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5250
diff
changeset
|
235 if err := bns[i].loadLimitingValidities(ctx, conn, from, to); err != nil { |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
236 log.Printf("error: %v\n", err) |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
237 http.Error(rw, "cannot load validities", http.StatusInternalServerError) |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
238 return |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
239 } |
5200
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
240 // load LCDs |
5251
1fce0fd81f46
Code simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5250
diff
changeset
|
241 if err := bns[i].loadLDCs(ctx, conn, from, to); err != nil { |
5200
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
242 log.Printf("error: %v\n", err) |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
243 http.Error(rw, "cannot load LDCs", http.StatusInternalServerError) |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
244 return |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
245 } |
5202
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
246 // load values |
5251
1fce0fd81f46
Code simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5250
diff
changeset
|
247 if err := bns[i].loadValues(ctx, conn, from, to, los); err != nil { |
5202
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
248 log.Printf("error: %v\n", err) |
5230
40c9acd114cd
Added missing parameter to SQL query.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5228
diff
changeset
|
249 http.Error(rw, "cannot load values", http.StatusInternalServerError) |
5202
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
250 return |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
251 } |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
252 } |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
253 |
5210
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
254 // separate breaks for depth and width |
5212
6c316a4d3386
Pull breaks from the request parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5211
diff
changeset
|
255 var ( |
5214
ebcf33d79d2e
Use breaks to classfify.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5213
diff
changeset
|
256 breaks = parseBreaks(req.FormValue("breaks"), afdRefs) |
ebcf33d79d2e
Use breaks to classfify.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5213
diff
changeset
|
257 depthBreaks = parseBreaks(req.FormValue("depthbreaks"), breaks) |
ebcf33d79d2e
Use breaks to classfify.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5213
diff
changeset
|
258 widthBreaks = parseBreaks(req.FormValue("widthbreaks"), breaks) |
ebcf33d79d2e
Use breaks to classfify.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5213
diff
changeset
|
259 chooseBreaks = [...][]float64{ |
ebcf33d79d2e
Use breaks to classfify.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5213
diff
changeset
|
260 limitingDepth: depthBreaks, |
ebcf33d79d2e
Use breaks to classfify.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5213
diff
changeset
|
261 limitingWidth: widthBreaks, |
ebcf33d79d2e
Use breaks to classfify.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5213
diff
changeset
|
262 } |
ebcf33d79d2e
Use breaks to classfify.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5213
diff
changeset
|
263 |
5251
1fce0fd81f46
Code simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5250
diff
changeset
|
264 useDepth = bns.hasLimiting(limitingDepth, from, to) |
1fce0fd81f46
Code simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5250
diff
changeset
|
265 useWidth = bns.hasLimiting(limitingWidth, from, to) |
5212
6c316a4d3386
Pull breaks from the request parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5211
diff
changeset
|
266 ) |
5210
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
267 |
5212
6c316a4d3386
Pull breaks from the request parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5211
diff
changeset
|
268 if useDepth && useWidth && len(widthBreaks) != len(depthBreaks) { |
5211
8d582b5ff71e
Some checks to prevent trivial errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5210
diff
changeset
|
269 http.Error( |
8d582b5ff71e
Some checks to prevent trivial errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5210
diff
changeset
|
270 rw, |
8d582b5ff71e
Some checks to prevent trivial errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5210
diff
changeset
|
271 fmt.Sprintf("class breaks lengths differ: %d != %d", |
5212
6c316a4d3386
Pull breaks from the request parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5211
diff
changeset
|
272 len(widthBreaks), len(depthBreaks)), |
5211
8d582b5ff71e
Some checks to prevent trivial errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5210
diff
changeset
|
273 http.StatusBadRequest, |
8d582b5ff71e
Some checks to prevent trivial errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5210
diff
changeset
|
274 ) |
8d582b5ff71e
Some checks to prevent trivial errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5210
diff
changeset
|
275 return |
8d582b5ff71e
Some checks to prevent trivial errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5210
diff
changeset
|
276 } |
8d582b5ff71e
Some checks to prevent trivial errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5210
diff
changeset
|
277 |
5221
6794e85dc2dd
Write headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5220
diff
changeset
|
278 availability := vars["type"] == "availability" |
6794e85dc2dd
Write headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5220
diff
changeset
|
279 |
6794e85dc2dd
Write headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5220
diff
changeset
|
280 var record []string |
5242
98ad96446d37
Switched availability and fairway depths modes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5239
diff
changeset
|
281 if !availability { |
5221
6794e85dc2dd
Write headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5220
diff
changeset
|
282 // in days |
6794e85dc2dd
Write headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5220
diff
changeset
|
283 record = makeHeader(useDepth && useWidth, 1, breaks, 'd') |
6794e85dc2dd
Write headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5220
diff
changeset
|
284 } else { |
6794e85dc2dd
Write headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5220
diff
changeset
|
285 // percentage |
6794e85dc2dd
Write headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5220
diff
changeset
|
286 record = makeHeader(useDepth && useWidth, 3, breaks, '%') |
6794e85dc2dd
Write headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5220
diff
changeset
|
287 } |
6794e85dc2dd
Write headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5220
diff
changeset
|
288 |
6794e85dc2dd
Write headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5220
diff
changeset
|
289 rw.Header().Add("Content-Type", "text/csv") |
6794e85dc2dd
Write headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5220
diff
changeset
|
290 |
6794e85dc2dd
Write headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5220
diff
changeset
|
291 out := csv.NewWriter(rw) |
6794e85dc2dd
Write headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5220
diff
changeset
|
292 |
6794e85dc2dd
Write headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5220
diff
changeset
|
293 if err := out.Write(record); err != nil { |
6794e85dc2dd
Write headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5220
diff
changeset
|
294 // Too late for HTTP status message. |
6794e85dc2dd
Write headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5220
diff
changeset
|
295 log.Printf("error: %v\n", err) |
6794e85dc2dd
Write headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5220
diff
changeset
|
296 return |
6794e85dc2dd
Write headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5220
diff
changeset
|
297 } |
6794e85dc2dd
Write headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5220
diff
changeset
|
298 |
6794e85dc2dd
Write headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5220
diff
changeset
|
299 for i := range record[1:] { |
5244
8f9cd1df5028
Fixed a copy-by-value problem.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5243
diff
changeset
|
300 record[i+1] = "0" |
5221
6794e85dc2dd
Write headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5220
diff
changeset
|
301 } |
6794e85dc2dd
Write headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5220
diff
changeset
|
302 |
5203
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
303 // For every day on every bottleneck we need to find out if this day is valid. |
5251
1fce0fd81f46
Code simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5250
diff
changeset
|
304 validities := make([]func(time.Time, time.Time) *limitingValidity, len(bns)) |
1fce0fd81f46
Code simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5250
diff
changeset
|
305 for i := range bns { |
1fce0fd81f46
Code simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5250
diff
changeset
|
306 validities[i] = bns[i].validities.find() |
5203
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
307 } |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
308 |
5227
fa55f403985b
Added a comment about the mode.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5226
diff
changeset
|
309 // Mode reflects if we use monthly, quarterly od yearly intervals. |
5208
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
310 mode := parseFWAMode(req.FormValue("mode")) |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
311 |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
312 label, finish := interval(mode, from) |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
313 |
5236
b47a041e03c4
Fill classification columns in CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5234
diff
changeset
|
314 var ( |
b47a041e03c4
Fill classification columns in CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5234
diff
changeset
|
315 totalDays, overLDCDays int |
b47a041e03c4
Fill classification columns in CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5234
diff
changeset
|
316 missingLDCs = make([]int, len(validities)) |
5244
8f9cd1df5028
Fixed a copy-by-value problem.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5243
diff
changeset
|
317 counters = make([]int, len(breaks)+1) |
5236
b47a041e03c4
Fill classification columns in CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5234
diff
changeset
|
318 ) |
5216
91feaf7ac486
Started to accumulate time segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5215
diff
changeset
|
319 |
5243
0ab809236eb5
Write rest if lasteval period was not complete.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5242
diff
changeset
|
320 var current, next time.Time |
0ab809236eb5
Write rest if lasteval period was not complete.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5242
diff
changeset
|
321 |
0ab809236eb5
Write rest if lasteval period was not complete.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5242
diff
changeset
|
322 write := func() error { |
0ab809236eb5
Write rest if lasteval period was not complete.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5242
diff
changeset
|
323 record[0] = label(current) |
0ab809236eb5
Write rest if lasteval period was not complete.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5242
diff
changeset
|
324 |
0ab809236eb5
Write rest if lasteval period was not complete.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5242
diff
changeset
|
325 if !availability { |
0ab809236eb5
Write rest if lasteval period was not complete.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5242
diff
changeset
|
326 record[1] = strconv.Itoa(totalDays - overLDCDays) |
0ab809236eb5
Write rest if lasteval period was not complete.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5242
diff
changeset
|
327 record[2] = strconv.Itoa(overLDCDays) |
0ab809236eb5
Write rest if lasteval period was not complete.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5242
diff
changeset
|
328 for i, c := range counters { |
0ab809236eb5
Write rest if lasteval period was not complete.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5242
diff
changeset
|
329 record[3+i] = strconv.Itoa(c) |
0ab809236eb5
Write rest if lasteval period was not complete.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5242
diff
changeset
|
330 } |
0ab809236eb5
Write rest if lasteval period was not complete.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5242
diff
changeset
|
331 } else { |
0ab809236eb5
Write rest if lasteval period was not complete.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5242
diff
changeset
|
332 overPerc := float64(overLDCDays) * 100 / float64(totalDays) |
0ab809236eb5
Write rest if lasteval period was not complete.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5242
diff
changeset
|
333 record[1] = fmt.Sprintf("%.3f", 100-overPerc) |
0ab809236eb5
Write rest if lasteval period was not complete.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5242
diff
changeset
|
334 record[2] = fmt.Sprintf("%.3f", overPerc) |
0ab809236eb5
Write rest if lasteval period was not complete.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5242
diff
changeset
|
335 for i, c := range counters { |
0ab809236eb5
Write rest if lasteval period was not complete.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5242
diff
changeset
|
336 perc := float64(c) * 100 / float64(totalDays) |
0ab809236eb5
Write rest if lasteval period was not complete.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5242
diff
changeset
|
337 record[3+i] = fmt.Sprintf("%.3f", perc) |
0ab809236eb5
Write rest if lasteval period was not complete.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5242
diff
changeset
|
338 } |
0ab809236eb5
Write rest if lasteval period was not complete.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5242
diff
changeset
|
339 } |
0ab809236eb5
Write rest if lasteval period was not complete.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5242
diff
changeset
|
340 |
0ab809236eb5
Write rest if lasteval period was not complete.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5242
diff
changeset
|
341 return out.Write(record) |
0ab809236eb5
Write rest if lasteval period was not complete.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5242
diff
changeset
|
342 } |
0ab809236eb5
Write rest if lasteval period was not complete.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5242
diff
changeset
|
343 |
5253
878d52d95e37
Early calcultion stop to prevent classification in the future.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5252
diff
changeset
|
344 // Stop yesterday |
5296
b3b990811f2c
Moved Dusk and Dawn functions to common time functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5258
diff
changeset
|
345 end := common.MinTime(common.Dusk(time.Now()).Add(-time.Nanosecond), to) |
5253
878d52d95e37
Early calcultion stop to prevent classification in the future.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5252
diff
changeset
|
346 |
5203
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
347 // We step through the time in steps of one day. |
5253
878d52d95e37
Early calcultion stop to prevent classification in the future.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5252
diff
changeset
|
348 for current = from; current.Before(end); { |
5203
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
349 |
5243
0ab809236eb5
Write rest if lasteval period was not complete.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5242
diff
changeset
|
350 next = current.AddDate(0, 0, 1) |
5203
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
351 |
5228
f3a88039d822
Renamed variable shipable to overLDC to remove implicit semantics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5227
diff
changeset
|
352 // Assume that a bottleneck is over LDC. |
f3a88039d822
Renamed variable shipable to overLDC to remove implicit semantics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5227
diff
changeset
|
353 overLDC := true |
5252
aebe1a12e8b9
If looking at sections/stretches the bottleneck with the lowest class determines the class of the whole construct.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5251
diff
changeset
|
354 lowest := len(counters) - 1 |
5203
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
355 |
5244
8f9cd1df5028
Fixed a copy-by-value problem.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5243
diff
changeset
|
356 var hasValid bool |
8f9cd1df5028
Fixed a copy-by-value problem.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5243
diff
changeset
|
357 |
5216
91feaf7ac486
Started to accumulate time segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5215
diff
changeset
|
358 // check all bottlenecks |
5203
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
359 for i, validity := range validities { |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
360 |
5216
91feaf7ac486
Started to accumulate time segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5215
diff
changeset
|
361 // Check if bottleneck is available for this day. |
91feaf7ac486
Started to accumulate time segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5215
diff
changeset
|
362 vs := validity(current, next) |
91feaf7ac486
Started to accumulate time segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5215
diff
changeset
|
363 if vs == nil { |
91feaf7ac486
Started to accumulate time segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5215
diff
changeset
|
364 continue |
91feaf7ac486
Started to accumulate time segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5215
diff
changeset
|
365 } |
5203
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
366 |
5216
91feaf7ac486
Started to accumulate time segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5215
diff
changeset
|
367 // Let's see if we have a LDC for this day. |
91feaf7ac486
Started to accumulate time segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5215
diff
changeset
|
368 ldc := vs.ldcs.find(current, next) |
91feaf7ac486
Started to accumulate time segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5215
diff
changeset
|
369 if ldc == nil { |
5217
70d83b7d36ef
Track the number days LDCs are not available at bottlenecks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5216
diff
changeset
|
370 missingLDCs[i]++ |
5216
91feaf7ac486
Started to accumulate time segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5215
diff
changeset
|
371 continue |
91feaf7ac486
Started to accumulate time segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5215
diff
changeset
|
372 } |
5203
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
373 |
5244
8f9cd1df5028
Fixed a copy-by-value problem.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5243
diff
changeset
|
374 hasValid = true |
8f9cd1df5028
Fixed a copy-by-value problem.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5243
diff
changeset
|
375 |
5228
f3a88039d822
Renamed variable shipable to overLDC to remove implicit semantics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5227
diff
changeset
|
376 if overLDC { // If its already not shipable we need no further tests. |
5251
1fce0fd81f46
Code simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5250
diff
changeset
|
377 result := bns[i].measurements.classify( |
5214
ebcf33d79d2e
Use breaks to classfify.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5213
diff
changeset
|
378 current, next, |
5216
91feaf7ac486
Started to accumulate time segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5215
diff
changeset
|
379 ldc.value, |
91feaf7ac486
Started to accumulate time segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5215
diff
changeset
|
380 (*availMeasurement).getValue) |
5214
ebcf33d79d2e
Use breaks to classfify.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5213
diff
changeset
|
381 |
5258
b373213d8e7c
Assume that the decision if a day is below LDC is only possible if there are values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5256
diff
changeset
|
382 if (result[0] != 0 || result[1] != 0) && result[1] < 12*time.Hour { |
5228
f3a88039d822
Renamed variable shipable to overLDC to remove implicit semantics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5227
diff
changeset
|
383 overLDC = false |
5216
91feaf7ac486
Started to accumulate time segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5215
diff
changeset
|
384 } |
91feaf7ac486
Started to accumulate time segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5215
diff
changeset
|
385 } |
5214
ebcf33d79d2e
Use breaks to classfify.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5213
diff
changeset
|
386 |
5251
1fce0fd81f46
Code simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5250
diff
changeset
|
387 if min := minClass(bns[i].measurements.classify( |
5216
91feaf7ac486
Started to accumulate time segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5215
diff
changeset
|
388 current, next, |
91feaf7ac486
Started to accumulate time segments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5215
diff
changeset
|
389 chooseBreaks[vs.limiting], |
5236
b47a041e03c4
Fill classification columns in CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5234
diff
changeset
|
390 limitingAccess[vs.limiting]), |
b47a041e03c4
Fill classification columns in CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5234
diff
changeset
|
391 12*time.Hour, |
5252
aebe1a12e8b9
If looking at sections/stretches the bottleneck with the lowest class determines the class of the whole construct.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5251
diff
changeset
|
392 ); min < lowest { |
aebe1a12e8b9
If looking at sections/stretches the bottleneck with the lowest class determines the class of the whole construct.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5251
diff
changeset
|
393 lowest = min |
5236
b47a041e03c4
Fill classification columns in CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5234
diff
changeset
|
394 } |
5203
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
395 } |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
396 |
5244
8f9cd1df5028
Fixed a copy-by-value problem.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5243
diff
changeset
|
397 if hasValid { |
8f9cd1df5028
Fixed a copy-by-value problem.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5243
diff
changeset
|
398 if overLDC { |
8f9cd1df5028
Fixed a copy-by-value problem.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5243
diff
changeset
|
399 overLDCDays++ |
8f9cd1df5028
Fixed a copy-by-value problem.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5243
diff
changeset
|
400 } |
5252
aebe1a12e8b9
If looking at sections/stretches the bottleneck with the lowest class determines the class of the whole construct.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5251
diff
changeset
|
401 counters[lowest]++ |
5245
9dd1ae697f93
If not valid assume all is in best conditions.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5244
diff
changeset
|
402 } else { // assume that all is in best conditions |
9dd1ae697f93
If not valid assume all is in best conditions.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5244
diff
changeset
|
403 overLDCDays++ |
9dd1ae697f93
If not valid assume all is in best conditions.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5244
diff
changeset
|
404 counters[len(counters)-1]++ |
5236
b47a041e03c4
Fill classification columns in CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5234
diff
changeset
|
405 } |
5245
9dd1ae697f93
If not valid assume all is in best conditions.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5244
diff
changeset
|
406 |
5224
fc999a902d87
Write LCD columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5223
diff
changeset
|
407 totalDays++ |
5208
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
408 |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
409 if finish(next) { |
5243
0ab809236eb5
Write rest if lasteval period was not complete.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5242
diff
changeset
|
410 if err := write(); err != nil { |
5239
158a26bcb2af
Write the data out!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5236
diff
changeset
|
411 // Too late for HTTP status message. |
158a26bcb2af
Write the data out!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5236
diff
changeset
|
412 log.Printf("error: %v\n", err) |
158a26bcb2af
Write the data out!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5236
diff
changeset
|
413 return |
158a26bcb2af
Write the data out!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5236
diff
changeset
|
414 } |
158a26bcb2af
Write the data out!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5236
diff
changeset
|
415 |
5208
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
416 // Reset counters |
5228
f3a88039d822
Renamed variable shipable to overLDC to remove implicit semantics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5227
diff
changeset
|
417 overLDCDays, totalDays = 0, 0 |
5236
b47a041e03c4
Fill classification columns in CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5234
diff
changeset
|
418 for i := range counters { |
b47a041e03c4
Fill classification columns in CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5234
diff
changeset
|
419 counters[i] = 0 |
b47a041e03c4
Fill classification columns in CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5234
diff
changeset
|
420 } |
5208
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
421 } |
5203
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
422 |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
423 current = next |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
424 } |
5217
70d83b7d36ef
Track the number days LDCs are not available at bottlenecks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5216
diff
changeset
|
425 |
5243
0ab809236eb5
Write rest if lasteval period was not complete.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5242
diff
changeset
|
426 // Write rest if last period was not finished. |
0ab809236eb5
Write rest if lasteval period was not complete.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5242
diff
changeset
|
427 if totalDays > 0 { |
0ab809236eb5
Write rest if lasteval period was not complete.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5242
diff
changeset
|
428 if err := write(); err != nil { |
0ab809236eb5
Write rest if lasteval period was not complete.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5242
diff
changeset
|
429 // Too late for HTTP status message. |
0ab809236eb5
Write rest if lasteval period was not complete.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5242
diff
changeset
|
430 log.Printf("error: %v\n", err) |
0ab809236eb5
Write rest if lasteval period was not complete.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5242
diff
changeset
|
431 return |
0ab809236eb5
Write rest if lasteval period was not complete.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5242
diff
changeset
|
432 } |
0ab809236eb5
Write rest if lasteval period was not complete.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5242
diff
changeset
|
433 } |
0ab809236eb5
Write rest if lasteval period was not complete.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5242
diff
changeset
|
434 |
5256
ed62f138528a
Log days of missing LDCs per bottleneck.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5255
diff
changeset
|
435 for i, days := range missingLDCs { |
ed62f138528a
Log days of missing LDCs per bottleneck.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5255
diff
changeset
|
436 if missingLDCs[i] > 0 { |
ed62f138528a
Log days of missing LDCs per bottleneck.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5255
diff
changeset
|
437 log.Printf("warn: Missing LDCs for %s on %d days.\n", |
ed62f138528a
Log days of missing LDCs per bottleneck.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5255
diff
changeset
|
438 bns[i].id, days) |
ed62f138528a
Log days of missing LDCs per bottleneck.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5255
diff
changeset
|
439 } |
ed62f138528a
Log days of missing LDCs per bottleneck.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5255
diff
changeset
|
440 } |
5221
6794e85dc2dd
Write headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5220
diff
changeset
|
441 |
6794e85dc2dd
Write headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5220
diff
changeset
|
442 out.Flush() |
6794e85dc2dd
Write headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5220
diff
changeset
|
443 if err := out.Error(); err != nil { |
6794e85dc2dd
Write headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5220
diff
changeset
|
444 // Too late for HTTP status message. |
6794e85dc2dd
Write headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5220
diff
changeset
|
445 log.Printf("error: %v\n", err) |
6794e85dc2dd
Write headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5220
diff
changeset
|
446 } |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
447 } |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
448 |
5236
b47a041e03c4
Fill classification columns in CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5234
diff
changeset
|
449 func minClass(classes []time.Duration, threshold time.Duration) int { |
b47a041e03c4
Fill classification columns in CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5234
diff
changeset
|
450 var sum time.Duration |
b47a041e03c4
Fill classification columns in CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5234
diff
changeset
|
451 for i, v := range classes { |
b47a041e03c4
Fill classification columns in CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5234
diff
changeset
|
452 if sum += v; sum >= threshold { |
b47a041e03c4
Fill classification columns in CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5234
diff
changeset
|
453 return i |
5225
c5599966befe
find minima of each class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5224
diff
changeset
|
454 } |
c5599966befe
find minima of each class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5224
diff
changeset
|
455 } |
5252
aebe1a12e8b9
If looking at sections/stretches the bottleneck with the lowest class determines the class of the whole construct.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5251
diff
changeset
|
456 return len(classes) - 1 |
5225
c5599966befe
find minima of each class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5224
diff
changeset
|
457 } |
c5599966befe
find minima of each class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5224
diff
changeset
|
458 |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
459 func parseFromTo( |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
460 rw http.ResponseWriter, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
461 req *http.Request, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
462 ) (time.Time, time.Time, bool) { |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
463 from, ok := parseFormTime(rw, req, "from", time.Now().AddDate(-1, 0, 0)) |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
464 if !ok { |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
465 return time.Time{}, time.Time{}, false |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
466 } |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
467 |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
468 to, ok := parseFormTime(rw, req, "to", from.AddDate(1, 0, 0)) |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
469 if !ok { |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
470 return time.Time{}, time.Time{}, false |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
471 } |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
472 |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
473 from, to = common.OrderTime(from, to) |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
474 // Operate on daily basis so go to full days. |
5296
b3b990811f2c
Moved Dusk and Dawn functions to common time functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5258
diff
changeset
|
475 return common.Dusk(from), common.Dawn(to), true |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
476 } |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
477 |
5204
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
478 func parseFWAMode(mode string) fwaMode { |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
479 switch strings.ToLower(mode) { |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
480 case "monthly": |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
481 return fwaMonthly |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
482 case "quarterly": |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
483 return fwaQuarterly |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
484 case "yearly": |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
485 return fwaYearly |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
486 default: |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
487 return fwaMonthly |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
488 } |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
489 } |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
490 |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
491 func breaksToReferenceValue(breaks string) []float64 { |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
492 parts := strings.Split(breaks, ",") |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
493 var values []float64 |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
494 |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
495 for _, part := range parts { |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
496 part = strings.TrimSpace(part) |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
497 if v, err := strconv.ParseFloat(part, 64); err == nil { |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
498 values = append(values, v) |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
499 } |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
500 } |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
501 |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
502 return common.DedupFloat64s(values) |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
503 } |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
504 |
5213
de417840dfee
Made breaks defaults more sensible
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5212
diff
changeset
|
505 func parseBreaks(breaks string, defaults []float64) []float64 { |
5204
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
506 if breaks != "" { |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
507 return breaksToReferenceValue(breaks) |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
508 } |
5213
de417840dfee
Made breaks defaults more sensible
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5212
diff
changeset
|
509 return defaults |
5204
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
510 } |
7ca9e6c9a203
Introduced type for mode (monthly, quarterly, yearly).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5203
diff
changeset
|
511 |
5200
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
512 func (tr *timeRange) intersects(from, to time.Time) bool { |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
513 return !(to.Before(tr.lower) || from.After(tr.upper)) |
5197
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
514 } |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
515 |
5201
40daecc6f552
Made timeranges all UTC.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5200
diff
changeset
|
516 func (tr *timeRange) toUTC() { |
40daecc6f552
Made timeranges all UTC.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5200
diff
changeset
|
517 tr.lower = tr.lower.UTC() |
40daecc6f552
Made timeranges all UTC.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5200
diff
changeset
|
518 tr.upper = tr.upper.UTC() |
40daecc6f552
Made timeranges all UTC.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5200
diff
changeset
|
519 } |
40daecc6f552
Made timeranges all UTC.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5200
diff
changeset
|
520 |
5197
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
521 func (lvs limitingValidities) find() func(from, to time.Time) *limitingValidity { |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
522 |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
523 var last *limitingValidity |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
524 |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
525 return func(from, to time.Time) *limitingValidity { |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
526 if last != nil && last.intersects(from, to) { |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
527 return last |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
528 } |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
529 for i := range lvs { |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
530 if lv := &lvs[i]; lv.intersects(from, to) { |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
531 last = lv |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
532 return lv |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
533 } |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
534 } |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
535 return nil |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
536 } |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
537 } |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
538 |
5210
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
539 func (lvs limitingValidities) hasLimiting(limiting limitingFactor, from, to time.Time) bool { |
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
540 for i := range lvs { |
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
541 if lvs[i].limiting == limiting && lvs[i].intersects(from, to) { |
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
542 return true |
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
543 } |
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
544 } |
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
545 return false |
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
546 } |
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
547 |
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
548 func (bns bottlenecks) hasLimiting(limiting limitingFactor, from, to time.Time) bool { |
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
549 for i := range bns { |
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
550 if bns[i].validities.hasLimiting(limiting, from, to) { |
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
551 return true |
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
552 } |
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
553 } |
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
554 return false |
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
555 } |
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
556 |
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
557 func parseLimitingFactor(limiting string) limitingFactor { |
5203
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
558 switch limiting { |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
559 case "depth": |
5210
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
560 return limitingDepth |
5203
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
561 case "width": |
5210
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
562 return limitingWidth |
5203
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
563 default: |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
564 log.Printf("warn: unknown limitation '%s'. default to 'depth'\n", limiting) |
5210
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
565 return limitingDepth |
5203
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
566 } |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
567 } |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
568 |
5197
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
569 func loadLimitingValidities( |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
570 ctx context.Context, |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
571 conn *sql.Conn, |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
572 bottleneckID string, |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
573 from, to time.Time, |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
574 ) (limitingValidities, error) { |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
575 |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
576 var lvs limitingValidities |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
577 |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
578 rows, err := conn.QueryContext( |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
579 ctx, |
5223
d4e4f7232513
Removed old bottlenecks controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5221
diff
changeset
|
580 selectBottlenecksLimitingSQL, |
5230
40c9acd114cd
Added missing parameter to SQL query.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5228
diff
changeset
|
581 bottleneckID, |
5197
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
582 from, to) |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
583 |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
584 if err != nil { |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
585 return nil, err |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
586 } |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
587 defer rows.Close() |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
588 |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
589 for rows.Next() { |
5231
225b2d0a1824
Validities may have an NULL upper bound.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5230
diff
changeset
|
590 var ( |
225b2d0a1824
Validities may have an NULL upper bound.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5230
diff
changeset
|
591 lv limitingValidity |
225b2d0a1824
Validities may have an NULL upper bound.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5230
diff
changeset
|
592 limiting string |
225b2d0a1824
Validities may have an NULL upper bound.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5230
diff
changeset
|
593 upper sql.NullTime |
225b2d0a1824
Validities may have an NULL upper bound.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5230
diff
changeset
|
594 ) |
5197
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
595 if err := rows.Scan( |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
596 &lv.lower, |
5231
225b2d0a1824
Validities may have an NULL upper bound.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5230
diff
changeset
|
597 &upper, |
5233
d6374435111a
Fixed order of parameters in SQL result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5232
diff
changeset
|
598 &limiting, |
5197
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
599 ); err != nil { |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
600 return nil, err |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
601 } |
5231
225b2d0a1824
Validities may have an NULL upper bound.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5230
diff
changeset
|
602 if upper.Valid { |
225b2d0a1824
Validities may have an NULL upper bound.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5230
diff
changeset
|
603 lv.upper = upper.Time |
225b2d0a1824
Validities may have an NULL upper bound.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5230
diff
changeset
|
604 } else { |
225b2d0a1824
Validities may have an NULL upper bound.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5230
diff
changeset
|
605 lv.upper = to.Add(24 * time.Hour) |
225b2d0a1824
Validities may have an NULL upper bound.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5230
diff
changeset
|
606 } |
5201
40daecc6f552
Made timeranges all UTC.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5200
diff
changeset
|
607 lv.toUTC() |
5210
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
608 lv.limiting = parseLimitingFactor(limiting) |
5197
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
609 lvs = append(lvs, lv) |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
610 } |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
611 |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
612 return lvs, rows.Err() |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
613 } |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
614 |
5251
1fce0fd81f46
Code simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5250
diff
changeset
|
615 func loadSymbolBottlenecks( |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
616 ctx context.Context, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
617 conn *sql.Conn, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
618 what, name string, |
5250
13e1767b63a1
Reverted: 8c44b518141a, which didn't fix anything.
Sascha Wilde <wilde@intevation.de>
parents:
5248
diff
changeset
|
619 from, to time.Time, |
5210
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
620 ) (bottlenecks, error) { |
5184
445daeefca7b
Added controller stub for new fairway availability.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
621 |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
622 rows, err := conn.QueryContext( |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
623 ctx, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
624 fmt.Sprintf(selectSymbolBottlenecksSQL, what), |
5250
13e1767b63a1
Reverted: 8c44b518141a, which didn't fix anything.
Sascha Wilde <wilde@intevation.de>
parents:
5248
diff
changeset
|
625 name, |
13e1767b63a1
Reverted: 8c44b518141a, which didn't fix anything.
Sascha Wilde <wilde@intevation.de>
parents:
5248
diff
changeset
|
626 from, to) |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
627 if err != nil { |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
628 return nil, err |
5184
445daeefca7b
Added controller stub for new fairway availability.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
629 } |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
630 defer rows.Close() |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
631 |
5210
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
632 var bns bottlenecks |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
633 |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
634 for rows.Next() { |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
635 var b bottleneck |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
636 if err := rows.Scan(&b.id); err != nil { |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
637 return nil, err |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
638 } |
5210
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
639 bns = append(bns, b) |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
640 } |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
641 |
5210
da6eb8073f77
Introduce separate breaks from depths and widths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5209
diff
changeset
|
642 return bns, rows.Err() |
5184
445daeefca7b
Added controller stub for new fairway availability.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
643 } |
5195
d6710d29516b
Started to move code around.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5184
diff
changeset
|
644 |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
645 func (bn *bottleneck) loadLimitingValidities( |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
646 ctx context.Context, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
647 conn *sql.Conn, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
648 from, to time.Time, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
649 ) error { |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
650 vs, err := loadLimitingValidities( |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
651 ctx, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
652 conn, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
653 bn.id, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
654 from, to) |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
655 if err == nil { |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
656 bn.validities = vs |
5197
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
657 } |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
658 return err |
5195
d6710d29516b
Started to move code around.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5184
diff
changeset
|
659 } |
5200
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
660 |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
661 func (bn *bottleneck) loadLDCs( |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
662 ctx context.Context, |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
663 conn *sql.Conn, |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
664 from, to time.Time, |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
665 ) error { |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
666 rows, err := conn.QueryContext( |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
667 ctx, selectLDCsSQL, |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
668 bn.id, |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
669 from, to) |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
670 if err != nil { |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
671 return err |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
672 } |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
673 defer rows.Close() |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
674 for rows.Next() { |
5203
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
675 l := ldc{value: []float64{0}} |
5231
225b2d0a1824
Validities may have an NULL upper bound.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5230
diff
changeset
|
676 var upper sql.NullTime |
225b2d0a1824
Validities may have an NULL upper bound.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5230
diff
changeset
|
677 if err := rows.Scan(&l.lower, &upper, &l.value[0]); err != nil { |
5200
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
678 return err |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
679 } |
5231
225b2d0a1824
Validities may have an NULL upper bound.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5230
diff
changeset
|
680 if upper.Valid { |
225b2d0a1824
Validities may have an NULL upper bound.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5230
diff
changeset
|
681 l.upper = upper.Time |
225b2d0a1824
Validities may have an NULL upper bound.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5230
diff
changeset
|
682 } else { |
225b2d0a1824
Validities may have an NULL upper bound.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5230
diff
changeset
|
683 l.upper = to.Add(24 * time.Hour) |
225b2d0a1824
Validities may have an NULL upper bound.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5230
diff
changeset
|
684 } |
5201
40daecc6f552
Made timeranges all UTC.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5200
diff
changeset
|
685 l.toUTC() |
5200
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
686 for i := range bn.validities { |
5244
8f9cd1df5028
Fixed a copy-by-value problem.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5243
diff
changeset
|
687 vs := &bn.validities[i] |
8f9cd1df5028
Fixed a copy-by-value problem.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5243
diff
changeset
|
688 |
5200
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
689 if vs.intersects(l.lower, l.upper) { |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
690 vs.ldcs = append(vs.ldcs, &l) |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
691 } |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
692 } |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
693 } |
5202
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
694 return rows.Err() |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
695 } |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
696 |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
697 func (bn *bottleneck) loadValues( |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
698 ctx context.Context, |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
699 conn *sql.Conn, |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
700 from, to time.Time, |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
701 los int, |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
702 ) error { |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
703 rows, err := conn.QueryContext( |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
704 ctx, selectMeasurementsSQL, |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
705 bn.id, |
5234
30a55f46996f
Another swapped sql parameter.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5233
diff
changeset
|
706 los, |
30a55f46996f
Another swapped sql parameter.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5233
diff
changeset
|
707 from, to) |
5202
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
708 if err != nil { |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
709 return err |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
710 } |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
711 defer rows.Close() |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
712 |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
713 var ms availMeasurements |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
714 |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
715 for rows.Next() { |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
716 var m availMeasurement |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
717 if err := rows.Scan( |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
718 &m.when, |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
719 &m.depth, |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
720 &m.width, |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
721 &m.value, |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
722 ); err != nil { |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
723 return err |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
724 } |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
725 m.when = m.when.UTC() |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
726 ms = append(ms, m) |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
727 } |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
728 if err := rows.Err(); err != nil { |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
729 return err |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
730 } |
fbc79c8459b4
Load water values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5201
diff
changeset
|
731 bn.measurements = ms |
5200
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
732 return nil |
5572da077c89
Load LDCs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5199
diff
changeset
|
733 } |
5203
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
734 |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
735 func (measurement *availMeasurement) getDepth() float64 { |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
736 return float64(measurement.depth) |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
737 } |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
738 |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
739 func (measurement *availMeasurement) getValue() float64 { |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
740 return float64(measurement.value) |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
741 } |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
742 |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
743 func (measurement *availMeasurement) getWidth() float64 { |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
744 return float64(measurement.width) |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
745 } |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
746 |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
747 func (measurements availMeasurements) classify( |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
748 from, to time.Time, |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
749 breaks []float64, |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
750 access func(*availMeasurement) float64, |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
751 ) []time.Duration { |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
752 |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
753 if len(breaks) == 0 { |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
754 return []time.Duration{} |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
755 } |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
756 |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
757 result := make([]time.Duration, len(breaks)+1) |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
758 classes := make([]float64, len(breaks)+2) |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
759 values := make([]time.Time, len(classes)) |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
760 |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
761 // Add sentinels |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
762 classes[0] = breaks[0] - 9999 |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
763 classes[len(classes)-1] = breaks[len(breaks)-1] + 9999 |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
764 for i := range breaks { |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
765 classes[i+1] = breaks[i] |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
766 } |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
767 |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
768 idx := sort.Search(len(measurements), func(i int) bool { |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
769 // All values before from can be ignored. |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
770 return !measurements[i].when.Before(from) |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
771 }) |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
772 |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
773 if idx >= len(measurements) { |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
774 return result |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
775 } |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
776 |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
777 // Be safe for interpolation. |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
778 if idx > 0 { |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
779 idx-- |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
780 } |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
781 |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
782 measurements = measurements[idx:] |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
783 |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
784 for i := 0; i < len(measurements)-1; i++ { |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
785 p1 := &measurements[i] |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
786 p2 := &measurements[i+1] |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
787 |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
788 if p1.when.After(to) { |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
789 return result |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
790 } |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
791 |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
792 if p2.when.Before(from) { |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
793 continue |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
794 } |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
795 |
5247
d89f5d75223e
Deactivate interpolation stop for gaps longer than 1.5 hours.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5246
diff
changeset
|
796 // TODO: Discuss if we want somethinh like this. |
d89f5d75223e
Deactivate interpolation stop for gaps longer than 1.5 hours.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5246
diff
changeset
|
797 if false && p2.when.Sub(p1.when).Hours() > 1.5 { |
5203
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
798 // Don't interpolate ranges bigger then one and a half hour |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
799 continue |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
800 } |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
801 |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
802 lo, hi := common.MaxTime(p1.when, from), common.MinTime(p2.when, to) |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
803 |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
804 m1, m2 := access(p1), access(p2) |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
805 if m1 == m2 { // The whole interval is in only one class. |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
806 for j := 0; j < len(classes)-1; j++ { |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
807 if classes[j] <= m1 && m1 <= classes[j+1] { |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
808 result[j] += hi.Sub(lo) |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
809 break |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
810 } |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
811 } |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
812 continue |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
813 } |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
814 |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
815 f := common.InterpolateTime( |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
816 p1.when, m1, |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
817 p2.when, m2, |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
818 ) |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
819 |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
820 for j, c := range classes { |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
821 values[j] = f(c) |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
822 } |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
823 |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
824 for j := 0; j < len(values)-1; j++ { |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
825 start, end := common.OrderTime(values[j], values[j+1]) |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
826 |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
827 if start.After(hi) || end.Before(lo) { |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
828 continue |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
829 } |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
830 |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
831 start, end = common.MaxTime(start, lo), common.MinTime(end, hi) |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
832 result[j] += end.Sub(start) |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
833 } |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
834 } |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
835 |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
836 return result |
355195a90298
Start calculting the navigability. TODO: accumulate and do output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5202
diff
changeset
|
837 } |
5208
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
838 |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
839 func interval(mode fwaMode, t time.Time) ( |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
840 label func(time.Time) string, |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
841 finish func(time.Time) bool, |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
842 ) { |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
843 switch mode { |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
844 case fwaMonthly: |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
845 label, finish = monthLabel, otherMonth(t) |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
846 case fwaQuarterly: |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
847 label, finish = quarterLabel, otherQuarter(t) |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
848 case fwaYearly: |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
849 label, finish = yearLabel, otherYear(t) |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
850 default: |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
851 panic("Unknown mode") |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
852 } |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
853 return |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
854 } |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
855 |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
856 func monthLabel(t time.Time) string { |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
857 return fmt.Sprintf("%02d-%d", t.Month(), t.Year()) |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
858 } |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
859 |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
860 func quarterLabel(t time.Time) string { |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
861 return fmt.Sprintf("Q%d-%d", (int(t.Month())-1)/3+1, t.Year()) |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
862 } |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
863 |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
864 func yearLabel(t time.Time) string { |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
865 return strconv.Itoa(t.Year()) |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
866 } |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
867 |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
868 func otherMonth(t time.Time) func(time.Time) bool { |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
869 return func(x time.Time) bool { |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
870 flag := t.Day() == x.Day() |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
871 if flag { |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
872 t = x |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
873 } |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
874 return flag |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
875 } |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
876 } |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
877 |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
878 func otherQuarter(t time.Time) func(time.Time) bool { |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
879 return func(x time.Time) bool { |
5209
32eb35699bd3
Fixed bug in quarter detection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5208
diff
changeset
|
880 flag := (t.Month()-1)/3 != (x.Month()-1)/3 |
5208
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
881 if flag { |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
882 t = x |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
883 } |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
884 return flag |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
885 } |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
886 } |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
887 |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
888 func otherYear(t time.Time) func(time.Time) bool { |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
889 return func(x time.Time) bool { |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
890 flag := t.Year() != x.Year() |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
891 if flag { |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
892 t = x |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
893 } |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
894 return flag |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
895 } |
defca5418446
Define how modes work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5205
diff
changeset
|
896 } |
5220
142ac550bd9a
Unify headers for CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5218
diff
changeset
|
897 |
142ac550bd9a
Unify headers for CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5218
diff
changeset
|
898 func makeHeader(flag bool, prec int, breaks []float64, unit rune) []string { |
142ac550bd9a
Unify headers for CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5218
diff
changeset
|
899 record := make([]string, 1+2+len(breaks)+1) |
142ac550bd9a
Unify headers for CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5218
diff
changeset
|
900 record[0] = "# time" |
142ac550bd9a
Unify headers for CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5218
diff
changeset
|
901 record[1] = fmt.Sprintf("# < LDC [%c]", unit) |
142ac550bd9a
Unify headers for CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5218
diff
changeset
|
902 record[2] = fmt.Sprintf("# >= LDC [%c]", unit) |
142ac550bd9a
Unify headers for CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5218
diff
changeset
|
903 for i, v := range breaks { |
142ac550bd9a
Unify headers for CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5218
diff
changeset
|
904 if flag { |
142ac550bd9a
Unify headers for CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5218
diff
changeset
|
905 if i == 0 { |
142ac550bd9a
Unify headers for CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5218
diff
changeset
|
906 record[3] = fmt.Sprintf("# < break_1 [%c]", unit) |
142ac550bd9a
Unify headers for CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5218
diff
changeset
|
907 } |
142ac550bd9a
Unify headers for CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5218
diff
changeset
|
908 record[i+4] = fmt.Sprintf("# >= break_%d [%c]", i+1, unit) |
142ac550bd9a
Unify headers for CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5218
diff
changeset
|
909 } else { |
142ac550bd9a
Unify headers for CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5218
diff
changeset
|
910 if i == 0 { |
142ac550bd9a
Unify headers for CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5218
diff
changeset
|
911 record[3] = fmt.Sprintf("# < %.*f [%c]", prec, v, unit) |
142ac550bd9a
Unify headers for CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5218
diff
changeset
|
912 } |
142ac550bd9a
Unify headers for CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5218
diff
changeset
|
913 record[i+4] = fmt.Sprintf("# >= %.*f [%c]", prec, v, unit) |
142ac550bd9a
Unify headers for CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5218
diff
changeset
|
914 } |
142ac550bd9a
Unify headers for CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5218
diff
changeset
|
915 } |
142ac550bd9a
Unify headers for CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5218
diff
changeset
|
916 return record |
142ac550bd9a
Unify headers for CSV export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5218
diff
changeset
|
917 } |