From e5c508a94c8540e4abaa14a3684f844d860b0470 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arturo=20Filast=C3=B2?= Date: Mon, 10 Sep 2018 16:56:32 +0200 Subject: [PATCH] Fix bug in result listing --- internal/cli/list/list.go | 8 ++++---- internal/database/actions.go | 4 +++- internal/database/models.go | 6 ++++-- internal/log/handlers/cli/cli.go | 10 ++++++---- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/internal/cli/list/list.go b/internal/cli/list/list.go index c2f1e74..13ef534 100644 --- a/internal/cli/list/list.go +++ b/internal/cli/list/list.go @@ -42,7 +42,7 @@ func init() { } for idx, result := range incompleteResults { output.ResultItem(output.ResultItemData{ - ID: result.Result.ID, + ID: result.ResultID, Index: idx, TotalCount: len(incompleteResults), Name: result.TestGroupName, @@ -63,16 +63,16 @@ func init() { netCount := make(map[uint]int) output.SectionTitle("Results") for idx, result := range doneResults { - totalCount, anmlyCount, err := database.GetMeasurementCounts(ctx.DB, result.Result.ID) + totalCount, anmlyCount, err := database.GetMeasurementCounts(ctx.DB, result.ResultID) if err != nil { log.WithError(err).Error("failed to list measurement counts") } - testKeys, err := database.GetResultTestKeys(ctx.DB, result.Result.ID) + testKeys, err := database.GetResultTestKeys(ctx.DB, result.ResultID) if err != nil { log.WithError(err).Error("failed to get testKeys") } output.ResultItem(output.ResultItemData{ - ID: result.Result.ID, + ID: result.ResultID, Index: idx, TotalCount: len(doneResults), Name: result.TestGroupName, diff --git a/internal/database/actions.go b/internal/database/actions.go index 0a997ac..6cfd1f9 100644 --- a/internal/database/actions.go +++ b/internal/database/actions.go @@ -80,6 +80,7 @@ func GetMeasurementCounts(sess sqlbuilder.Database, resultID int64) (uint64, uin return totalCount, anmlyCount, err } + log.Debugf("counts: %d, %d, %d", resultID, totalCount, anmlyCount) return totalCount, anmlyCount, err } @@ -90,8 +91,9 @@ func ListResults(sess sqlbuilder.Database) ([]ResultNetwork, []ResultNetwork, er req := sess.Select( "networks.id AS network_id", - db.Raw("results.*"), + "results.id AS result_id", db.Raw("networks.*"), + db.Raw("results.*"), ).From("results"). Join("networks").On("results.network_id = networks.id"). OrderBy("results.start_time") diff --git a/internal/database/models.go b/internal/database/models.go index fd23e5d..83b2226 100644 --- a/internal/database/models.go +++ b/internal/database/models.go @@ -13,8 +13,10 @@ import ( // ResultNetwork is used to represent the structure made from the JOIN // between the results and networks tables. type ResultNetwork struct { - Result `db:",inline"` - Network `db:",inline"` + Result `db:",inline"` + ResultID int64 `db:"result_id"` + Network `db:",inline"` + NetworkID int64 `db:"network_id"` } // MeasurementURLNetwork is used for the JOIN between Measurement and URL diff --git a/internal/log/handlers/cli/cli.go b/internal/log/handlers/cli/cli.go index ca716d5..0aa718d 100644 --- a/internal/log/handlers/cli/cli.go +++ b/internal/log/handlers/cli/cli.go @@ -105,11 +105,13 @@ func logTable(w io.Writer, f log.Fields) error { func (h *Handler) TypedLog(t string, e *log.Entry) error { switch t { case "progress": - var err error - s := fmt.Sprintf("%.2f%%: %-25s", e.Fields.Get("percentage").(float64)*100, e.Message) - fmt.Fprintf(h.Writer, s) + perc := e.Fields.Get("percentage").(float64) * 100 + s := fmt.Sprintf(" %s\n %-25s", + bold.Sprintf("%.2f%%", perc), + bold.Sprint(e.Message)) + fmt.Fprint(h.Writer, s) fmt.Fprintln(h.Writer) - return err + return nil case "table": return logTable(h.Writer, e.Fields) case "result_item":