Mercurial > gemma
changeset 5243:0ab809236eb5 new-fwa
Write rest if lasteval period was not complete.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 12 May 2020 17:27:43 +0200 |
parents | 98ad96446d37 |
children | 8f9cd1df5028 |
files | pkg/controllers/fwa.go |
diffstat | 1 files changed, 36 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/pkg/controllers/fwa.go Tue May 12 17:20:32 2020 +0200 +++ b/pkg/controllers/fwa.go Tue May 12 17:27:43 2020 +0200 @@ -317,10 +317,34 @@ counters = make([]int, len(validities)) ) + var current, next time.Time + + write := func() error { + record[0] = label(current) + + if !availability { + record[1] = strconv.Itoa(totalDays - overLDCDays) + record[2] = strconv.Itoa(overLDCDays) + for i, c := range counters { + record[3+i] = strconv.Itoa(c) + } + } else { + overPerc := float64(overLDCDays) * 100 / float64(totalDays) + record[1] = fmt.Sprintf("%.3f", 100-overPerc) + record[2] = fmt.Sprintf("%.3f", overPerc) + for i, c := range counters { + perc := float64(c) * 100 / float64(totalDays) + record[3+i] = fmt.Sprintf("%.3f", perc) + } + } + + return out.Write(record) + } + // We step through the time in steps of one day. - for current := from; current.Before(to); { + for current = from; current.Before(to); { - next := current.AddDate(0, 0, 1) + next = current.AddDate(0, 0, 1) // Assume that a bottleneck is over LDC. overLDC := true @@ -372,25 +396,7 @@ totalDays++ if finish(next) { - record[0] = label(current) - - if !availability { - record[1] = strconv.Itoa(totalDays - overLDCDays) - record[2] = strconv.Itoa(overLDCDays) - for i, c := range counters { - record[3+i] = strconv.Itoa(c) - } - } else { - overPerc := float64(overLDCDays) * 100 / float64(totalDays) - record[1] = fmt.Sprintf("%.3f", 100-overPerc) - record[2] = fmt.Sprintf("%.3f", overPerc) - for i, c := range counters { - perc := float64(c) * 100 / float64(totalDays) - record[3+i] = fmt.Sprintf("%.3f", perc) - } - } - - if err := out.Write(record); err != nil { + if err := write(); err != nil { // Too late for HTTP status message. log.Printf("error: %v\n", err) return @@ -406,6 +412,15 @@ current = next } + // Write rest if last period was not finished. + if totalDays > 0 { + if err := write(); err != nil { + // Too late for HTTP status message. + log.Printf("error: %v\n", err) + return + } + } + // TODO: Log missing LDCs out.Flush()