Mercurial > gemma
comparison pkg/controllers/fwa.go @ 5250:13e1767b63a1 new-fwa
Reverted: 8c44b518141a, which didn't fix anything.
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Tue, 12 May 2020 23:03:21 +0200 |
parents | 8c44b518141a |
children | 1fce0fd81f46 |
comparison
equal
deleted
inserted
replaced
5249:d855426a6e5d | 5250:13e1767b63a1 |
---|---|
48 distinct(b.bottleneck_id) | 48 distinct(b.bottleneck_id) |
49 FROM | 49 FROM |
50 %s s, waterway.bottlenecks b | 50 %s s, waterway.bottlenecks b |
51 WHERE | 51 WHERE |
52 ST_Intersects(b.area, s.area) | 52 ST_Intersects(b.area, s.area) |
53 AND s.name = $1` | 53 AND s.name = $1 |
54 AND b.validity && tstzrange($2, $3)` | |
54 | 55 |
55 selectLDCsSQL = ` | 56 selectLDCsSQL = ` |
56 SELECT | 57 SELECT |
57 lower(grwl.validity), | 58 lower(grwl.validity), |
58 upper(grwl.validity), | 59 upper(grwl.validity), |
200 | 201 |
201 ctx := req.Context() | 202 ctx := req.Context() |
202 conn := middleware.GetDBConn(req) | 203 conn := middleware.GetDBConn(req) |
203 | 204 |
204 // Function to extract the bottleneck_id's from the query. | 205 // Function to extract the bottleneck_id's from the query. |
205 var extract func(context.Context, *sql.Conn, string) (bottlenecks, error) | 206 var extract func(context.Context, *sql.Conn, string, time.Time, time.Time) (bottlenecks, error) |
206 | 207 |
207 switch vars["kind"] { | 208 switch vars["kind"] { |
208 case "bottleneck": | 209 case "bottleneck": |
209 extract = extractBottleneck | 210 extract = extractBottleneck |
210 case "stretch": | 211 case "stretch": |
214 default: | 215 default: |
215 http.Error(rw, "Invalid kind type.", http.StatusBadRequest) | 216 http.Error(rw, "Invalid kind type.", http.StatusBadRequest) |
216 return | 217 return |
217 } | 218 } |
218 | 219 |
219 bottlenecks, err := extract(ctx, conn, name) | 220 bottlenecks, err := extract(ctx, conn, name, from, to) |
220 if err != nil { | 221 if err != nil { |
221 log.Printf("error: %v\n", err) | 222 log.Printf("error: %v\n", err) |
222 http.Error(rw, "cannot extract bottlenecks", http.StatusBadRequest) | 223 http.Error(rw, "cannot extract bottlenecks", http.StatusBadRequest) |
223 return | 224 return |
224 } | 225 } |
625 | 626 |
626 func loadSymbolBottlenecksFromTo( | 627 func loadSymbolBottlenecksFromTo( |
627 ctx context.Context, | 628 ctx context.Context, |
628 conn *sql.Conn, | 629 conn *sql.Conn, |
629 what, name string, | 630 what, name string, |
631 from, to time.Time, | |
630 ) (bottlenecks, error) { | 632 ) (bottlenecks, error) { |
631 | 633 |
632 rows, err := conn.QueryContext( | 634 rows, err := conn.QueryContext( |
633 ctx, | 635 ctx, |
634 fmt.Sprintf(selectSymbolBottlenecksSQL, what), | 636 fmt.Sprintf(selectSymbolBottlenecksSQL, what), |
635 name) | 637 name, |
638 from, to) | |
636 if err != nil { | 639 if err != nil { |
637 return nil, err | 640 return nil, err |
638 } | 641 } |
639 defer rows.Close() | 642 defer rows.Close() |
640 | 643 |
653 | 656 |
654 func extractBottleneck( | 657 func extractBottleneck( |
655 _ context.Context, | 658 _ context.Context, |
656 _ *sql.Conn, | 659 _ *sql.Conn, |
657 name string, | 660 name string, |
661 _, _ time.Time, | |
658 ) (bottlenecks, error) { | 662 ) (bottlenecks, error) { |
659 return bottlenecks{{id: name}}, nil | 663 return bottlenecks{{id: name}}, nil |
660 } | 664 } |
661 | 665 |
662 func extractStretch( | 666 func extractStretch( |
663 ctx context.Context, | 667 ctx context.Context, |
664 conn *sql.Conn, | 668 conn *sql.Conn, |
665 name string, | 669 name string, |
670 from, to time.Time, | |
666 ) (bottlenecks, error) { | 671 ) (bottlenecks, error) { |
667 return loadSymbolBottlenecksFromTo( | 672 return loadSymbolBottlenecksFromTo( |
668 ctx, | 673 ctx, |
669 conn, | 674 conn, |
670 "users.stretches", name) | 675 "users.stretches", name, |
676 from, to) | |
671 } | 677 } |
672 | 678 |
673 func extractSection( | 679 func extractSection( |
674 ctx context.Context, | 680 ctx context.Context, |
675 conn *sql.Conn, | 681 conn *sql.Conn, |
676 name string, | 682 name string, |
683 from, to time.Time, | |
677 ) (bottlenecks, error) { | 684 ) (bottlenecks, error) { |
678 return loadSymbolBottlenecksFromTo( | 685 return loadSymbolBottlenecksFromTo( |
679 ctx, | 686 ctx, |
680 conn, | 687 conn, |
681 "waterway.sections", name) | 688 "waterway.sections", name, |
689 from, to) | |
682 } | 690 } |
683 | 691 |
684 func (bn *bottleneck) loadLimitingValidities( | 692 func (bn *bottleneck) loadLimitingValidities( |
685 ctx context.Context, | 693 ctx context.Context, |
686 conn *sql.Conn, | 694 conn *sql.Conn, |