aboutsummaryrefslogtreecommitdiff
path: root/rankings/filter.go
diff options
context:
space:
mode:
Diffstat (limited to 'rankings/filter.go')
-rw-r--r--rankings/filter.go81
1 files changed, 81 insertions, 0 deletions
diff --git a/rankings/filter.go b/rankings/filter.go
new file mode 100644
index 0000000..5f54a81
--- /dev/null
+++ b/rankings/filter.go
@@ -0,0 +1,81 @@
1package main
2
3import (
4 "log"
5 "sort"
6)
7
8func filterRankings(spRankings, mpRankings, overallRankings *[]*Player, players *map[string]*Player) {
9 for k, p := range *players {
10 if p.SpIterations == 51 {
11 *spRankings = append(*spRankings, p)
12 }
13 if p.MpIterations == 48 {
14 *mpRankings = append(*mpRankings, p)
15 }
16 if p.SpIterations == 51 && p.MpIterations == 48 {
17 p.OverallScoreCount = p.SpScoreCount + p.MpScoreCount
18 *overallRankings = append(*overallRankings, p)
19 }
20 if p.SpIterations < 51 && p.MpIterations < 48 {
21 delete(*players, k)
22 }
23 }
24
25 log.Println("getting player summaries")
26 for _, v := range *players {
27 fetchPlayerInfo(v)
28 }
29
30 log.Println("sorting the ranks")
31 sort.Slice(*spRankings, func(i, j int) bool {
32 return (*spRankings)[i].SpScoreCount < (*spRankings)[j].SpScoreCount
33 })
34
35 rank := 1
36
37 for idx := 0; idx < len(*spRankings); idx++ {
38 if idx == 0 {
39 (*spRankings)[idx].SpRank = rank
40 continue
41 }
42 if (*spRankings)[idx-1].SpScoreCount != (*spRankings)[idx].SpScoreCount {
43 rank++
44 }
45 (*spRankings)[idx].SpRank = rank
46 }
47
48 sort.Slice(*mpRankings, func(i, j int) bool {
49 return (*mpRankings)[i].MpScoreCount < (*mpRankings)[j].MpScoreCount
50 })
51
52 rank = 1
53
54 for idx := 0; idx < len(*mpRankings); idx++ {
55 if idx == 0 {
56 (*mpRankings)[idx].MpRank = rank
57 continue
58 }
59 if (*mpRankings)[idx-1].MpScoreCount != (*mpRankings)[idx].MpScoreCount {
60 rank++
61 }
62 (*mpRankings)[idx].MpRank = rank
63 }
64
65 sort.Slice(*overallRankings, func(i, j int) bool {
66 return (*overallRankings)[i].OverallScoreCount < (*overallRankings)[j].OverallScoreCount
67 })
68
69 rank = 1
70
71 for idx := 0; idx < len(*overallRankings); idx++ {
72 if idx == 0 {
73 (*overallRankings)[idx].OverallRank = rank
74 continue
75 }
76 if (*overallRankings)[idx-1].OverallScoreCount != (*overallRankings)[idx].OverallScoreCount {
77 rank++
78 }
79 (*overallRankings)[idx].OverallRank = rank
80 }
81}