diff --git a/advisor/rules.go b/advisor/rules.go index 617d7cf37514b0ba7205740ddb9548e30eb15747..245d8bb6a4c36c7e089ea30915426804d6a8c14e 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 d9dd3ae53acb41656d559b006c7f150116cf6c8f..50374d04a35f7d948bd173d1517dcb3ed8e5eaa7 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": [