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
|
|
|
"sort" |
10
|
|
|
) |
11
|
|
|
|
12
|
|
|
func rateAndPrintGreetings(ghData []Repository) { |
13
|
1 |
|
greetings := rateGhData(ghData) |
14
|
1 |
|
fmt.Println(greetings) |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
func rateGhData(ghData []Repository) string { |
18
|
|
|
|
19
|
1 |
|
greetings := "" |
20
|
|
|
|
21
|
|
|
// Add points by repository total popularity (more popular is better) |
22
|
1 |
|
sort.Slice(ghData[:], func(i, j int) bool { |
23
|
1 |
|
return ghData[i].Watchers > ghData[j].Watchers |
24
|
|
|
}) |
25
|
1 |
|
greetings += fmt.Sprintf("* The most popular project is `%s`\n", ghData[0].Name) |
26
|
1 |
|
for i := range ghData { |
27
|
1 |
|
ghData[i].PlacementPopularity = ghData[i].PlacementPopularity + i |
28
|
1 |
|
ghData[i].PlacementOverall = ghData[i].PlacementOverall + i |
29
|
|
|
} |
30
|
|
|
|
31
|
1 |
|
greetings += fmt.Sprintf("* The newest project is `%s`\n", ghData[0].Name) |
32
|
1 |
|
for i := range ghData { |
33
|
1 |
|
ghData[i].PlacementAge = ghData[i].PlacementAge + i |
34
|
1 |
|
ghData[i].PlacementOverall = ghData[i].PlacementOverall + i |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
// Add points by number of commits (more commits is better) |
38
|
1 |
|
sort.Slice(ghData[:], func(i, j int) bool { |
39
|
1 |
|
return ghData[i].TotalCommits > ghData[j].TotalCommits |
40
|
|
|
}) |
41
|
1 |
|
greetings += fmt.Sprintf("* The project with more commits is `%s`\n", ghData[0].Name) |
42
|
1 |
|
for i := range ghData { |
43
|
1 |
|
ghData[i].PlacementTotalCommits = ghData[i].PlacementTotalCommits + i |
44
|
1 |
|
ghData[i].PlacementOverall = ghData[i].PlacementOverall + i |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
// Add points by number of tags (more tags is better) |
48
|
1 |
|
sort.Slice(ghData[:], func(i, j int) bool { |
49
|
1 |
|
return ghData[i].TotalTags > ghData[j].TotalTags |
50
|
|
|
}) |
51
|
1 |
|
greetings += fmt.Sprintf("* The project with more tags is `%s`\n", ghData[0].Name) |
52
|
1 |
|
for i := range ghData { |
53
|
1 |
|
ghData[i].PlacementTotalTags = ghData[i].PlacementTotalTags + i |
54
|
1 |
|
ghData[i].PlacementOverall = ghData[i].PlacementOverall + i |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
// Add points by Top10 contributors followers |
58
|
1 |
|
sort.Slice(ghData[:], func(i, j int) bool { |
59
|
1 |
|
return ghData[i].Top10ContributorsFollowers > ghData[j].Top10ContributorsFollowers |
60
|
|
|
}) |
61
|
1 |
|
greetings += fmt.Sprintf("* The project made by most notable top contributors is `%s`\n", ghData[0].Name) |
62
|
1 |
|
for i := range ghData { |
63
|
1 |
|
ghData[i].PlacementTop10ContributorsFollowers = ghData[i].PlacementTop10ContributorsFollowers + i |
64
|
1 |
|
ghData[i].PlacementOverall = ghData[i].PlacementOverall + i |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
// Add points by Top10 contributors followers |
68
|
1 |
|
sort.Slice(ghData[:], func(i, j int) bool { |
69
|
1 |
|
return ghData[i].ClosedIssuesPercentage > ghData[j].ClosedIssuesPercentage |
70
|
|
|
}) |
71
|
1 |
|
greetings += fmt.Sprintf("* The project with best errors resolving rate is `%s`\n", ghData[0].Name) |
72
|
1 |
|
for i := range ghData { |
73
|
1 |
|
ghData[i].PlacementClosedIssuesPercentage = ghData[i].PlacementClosedIssuesPercentage + i |
74
|
1 |
|
ghData[i].PlacementOverall = ghData[i].PlacementOverall + i |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
// Add points by commits by day (more commits shows good healthy community) |
78
|
1 |
|
sort.Slice(ghData[:], func(i, j int) bool { |
79
|
1 |
|
return ghData[i].CommitsByDay > ghData[j].CommitsByDay |
80
|
|
|
}) |
81
|
1 |
|
greetings += fmt.Sprintf("* The project with more commits by day is `%s`\n", ghData[0].Name) |
82
|
1 |
|
for i := range ghData { |
83
|
1 |
|
ghData[i].PlacementCommitsByDay = ghData[i].PlacementCommitsByDay + i |
84
|
1 |
|
ghData[i].PlacementOverall = ghData[i].PlacementOverall + i |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
// Add points by active forkers (more active forkers shows good open source spirit of the community) |
88
|
1 |
|
sort.Slice(ghData[:], func(i, j int) bool { |
89
|
1 |
|
return ghData[i].ActiveForkersPercentage > ghData[j].ActiveForkersPercentage |
90
|
|
|
}) |
91
|
1 |
|
greetings += fmt.Sprintf("* The project with the most active community is `%s`\n", ghData[0].Name) |
92
|
1 |
|
for i := range ghData { |
93
|
1 |
|
ghData[i].PlacementActiveForkersColumn = ghData[i].PlacementActiveForkersColumn + i |
94
|
1 |
|
ghData[i].PlacementOverall = ghData[i].PlacementOverall + i |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
// Assign places to projects by all metrics |
98
|
1 |
|
sort.Slice(ghData[:], func(i, j int) bool { |
99
|
1 |
|
return ghData[i].PlacementOverall < ghData[j].PlacementOverall |
100
|
|
|
}) |
101
|
1 |
|
greetings += fmt.Sprintf("* The best project (taking in account placements in all competitions) is `%s`\n", ghData[0].Name) |
102
|
|
|
|
103
|
1 |
|
return greetings |
104
|
|
|
} |
105
|
|
|
|