1
|
|
|
// Copyright 2018 Fedir RYKHTIK. All rights reserved. |
2
|
|
|
// Use of this source code is governed by the GNU GPL 3.0 |
3
|
|
|
// license that can be found in the LICENSE file. |
4
|
|
|
|
5
|
|
|
package main |
6
|
|
|
|
7
|
|
|
import ( |
8
|
|
|
"fmt" |
9
|
|
|
"log" |
10
|
|
|
"strconv" |
11
|
|
|
) |
12
|
|
|
|
13
|
|
|
func rateGhData(ghData [][]string, columnsIndexes map[string]int) string { |
14
|
1 |
|
greetings := "" |
15
|
|
|
// Add points by repository total popularity (more popular is better) |
16
|
1 |
|
sortSliceByColumnIndexIntDesc(ghData, columnsIndexes["stargazersColumn"]) |
17
|
1 |
|
greetings += fmt.Sprintf("* The most popular project is `%s`\n", ghData[0][0]) |
18
|
1 |
|
addPoints(ghData, columnsIndexes["stargazersColumn"], columnsIndexes["totalPointsColumnIndex"]) |
19
|
|
|
// Add points by project age (we like fresh ideas) |
20
|
1 |
|
sortSliceByColumnIndexIntAsc(ghData, columnsIndexes["ageColumn"]) |
21
|
1 |
|
greetings += fmt.Sprintf("* The newest project is `%s`\n", ghData[0][0]) |
22
|
1 |
|
addPoints(ghData, columnsIndexes["ageColumn"], columnsIndexes["totalPointsColumnIndex"]) |
23
|
|
|
// Add points by number of commits (more commits is better) |
24
|
1 |
|
sortSliceByColumnIndexIntDesc(ghData, columnsIndexes["totalCommitsColumn"]) |
25
|
1 |
|
greetings += fmt.Sprintf("* The project with more commits is `%s`\n", ghData[0][0]) |
26
|
1 |
|
addPoints(ghData, columnsIndexes["totalCommitsColumn"], columnsIndexes["totalPointsColumnIndex"]) |
27
|
|
|
// Add points by number of tags (more tags is better) |
28
|
1 |
|
sortSliceByColumnIndexIntDesc(ghData, columnsIndexes["totalTagsColumn"]) |
29
|
1 |
|
greetings += fmt.Sprintf("* The project with more tags is `%s`\n", ghData[0][0]) |
30
|
1 |
|
addPoints(ghData, columnsIndexes["totalCommitsColumn"], columnsIndexes["totalPointsColumnIndex"]) |
31
|
|
|
// Add points by Top10 contributors followers |
32
|
1 |
|
sortSliceByColumnIndexIntDesc(ghData, columnsIndexes["top10ContributorsFollowersColumn"]) |
33
|
1 |
|
greetings += fmt.Sprintf("* The project made by most notable top contributors is `%s`\n", ghData[0][0]) |
34
|
1 |
|
addPoints(ghData, columnsIndexes["top10ContributorsFollowersColumn"], columnsIndexes["totalPointsColumnIndex"]) |
35
|
|
|
// Add points by proportion of total and resolved issues (less opened issues is better) |
36
|
1 |
|
sortSliceByColumnIndexFloatDesc(ghData, columnsIndexes["closedIssuesPercentageColumn"]) |
37
|
1 |
|
greetings += fmt.Sprintf("* The project with best errors resolving rate is `%s`\n", ghData[0][0]) |
38
|
1 |
|
addPoints(ghData, columnsIndexes["closedIssuesPercentageColumn"], columnsIndexes["totalPointsColumnIndex"]) |
39
|
|
|
// Add points by commits by day (more commits shows good healthy community) |
40
|
1 |
|
sortSliceByColumnIndexFloatDesc(ghData, columnsIndexes["commitsByDayColumn"]) |
41
|
1 |
|
greetings += fmt.Sprintf("* The project with more commits by day is `%s`\n", ghData[0][0]) |
42
|
1 |
|
addPoints(ghData, columnsIndexes["activeForkersColumn"], columnsIndexes["totalPointsColumnIndex"]) |
43
|
|
|
// Add points by active forkers (more active forkers shows good open source spirit of the community) |
44
|
1 |
|
sortSliceByColumnIndexFloatDesc(ghData, columnsIndexes["activeForkersColumn"]) |
45
|
1 |
|
greetings += fmt.Sprintf("* The project with the most active community is `%s`\n", ghData[0][0]) |
46
|
1 |
|
addPoints(ghData, columnsIndexes["activeForkersColumn"], columnsIndexes["totalPointsColumnIndex"]) |
47
|
|
|
// Assign places to projects by all metrics |
48
|
1 |
|
sortSliceByColumnIndexIntAsc(ghData, columnsIndexes["totalPointsColumnIndex"]) |
49
|
1 |
|
greetings += fmt.Sprintf("* The best project (taking in account placements in all competitions) is `%s`\n", ghData[0][0]) |
50
|
1 |
|
assignPlaces(ghData, columnsIndexes["totalPointsColumnIndex"]) |
51
|
1 |
|
return greetings |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
func addPoints(s [][]string, columnIndex int, totalPointsColumnIndex int) [][]string { |
55
|
1 |
|
if totalPointsColumnIndex == 0 { |
56
|
|
|
log.Fatalf("Error occurred. Please check map of columns indexes") |
57
|
|
|
} |
58
|
1 |
|
for i := range s { |
59
|
1 |
|
currentValue, _ := strconv.Atoi(s[i][totalPointsColumnIndex]) |
60
|
1 |
|
currentValue = currentValue + i + 1 |
61
|
1 |
|
s[i][totalPointsColumnIndex] = strconv.Itoa(currentValue) |
62
|
|
|
} |
63
|
1 |
|
return s |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
func firstPlaceGreeting(s [][]string, message string) string { |
67
|
|
|
return fmt.Sprintf("* %s `%s`\n", message, s[0][0]) |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
func assignPlaces(s [][]string, totalPointsColumnIndex int) [][]string { |
71
|
1 |
|
if totalPointsColumnIndex == 0 { |
72
|
|
|
log.Fatalf("Error occurred. Please check map of columns indexes") |
73
|
|
|
} |
74
|
1 |
|
for i := range s { |
75
|
1 |
|
place := i + 1 |
76
|
1 |
|
s[i][totalPointsColumnIndex] = strconv.Itoa(place) |
77
|
|
|
} |
78
|
1 |
|
return s |
79
|
|
|
} |
80
|
|
|
|