Mercurial > gemma
changeset 5210:da6eb8073f77 new-fwa
Introduce separate breaks from depths and widths.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 11 May 2020 16:10:26 +0200 |
parents | 32eb35699bd3 |
children | 8d582b5ff71e |
files | pkg/controllers/bottlenecks.go pkg/controllers/fwa.go |
diffstat | 2 files changed, 64 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/pkg/controllers/bottlenecks.go Mon May 11 15:06:44 2020 +0200 +++ b/pkg/controllers/bottlenecks.go Mon May 11 16:10:26 2020 +0200 @@ -228,7 +228,7 @@ return } - access := limitingFactor(limiting) + access := limitingAccess[parseLimitingFactor(limiting)] ldcRefs, err := loadLDCReferenceValue(ctx, conn, bn) if err != nil { @@ -375,7 +375,7 @@ return } - access := limitingFactor(limiting) + access := limitingAccess[parseLimitingFactor(limiting)] log.Printf("info: time interval: (%v - %v)\n", from, to)
--- a/pkg/controllers/fwa.go Mon May 11 15:06:44 2020 +0200 +++ b/pkg/controllers/fwa.go Mon May 11 16:10:26 2020 +0200 @@ -118,9 +118,11 @@ ldcs []*ldc + limitingFactor int + limitingValidity struct { timeRange - limiting func(*availMeasurement) float64 + limiting limitingFactor ldcs ldcs } @@ -141,6 +143,8 @@ measurements availMeasurements } + bottlenecks []bottleneck + fwaMode int ) @@ -150,6 +154,16 @@ fwaYearly ) +const ( + limitingDepth limitingFactor = iota + limitingWidth +) + +var limitingAccess = [...]func(*availMeasurement) float64{ + limitingDepth: (*availMeasurement).getDepth, + limitingWidth: (*availMeasurement).getWidth, +} + // afdRefs are the typical available fairway depth reference values. var afdRefs = []float64{ 230, @@ -188,7 +202,7 @@ conn := middleware.GetDBConn(req) // Function to extract the bottleneck_id's from the query. - var extract func(context.Context, *sql.Conn, string, time.Time, time.Time) ([]bottleneck, error) + var extract func(context.Context, *sql.Conn, string, time.Time, time.Time) (bottlenecks, error) switch vars["kind"] { case "bottleneck": @@ -231,6 +245,19 @@ } + // separate breaks for depth and width + depthbreaks := parseBreaks("depthbreaks") + widthbreaks := parseBreaks("widthbreaks") + + useDepth := bottlenecks.hasLimiting(limitingDepth, from, to) + useWidth := bottlenecks.hasLimiting(limitingWidth, from, to) + + // TODO: use these. + _ = depthbreaks + _ = widthbreaks + _ = useDepth + _ = useWidth + // For every day on every bottleneck we need to find out if this day is valid. validities := make([]func(time.Time, time.Time) *limitingValidity, len(bottlenecks)) for i := range bottlenecks { @@ -388,15 +415,33 @@ } } -func limitingFactor(limiting string) func(*availMeasurement) float64 { +func (lvs limitingValidities) hasLimiting(limiting limitingFactor, from, to time.Time) bool { + for i := range lvs { + if lvs[i].limiting == limiting && lvs[i].intersects(from, to) { + return true + } + } + return false +} + +func (bns bottlenecks) hasLimiting(limiting limitingFactor, from, to time.Time) bool { + for i := range bns { + if bns[i].validities.hasLimiting(limiting, from, to) { + return true + } + } + return false +} + +func parseLimitingFactor(limiting string) limitingFactor { switch limiting { case "depth": - return (*availMeasurement).getDepth + return limitingDepth case "width": - return (*availMeasurement).getWidth + return limitingWidth default: log.Printf("warn: unknown limitation '%s'. default to 'depth'\n", limiting) - return (*availMeasurement).getDepth + return limitingDepth } } @@ -421,16 +466,16 @@ for rows.Next() { var lv limitingValidity - var access string + var limiting string if err := rows.Scan( - &access, + &limiting, &lv.lower, &lv.upper, ); err != nil { return nil, err } lv.toUTC() - lv.limiting = limitingFactor(access) + lv.limiting = parseLimitingFactor(limiting) lvs = append(lvs, lv) } @@ -442,7 +487,7 @@ conn *sql.Conn, what, name string, from, to time.Time, -) ([]bottleneck, error) { +) (bottlenecks, error) { rows, err := conn.QueryContext( ctx, @@ -454,17 +499,17 @@ } defer rows.Close() - var bottlenecks []bottleneck + var bns bottlenecks for rows.Next() { var b bottleneck if err := rows.Scan(&b.id); err != nil { return nil, err } - bottlenecks = append(bottlenecks, b) + bns = append(bns, b) } - return bottlenecks, rows.Err() + return bns, rows.Err() } func extractBottleneck( @@ -472,8 +517,8 @@ _ *sql.Conn, name string, _, _ time.Time, -) ([]bottleneck, error) { - return []bottleneck{{id: name}}, nil +) (bottlenecks, error) { + return bottlenecks{{id: name}}, nil } func extractStretch( @@ -481,7 +526,7 @@ conn *sql.Conn, name string, from, to time.Time, -) ([]bottleneck, error) { +) (bottlenecks, error) { return loadSymbolBottlenecksFromTo( ctx, conn, @@ -494,7 +539,7 @@ conn *sql.Conn, name string, from, to time.Time, -) ([]bottleneck, error) { +) (bottlenecks, error) { return loadSymbolBottlenecksFromTo( ctx, conn,