Mercurial > gemma
diff pkg/controllers/bottlenecks.go @ 5204:7ca9e6c9a203 new-fwa
Introduced type for mode (monthly, quarterly, yearly).
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 11 May 2020 11:03:19 +0200 |
parents | 355195a90298 |
children | 23addd19a6e2 |
line wrap: on
line diff
--- a/pkg/controllers/bottlenecks.go Fri May 08 18:59:14 2020 +0200 +++ b/pkg/controllers/bottlenecks.go Mon May 11 11:03:19 2020 +0200 @@ -21,8 +21,6 @@ "fmt" "log" "net/http" - "strconv" - "strings" "time" "github.com/gorilla/mux" @@ -91,12 +89,6 @@ ` ) -// afdRefs are the typical available fairway depth reference values. -var afdRefs = []float64{ - 230, - 250, -} - // According to clarification, it has to be assumed, that at times // with no data, the best case (which by convention is the highest // class created by classify()) should be assumed. That is due to the @@ -140,19 +132,6 @@ return percents } -func intervalMode(mode string) int { - switch strings.ToLower(mode) { - case "monthly": - return 0 - case "quarterly": - return 1 - case "yearly": - return 2 - default: - return 0 - } -} - func loadDepthValues( ctx context.Context, conn *sql.Conn, @@ -207,23 +186,9 @@ return []float64{value}, nil } -func breaksToReferenceValue(breaks string) []float64 { - parts := strings.Split(breaks, ",") - var values []float64 - - for _, part := range parts { - part = strings.TrimSpace(part) - if v, err := strconv.ParseFloat(part, 64); err == nil { - values = append(values, v) - } - } - - return common.DedupFloat64s(values) -} - func bottleneckAvailabilty(rw http.ResponseWriter, req *http.Request) { - mode := intervalMode(req.FormValue("mode")) + mode := parseFWAMode(req.FormValue("mode")) bn := mux.Vars(req)["objnam"] if bn == "" { @@ -284,12 +249,7 @@ return } - var breaks []float64 - if b := req.FormValue("breaks"); b != "" { - breaks = breaksToReferenceValue(b) - } else { - breaks = afdRefs - } + breaks := parseBreaks(req.FormValue("breaks")) log.Printf("info: time interval: (%v - %v)\n", from, to) @@ -377,7 +337,7 @@ func bottleneckAvailableFairwayDepth(rw http.ResponseWriter, req *http.Request) { - mode := intervalMode(req.FormValue("mode")) + mode := parseFWAMode(req.FormValue("mode")) bn := mux.Vars(req)["objnam"] if bn == "" { @@ -449,12 +409,7 @@ return } - var breaks []float64 - if b := req.FormValue("breaks"); b != "" { - breaks = breaksToReferenceValue(b) - } else { - breaks = afdRefs - } + breaks := parseBreaks(req.FormValue("breaks")) rw.Header().Add("Content-Type", "text/csv") @@ -539,9 +494,9 @@ } var intervals = []func(time.Time, time.Time) func() (time.Time, time.Time, string){ - monthly, - quarterly, - yearly, + fwaMonthly: monthly, + fwaQuarterly: quarterly, + fwaYearly: yearly, } func monthly(from, to time.Time) func() (time.Time, time.Time, string) {