From 955509e6f8fd64712016c1627195b2ea4654fa50 Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Sat, 28 Dec 2019 18:26:32 +0100 Subject: [PATCH] nettests: don't say ETA is infinite 1. only print time left if ETA is positive 2. skip ETA calculation with a single input 3. don't compute ETA for first entry[*] [*] this is actually what avoids emitting infinite but the other parts of this diff felt useful yak shaving as well. Closes #91 --- internal/log/handlers/cli/cli.go | 9 ++++++--- nettests/nettests.go | 6 ++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/internal/log/handlers/cli/cli.go b/internal/log/handlers/cli/cli.go index 5bb033a..c3de93e 100644 --- a/internal/log/handlers/cli/cli.go +++ b/internal/log/handlers/cli/cli.go @@ -110,10 +110,13 @@ func (h *Handler) TypedLog(t string, e *log.Entry) error { case "progress": perc := e.Fields.Get("percentage").(float64) * 100 eta := e.Fields.Get("eta").(float64) - s := fmt.Sprintf(" %s %-25s (%ss left)", + var etaMessage string + if eta >= 0 { + etaMessage = fmt.Sprintf("(%ss left)", bold.Sprintf("%.2f", eta)) + } + s := fmt.Sprintf(" %s %-25s %s", bold.Sprintf("%.2f%%", perc), - e.Message, - bold.Sprintf("%.2f", eta)) + e.Message, etaMessage) fmt.Fprint(h.Writer, s) fmt.Fprintln(h.Writer) return nil diff --git a/nettests/nettests.go b/nettests/nettests.go index 4826598..07cd90e 100644 --- a/nettests/nettests.go +++ b/nettests/nettests.go @@ -192,12 +192,14 @@ func (c *Controller) OnProgress(perc float64, msg string) { log.Debugf("OnProgress: %f - %s", perc, msg) var eta float64 eta = -1.0 - if c.numInputs >= 1 { + if c.numInputs > 1 { // make the percentage relative to the current input over all inputs floor := (float64(c.curInputIdx) / float64(c.numInputs)) step := 1.0 / float64(c.numInputs) perc = floor + perc*step - eta = (float64(time.Now().Sub(c.ntStartTime).Seconds()) / float64(c.curInputIdx)) * float64(c.numInputs-c.curInputIdx) + if c.curInputIdx > 0 { + eta = (time.Now().Sub(c.ntStartTime).Seconds() / float64(c.curInputIdx)) * float64(c.numInputs-c.curInputIdx) + } } if c.ntCount > 0 { // make the percentage relative to the current nettest over all nettests