feat(parser/clangtidy): show occurrences summary
This commit is contained in:
		
							parent
							
								
									28777fa68c
								
							
						
					
					
						commit
						94f361c46a
					
				|  | @ -2,47 +2,53 @@ package clangtidy | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"fmt" | 	"fmt" | ||||||
|  | 	"sort" | ||||||
| 	"strings" | 	"strings" | ||||||
| 
 |  | ||||||
| 	"github.com/joint-online-judge/JOJ3/pkg/utils" |  | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func GetResult(jsonMessages []JsonMessage, conf Conf) (int, string) { | func GetResult(jsonMessages []JsonMessage, conf Conf) (int, string) { | ||||||
| 	score := conf.Score | 	score := conf.Score | ||||||
| 	comment := "### Test results summary\n\n" | 	comment := "### Test results summary\n\n" | ||||||
| 	categoryCount := map[string]int{} | 	matchCount := make(map[string]int) | ||||||
|  | 	scoreChange := make(map[string]int) | ||||||
| 	for _, jsonMessage := range jsonMessages { | 	for _, jsonMessage := range jsonMessages { | ||||||
| 		// checkName is commas separated string here
 | 		// checkName is commas separated string here
 | ||||||
| 		checkName := jsonMessage.CheckName | 		checkName := jsonMessage.CheckName | ||||||
| 		for _, match := range conf.Matches { | 		for _, match := range conf.Matches { | ||||||
| 			for _, keyword := range match.Keywords { | 			for _, keyword := range match.Keywords { | ||||||
| 				if strings.Contains(checkName, keyword) { | 				if strings.Contains(checkName, keyword) { | ||||||
| 					score -= match.Score | 					matchCount[keyword]++ | ||||||
|  | 					scoreChange[keyword] += -match.Score | ||||||
|  | 					score += -match.Score | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 		checkNames := strings.Split(checkName, ",") |  | ||||||
| 		for _, checkName := range checkNames { |  | ||||||
| 			parts := strings.Split(checkName, "-") |  | ||||||
| 			if len(parts) > 0 { |  | ||||||
| 				category := parts[0] |  | ||||||
| 				// checkName might be: -warnings-as-errors
 |  | ||||||
| 				if category == "" { |  | ||||||
| 					continue |  | ||||||
| 	} | 	} | ||||||
| 				categoryCount[category] += 1 | 	type Result struct { | ||||||
|  | 		Keyword     string | ||||||
|  | 		Count       int | ||||||
|  | 		ScoreChange int | ||||||
| 	} | 	} | ||||||
| 		} | 	var results []Result | ||||||
| 	} | 	for keyword, count := range matchCount { | ||||||
| 	sortedMap := utils.SortMap(categoryCount, | 		results = append(results, Result{ | ||||||
| 		func(i, j utils.Pair[string, int]) bool { | 			Keyword:     keyword, | ||||||
| 			if i.Value == j.Value { | 			Count:       count, | ||||||
| 				return i.Key < j.Key | 			ScoreChange: scoreChange[keyword], | ||||||
| 			} |  | ||||||
| 			return i.Value > j.Value |  | ||||||
| 		}) | 		}) | ||||||
| 	for i, kv := range sortedMap { | 	} | ||||||
| 		comment += fmt.Sprintf("%d. %s: %d\n", i+1, kv.Key, kv.Value) | 	sort.Slice(results, func(i, j int) bool { | ||||||
|  | 		if results[i].ScoreChange != results[j].ScoreChange { | ||||||
|  | 			return results[i].ScoreChange < results[j].ScoreChange | ||||||
|  | 		} | ||||||
|  | 		if results[i].Count != results[j].Count { | ||||||
|  | 			return results[i].Count > results[j].Count | ||||||
|  | 		} | ||||||
|  | 		return results[i].Keyword < results[j].Keyword | ||||||
|  | 	}) | ||||||
|  | 	for i, result := range results { | ||||||
|  | 		comment += fmt.Sprintf("%d. `%s`: %d occurrences, %d point(s)\n", | ||||||
|  | 			i+1, result.Keyword, result.Count, result.ScoreChange) | ||||||
| 	} | 	} | ||||||
| 	return score, comment | 	return score, comment | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user