Mercurial > gemma
comparison pkg/controllers/bottlenecks.go @ 5220:142ac550bd9a new-fwa
Unify headers for CSV export.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 12 May 2020 10:15:32 +0200 |
parents | de417840dfee |
children |
comparison
equal
deleted
inserted
replaced
5219:de86a96d55c3 | 5220:142ac550bd9a |
---|---|
269 | 269 |
270 rw.Header().Add("Content-Type", "text/csv") | 270 rw.Header().Add("Content-Type", "text/csv") |
271 | 271 |
272 out := csv.NewWriter(rw) | 272 out := csv.NewWriter(rw) |
273 | 273 |
274 record := makeHeader(breaks, '%') | 274 record := makeHeader(false, 1, breaks, '%') |
275 | 275 |
276 if err := out.Write(record); err != nil { | 276 if err := out.Write(record); err != nil { |
277 // Too late for HTTP status message. | 277 // Too late for HTTP status message. |
278 log.Printf("error: %v\n", err) | 278 log.Printf("error: %v\n", err) |
279 return | 279 return |
405 rw.Header().Add("Content-Type", "text/csv") | 405 rw.Header().Add("Content-Type", "text/csv") |
406 | 406 |
407 out := csv.NewWriter(rw) | 407 out := csv.NewWriter(rw) |
408 | 408 |
409 // label, ldc, classes | 409 // label, ldc, classes |
410 record := makeHeader(breaks, 'd') | 410 record := makeHeader(false, 1, breaks, 'd') |
411 | 411 |
412 if err := out.Write(record); err != nil { | 412 if err := out.Write(record); err != nil { |
413 // Too late for HTTP status message. | 413 // Too late for HTTP status message. |
414 log.Printf("error: %v\n", err) | 414 log.Printf("error: %v\n", err) |
415 return | 415 return |
473 // Too late for HTTP status message. | 473 // Too late for HTTP status message. |
474 log.Printf("error: %v\n", err) | 474 log.Printf("error: %v\n", err) |
475 } | 475 } |
476 } | 476 } |
477 | 477 |
478 func makeHeader(breaks []float64, unit rune) []string { | |
479 record := make([]string, 1+2+len(breaks)+1) | |
480 record[0] = "#time" | |
481 record[1] = fmt.Sprintf("# < LDC [%c]", unit) | |
482 record[2] = fmt.Sprintf("# >= LDC [%c]", unit) | |
483 for i, v := range breaks { | |
484 if i == 0 { | |
485 record[3] = fmt.Sprintf("#d < %.1f [%c]", v, unit) | |
486 } | |
487 record[i+4] = fmt.Sprintf("#d >= %.1f [%c]", v, unit) | |
488 } | |
489 return record | |
490 } | |
491 | |
492 var intervals = []func(time.Time, time.Time) func() (time.Time, time.Time, string){ | 478 var intervals = []func(time.Time, time.Time) func() (time.Time, time.Time, string){ |
493 fwaMonthly: monthly, | 479 fwaMonthly: monthly, |
494 fwaQuarterly: quarterly, | 480 fwaQuarterly: quarterly, |
495 fwaYearly: yearly, | 481 fwaYearly: yearly, |
496 } | 482 } |