Mercurial > gemma
comparison pkg/controllers/fwa.go @ 5244:8f9cd1df5028 new-fwa
Fixed a copy-by-value problem.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 12 May 2020 19:11:02 +0200 |
parents | 0ab809236eb5 |
children | 9dd1ae697f93 |
comparison
equal
deleted
inserted
replaced
5243:0ab809236eb5 | 5244:8f9cd1df5028 |
---|---|
295 log.Printf("error: %v\n", err) | 295 log.Printf("error: %v\n", err) |
296 return | 296 return |
297 } | 297 } |
298 | 298 |
299 for i := range record[1:] { | 299 for i := range record[1:] { |
300 record[i+1] = "0.0" | 300 record[i+1] = "0" |
301 } | 301 } |
302 | 302 |
303 // For every day on every bottleneck we need to find out if this day is valid. | 303 // For every day on every bottleneck we need to find out if this day is valid. |
304 validities := make([]func(time.Time, time.Time) *limitingValidity, len(bottlenecks)) | 304 validities := make([]func(time.Time, time.Time) *limitingValidity, len(bottlenecks)) |
305 for i := range bottlenecks { | 305 for i := range bottlenecks { |
312 label, finish := interval(mode, from) | 312 label, finish := interval(mode, from) |
313 | 313 |
314 var ( | 314 var ( |
315 totalDays, overLDCDays int | 315 totalDays, overLDCDays int |
316 missingLDCs = make([]int, len(validities)) | 316 missingLDCs = make([]int, len(validities)) |
317 counters = make([]int, len(validities)) | 317 counters = make([]int, len(breaks)+1) |
318 ) | 318 ) |
319 | 319 |
320 var current, next time.Time | 320 var current, next time.Time |
321 | 321 |
322 write := func() error { | 322 write := func() error { |
348 | 348 |
349 // Assume that a bottleneck is over LDC. | 349 // Assume that a bottleneck is over LDC. |
350 overLDC := true | 350 overLDC := true |
351 highest := -1 | 351 highest := -1 |
352 | 352 |
353 var hasValid bool | |
354 | |
353 // check all bottlenecks | 355 // check all bottlenecks |
354 for i, validity := range validities { | 356 for i, validity := range validities { |
355 | 357 |
356 // Check if bottleneck is available for this day. | 358 // Check if bottleneck is available for this day. |
357 vs := validity(current, next) | 359 vs := validity(current, next) |
363 ldc := vs.ldcs.find(current, next) | 365 ldc := vs.ldcs.find(current, next) |
364 if ldc == nil { | 366 if ldc == nil { |
365 missingLDCs[i]++ | 367 missingLDCs[i]++ |
366 continue | 368 continue |
367 } | 369 } |
370 | |
371 hasValid = true | |
368 | 372 |
369 if overLDC { // If its already not shipable we need no further tests. | 373 if overLDC { // If its already not shipable we need no further tests. |
370 result := bottlenecks[i].measurements.classify( | 374 result := bottlenecks[i].measurements.classify( |
371 current, next, | 375 current, next, |
372 ldc.value, | 376 ldc.value, |
385 ); min > highest { | 389 ); min > highest { |
386 highest = min | 390 highest = min |
387 } | 391 } |
388 } | 392 } |
389 | 393 |
390 if overLDC { | 394 if hasValid { |
391 overLDCDays++ | 395 if overLDC { |
392 } | 396 overLDCDays++ |
393 if highest > -1 { | 397 } |
394 counters[highest]++ | 398 if highest > -1 { |
399 counters[highest]++ | |
400 } | |
395 } | 401 } |
396 totalDays++ | 402 totalDays++ |
397 | 403 |
398 if finish(next) { | 404 if finish(next) { |
399 if err := write(); err != nil { | 405 if err := write(); err != nil { |
719 } else { | 725 } else { |
720 l.upper = to.Add(24 * time.Hour) | 726 l.upper = to.Add(24 * time.Hour) |
721 } | 727 } |
722 l.toUTC() | 728 l.toUTC() |
723 for i := range bn.validities { | 729 for i := range bn.validities { |
724 vs := bn.validities[i] | 730 vs := &bn.validities[i] |
731 | |
725 if vs.intersects(l.lower, l.upper) { | 732 if vs.intersects(l.lower, l.upper) { |
726 vs.ldcs = append(vs.ldcs, &l) | 733 vs.ldcs = append(vs.ldcs, &l) |
727 } | 734 } |
728 } | 735 } |
729 } | 736 } |