Mercurial > gemma
annotate pkg/controllers/fwa.go @ 5199:5001582f2ee1 new-fwa
Prepare to treat stretches and sections, too.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 08 May 2020 11:43:06 +0200 |
parents | c352dbbf2778 |
children | 5572da077c89 |
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" |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
19 "fmt" |
5195
d6710d29516b
Started to move code around.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5184
diff
changeset
|
20 "log" |
5184
445daeefca7b
Added controller stub for new fairway availability.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 "net/http" |
5196
5bc8daa986d9
More code movement.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5195
diff
changeset
|
22 "time" |
5184
445daeefca7b
Added controller stub for new fairway availability.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 |
5197
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
24 "github.com/gorilla/mux" |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
25 |
5196
5bc8daa986d9
More code movement.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5195
diff
changeset
|
26 "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
|
27 "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
|
28 ) |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
29 |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
30 const ( |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
31 selectBottlenecksLimitingSQL = ` |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
32 SELECT |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
33 lower(validity), |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
34 upper(validity), |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
35 limiting |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
36 FROM |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
37 waterway.bottlenecks |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
38 WHERE |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
39 bottleneck_id = $1 AND |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
40 validity && tstzrange($2, $3)` |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
41 |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
42 selectSymbolBottlenecksSQL = ` |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
43 SELECT |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
44 distinct(b.bottleneck_id) |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
45 FROM |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
46 users.%s s, waterway.bottlenecks b |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
47 WHERE |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
48 ST_Intersects(b.area, s.area) |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
49 AND s.name = $1 |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
50 AND b.validity && tstzrange($2, $3)` |
5197
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
51 ) |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
52 |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
53 type ( |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
54 limitingValidity struct { |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
55 limiting string |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
56 lower time.Time |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
57 upper time.Time |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
58 } |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
59 |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
60 limitingValidities []limitingValidity |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
61 |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
62 bottleneck struct { |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
63 id string |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
64 validities limitingValidities |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
65 } |
5184
445daeefca7b
Added controller stub for new fairway availability.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 ) |
445daeefca7b
Added controller stub for new fairway availability.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
68 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
|
69 |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
70 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
|
71 if !ok { |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
72 return |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
73 } |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
74 |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
75 vars := mux.Vars(req) |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
76 name := vars["name"] |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
77 if name == "" { |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
78 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
|
79 return |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
80 } |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
81 |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
82 ctx := req.Context() |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
83 conn := middleware.GetDBConn(req) |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
84 |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
85 // Function to extract the bottleneck_id's from the query. |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
86 var extract func(context.Context, *sql.Conn, string, time.Time, time.Time) ([]bottleneck, error) |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
87 |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
88 switch vars["kind"] { |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
89 case "bottleneck": |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
90 extract = extractBottleneck |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
91 case "stretch": |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
92 extract = extractStretch |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
93 case "section": |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
94 extract = extractSection |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
95 default: |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
96 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
|
97 return |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
98 } |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
99 |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
100 bottlenecks, err := extract(ctx, conn, name, from, to) |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
101 if err != nil { |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
102 log.Println("error: %v\n", err) |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
103 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
|
104 return |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
105 } |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
106 |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
107 // load validities and limiting factors |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
108 for i := range bottlenecks { |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
109 if err := bottlenecks[i].loadLimitingValidities(ctx, conn, from, to); err != nil { |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
110 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
|
111 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
|
112 return |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
113 } |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
114 } |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
115 |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
116 // TODO: Implement me! |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
117 } |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
118 |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
119 func dusk(t time.Time) time.Time { |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
120 return time.Date( |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
121 t.Year(), |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
122 t.Month(), |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
123 t.Day(), |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
124 0, 0, 0, 0, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
125 t.Location()) |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
126 } |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
127 |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
128 func dawn(t time.Time) time.Time { |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
129 return time.Date( |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
130 t.Year(), |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
131 t.Month(), |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
132 t.Day(), |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
133 23, 59, 59, 999999999, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
134 t.Location()) |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
135 } |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
136 |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
137 func parseFromTo( |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
138 rw http.ResponseWriter, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
139 req *http.Request, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
140 ) (time.Time, time.Time, bool) { |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
141 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
|
142 if !ok { |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
143 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
|
144 } |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
145 |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
146 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
|
147 if !ok { |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
148 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
|
149 } |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
150 |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
151 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
|
152 // Operate on daily basis so go to full days. |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
153 return dusk(from), dawn(to), true |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
154 } |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
155 |
5197
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
156 func (lv *limitingValidity) intersects(from, to time.Time) bool { |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
157 return !(to.Before(lv.lower) || from.After(lv.upper)) |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
158 } |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
159 |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
160 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
|
161 |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
162 var last *limitingValidity |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
163 |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
164 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
|
165 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
|
166 return last |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
167 } |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
168 for i := range lvs { |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
169 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
|
170 last = lv |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
171 return lv |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
172 } |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
173 } |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
174 return nil |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
175 } |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
176 } |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
177 |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
178 func loadLimitingValidities( |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
179 ctx context.Context, |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
180 conn *sql.Conn, |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
181 bottleneckID string, |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
182 from, to time.Time, |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
183 ) (limitingValidities, error) { |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
184 |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
185 var lvs limitingValidities |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
186 |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
187 rows, err := conn.QueryContext( |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
188 ctx, |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
189 selectLimitingSQL, |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
190 from, to) |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
191 |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
192 if err != nil { |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
193 return nil, err |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
194 } |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
195 defer rows.Close() |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
196 |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
197 for rows.Next() { |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
198 var lv limitingValidity |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
199 if err := rows.Scan( |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
200 &lv.limiting, |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
201 &lv.lower, |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
202 &lv.upper, |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
203 ); err != nil { |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
204 return nil, err |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
205 } |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
206 lv.lower = lv.lower.UTC() |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
207 lv.upper = lv.upper.UTC() |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
208 lvs = append(lvs, lv) |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
209 } |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
210 |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
211 return lvs, rows.Err() |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
212 } |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
213 |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
214 func loadSymbolBottlenecksFromTo( |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
215 ctx context.Context, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
216 conn *sql.Conn, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
217 what, name string, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
218 from, to time.Time, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
219 ) ([]bottleneck, error) { |
5184
445daeefca7b
Added controller stub for new fairway availability.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
220 |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
221 rows, err := conn.QueryContext( |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
222 ctx, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
223 fmt.Sprintf(selectSymbolBottlenecksSQL, what), |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
224 name, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
225 from, to) |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
226 if err != nil { |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
227 return nil, err |
5184
445daeefca7b
Added controller stub for new fairway availability.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
228 } |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
229 defer rows.Close() |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
230 |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
231 var bottlenecks []bottleneck |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
232 |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
233 for rows.Next() { |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
234 var b bottleneck |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
235 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
|
236 return nil, err |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
237 } |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
238 bottlenecks = append(bottlenecks, b) |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
239 } |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
240 |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
241 return bottlenecks, rows.Err() |
5184
445daeefca7b
Added controller stub for new fairway availability.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
242 } |
5195
d6710d29516b
Started to move code around.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5184
diff
changeset
|
243 |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
244 func extractBottleneck( |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
245 _ context.Context, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
246 _ *sql.Conn, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
247 name string, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
248 _, _ time.Time, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
249 ) ([]bottleneck, error) { |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
250 return []bottleneck{{id: name}}, nil |
5196
5bc8daa986d9
More code movement.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5195
diff
changeset
|
251 } |
5bc8daa986d9
More code movement.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5195
diff
changeset
|
252 |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
253 func extractStretch( |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
254 ctx context.Context, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
255 conn *sql.Conn, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
256 name string, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
257 from, to time.Time, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
258 ) ([]bottleneck, error) { |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
259 return loadSymbolBottlenecksFromTo( |
5197
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
260 ctx, |
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
261 conn, |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
262 "stretches", name, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
263 from, to) |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
264 } |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
265 |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
266 func extractSection( |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
267 ctx context.Context, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
268 conn *sql.Conn, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
269 name string, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
270 from, to time.Time, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
271 ) ([]bottleneck, error) { |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
272 return loadSymbolBottlenecksFromTo( |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
273 ctx, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
274 conn, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
275 "sections", name, |
5197
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
276 from, to) |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
277 } |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
278 |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
279 func (bn *bottleneck) loadLimitingValidities( |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
280 ctx context.Context, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
281 conn *sql.Conn, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
282 from, to time.Time, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
283 ) error { |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
284 vs, err := loadLimitingValidities( |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
285 ctx, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
286 conn, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
287 bn.id, |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
288 from, to) |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
289 if err == nil { |
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
290 bn.validities = vs |
5197
c352dbbf2778
Started with loading limiting factors and validities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5196
diff
changeset
|
291 } |
5199
5001582f2ee1
Prepare to treat stretches and sections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5197
diff
changeset
|
292 return err |
5195
d6710d29516b
Started to move code around.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5184
diff
changeset
|
293 } |