From 248b2aef9f2c09fe95deaf09f45a4ca036f01a51 Mon Sep 17 00:00:00 2001 From: Leon Zhang Date: Thu, 18 Apr 2019 16:12:34 +0800 Subject: [PATCH] fix #199 --- advisor/rules.go | 14 ++++++++++++++ .../fixture/test_Check_soar_report_for_json.golden | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/advisor/rules.go b/advisor/rules.go index 617d7cf..245d8bb 100644 --- a/advisor/rules.go +++ b/advisor/rules.go @@ -1460,11 +1460,25 @@ func formatJSON(sql string, db string, suggest map[string]Rule) string { fingerprint = query.Fingerprint(sql) id = query.Id(fingerprint) + // Score + score := 100 + for item := range suggest { + l, err := strconv.Atoi(strings.TrimLeft(suggest[item].Severity, "L")) + if err != nil { + common.Log.Error("formatJSON strconv.Atoi error: %s, item: %s, serverity: %s", err.Error(), item, suggest[item].Severity) + } + score = score - l*5 + } + if score < 0 { + score = 0 + } + sug := JSONSuggest{ ID: id, Fingerprint: fingerprint, Sample: sql, Tables: ast.SchemaMetaInfo(sql, db), + Score: score, } // Explain info diff --git a/test/fixture/test_Check_soar_report_for_json.golden b/test/fixture/test_Check_soar_report_for_json.golden index d9dd3ae..50374d0 100644 --- a/test/fixture/test_Check_soar_report_for_json.golden +++ b/test/fixture/test_Check_soar_report_for_json.golden @@ -2,7 +2,7 @@ { "ID": "687D590364E29465", "Fingerprint": "select * from film", - "Score": 0, + "Score": 75, "Sample": "select * from film", "Explain": null, "HeuristicRules": [ -- GitLab