Mercurial > gemma
diff pkg/controllers/bottlenecks.go @ 5195:d6710d29516b new-fwa
Started to move code around.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 07 May 2020 15:46:51 +0200 |
parents | 1a9e3e5feaa7 |
children | 5bc8daa986d9 |
line wrap: on
line diff
--- a/pkg/controllers/bottlenecks.go Wed May 06 17:35:40 2020 +0200 +++ b/pkg/controllers/bottlenecks.go Thu May 07 15:46:51 2020 +0200 @@ -221,7 +221,7 @@ continue } - lo, hi := maxTime(p1.when, from), minTime(p2.when, to) + lo, hi := common.MaxTime(p1.when, from), common.MinTime(p2.when, to) m1, m2 := access(p1), access(p2) if m1 == m2 { // The whole interval is in only one class. @@ -244,13 +244,13 @@ } for j := 0; j < len(values)-1; j++ { - start, end := orderTime(values[j], values[j+1]) + start, end := common.OrderTime(values[j], values[j+1]) if start.After(hi) || end.Before(lo) { continue } - start, end = maxTime(start, lo), minTime(end, hi) + start, end = common.MaxTime(start, lo), common.MinTime(end, hi) result[j] += end.Sub(start) } } @@ -258,27 +258,6 @@ return optimisticPadClassification(from, to, result) } -func orderTime(a, b time.Time) (time.Time, time.Time) { - if a.Before(b) { - return a, b - } - return b, a -} - -func minTime(a, b time.Time) time.Time { - if a.Before(b) { - return a - } - return b -} - -func maxTime(a, b time.Time) time.Time { - if a.After(b) { - return a - } - return b -} - func durationsToPercentage(duration time.Duration, classes []time.Duration) []float64 { percents := make([]float64, len(classes)) total := 100 / duration.Seconds() @@ -288,48 +267,6 @@ return percents } -func parseFormTime( - rw http.ResponseWriter, - req *http.Request, - field string, - def time.Time, -) (time.Time, bool) { - f := req.FormValue(field) - if f == "" { - return def.UTC(), true - } - v, err := common.ParseTime(f) - if err != nil { - http.Error( - rw, fmt.Sprintf("Invalid format for '%s'.", field), - http.StatusBadRequest, - ) - return time.Time{}, false - } - return v.UTC(), true -} - -func parseFormInt( - rw http.ResponseWriter, - req *http.Request, - field string, - def int, -) (int, bool) { - f := req.FormValue(field) - if f == "" { - return def, true - } - v, err := strconv.Atoi(f) - if err != nil { - http.Error( - rw, fmt.Sprintf("Invalid format for '%s'.", field), - http.StatusBadRequest, - ) - return 0, false - } - return v, true -} - func intervalMode(mode string) int { switch strings.ToLower(mode) { case "monthly":