# HG changeset patch # User Sascha L. Teichmann # Date 1567786005 -7200 # Node ID 6ac94171a994c00d544473080282b71c523dffce # Parent 63c25eb9c07cd66000e402a170076d55ba52c516 Fixed typos, tightened code removed trailing whitespace. diff -r 63c25eb9c07c -r 6ac94171a994 pkg/controllers/bottlenecks.go --- a/pkg/controllers/bottlenecks.go Fri Sep 06 17:22:42 2019 +0200 +++ b/pkg/controllers/bottlenecks.go Fri Sep 06 18:06:45 2019 +0200 @@ -135,36 +135,37 @@ // 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 -// fact, that at times where bottlenecks are ot a limiting factor on -// the waterway, services don't brovide any data for the bottleneck in +// fact, that at times where bottlenecks are not a limiting factor on +// the waterway, services don't provide any data for the bottleneck in // question. // -// FIXME: A potentional improvement could be to intercest the time +// FIXME: A potential improvement could be to intersect the time // ranges with the time ranges where bottlenecks were "active" (this -// _might_ be derivable fromt the validity periods in the bottleneck +// _might_ be derivable from the validity periods in the bottleneck // data. So it _might_ be possible do detect actual missing data (BN // valid, but no data from FA service). Anyway, this is left out for -// now, as many clarification regarding the base assumtions would bee +// now, as many clarification regarding the base assumtions would be // needed and the results still might be unrelyable. func optimisticPadClassification( from, to time.Time, classified []time.Duration, ) []time.Duration { + var actualDuration time.Duration - maxDuration := to.Sub(from) - - for i := 0; i < len(classified); i++ { - actualDuration += classified[i] + for _, v := range classified { + actualDuration += v } - delta := maxDuration - actualDuration - if delta > 0 { + // If the actual duration is smaller than the length + // of the classifaction interval extend the + // time spend in the highest class by the difference. + if delta := to.Sub(from) - actualDuration; delta > 0 { log.Printf("info: time interval: (%v - %v)\n", from, to) log.Printf("info: found only data for %.2f hours, padding by %.2f hours\n", actualDuration.Hours(), delta.Hours()) - classified[len(classified)-1] = classified[len(classified)-1] + delta + classified[len(classified)-1] += delta } - + return classified }