From df6f6cb5ff8957be8f01d58d60857da2c094a3d9 Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Thu, 12 Sep 2024 00:25:15 +0300 Subject: refactor: unofficial rankings implementation --- rankings/filter.go | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 rankings/filter.go (limited to 'rankings/filter.go') 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 @@ +package main + +import ( + "log" + "sort" +) + +func filterRankings(spRankings, mpRankings, overallRankings *[]*Player, players *map[string]*Player) { + for k, p := range *players { + if p.SpIterations == 51 { + *spRankings = append(*spRankings, p) + } + if p.MpIterations == 48 { + *mpRankings = append(*mpRankings, p) + } + if p.SpIterations == 51 && p.MpIterations == 48 { + p.OverallScoreCount = p.SpScoreCount + p.MpScoreCount + *overallRankings = append(*overallRankings, p) + } + if p.SpIterations < 51 && p.MpIterations < 48 { + delete(*players, k) + } + } + + log.Println("getting player summaries") + for _, v := range *players { + fetchPlayerInfo(v) + } + + log.Println("sorting the ranks") + sort.Slice(*spRankings, func(i, j int) bool { + return (*spRankings)[i].SpScoreCount < (*spRankings)[j].SpScoreCount + }) + + rank := 1 + + for idx := 0; idx < len(*spRankings); idx++ { + if idx == 0 { + (*spRankings)[idx].SpRank = rank + continue + } + if (*spRankings)[idx-1].SpScoreCount != (*spRankings)[idx].SpScoreCount { + rank++ + } + (*spRankings)[idx].SpRank = rank + } + + sort.Slice(*mpRankings, func(i, j int) bool { + return (*mpRankings)[i].MpScoreCount < (*mpRankings)[j].MpScoreCount + }) + + rank = 1 + + for idx := 0; idx < len(*mpRankings); idx++ { + if idx == 0 { + (*mpRankings)[idx].MpRank = rank + continue + } + if (*mpRankings)[idx-1].MpScoreCount != (*mpRankings)[idx].MpScoreCount { + rank++ + } + (*mpRankings)[idx].MpRank = rank + } + + sort.Slice(*overallRankings, func(i, j int) bool { + return (*overallRankings)[i].OverallScoreCount < (*overallRankings)[j].OverallScoreCount + }) + + rank = 1 + + for idx := 0; idx < len(*overallRankings); idx++ { + if idx == 0 { + (*overallRankings)[idx].OverallRank = rank + continue + } + if (*overallRankings)[idx-1].OverallScoreCount != (*overallRankings)[idx].OverallScoreCount { + rank++ + } + (*overallRankings)[idx].OverallRank = rank + } +} -- cgit v1.2.3