diff options
| author | NeKz <NeKzor@users.noreply.github.com> | 2024-11-16 21:53:35 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-16 23:53:35 +0300 |
| commit | 3d8afc2087d0072aaf15d5e2932cc4c3eb23a3b0 (patch) | |
| tree | b9037a31eb1364411d2a01de85f9e88bb73ac848 /rankings | |
| parent | feat/rankings: fetch profiles faster and improvements (#234) (diff) | |
| download | lphub-3d8afc2087d0072aaf15d5e2932cc4c3eb23a3b0.tar.gz lphub-3d8afc2087d0072aaf15d5e2932cc4c3eb23a3b0.tar.bz2 lphub-3d8afc2087d0072aaf15d5e2932cc4c3eb23a3b0.zip | |
feat/rankings: make sorting stable (#235)
Diffstat (limited to 'rankings')
| -rw-r--r-- | rankings/filter.go | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/rankings/filter.go b/rankings/filter.go index 2af7911..f90321f 100644 --- a/rankings/filter.go +++ b/rankings/filter.go | |||
| @@ -31,7 +31,12 @@ func filterRankings(spRankings, mpRankings, overallRankings *[]*Player, players | |||
| 31 | 31 | ||
| 32 | log.Println("sorting the ranks") | 32 | log.Println("sorting the ranks") |
| 33 | sort.Slice(*spRankings, func(i, j int) bool { | 33 | sort.Slice(*spRankings, func(i, j int) bool { |
| 34 | return (*spRankings)[i].SpScoreCount < (*spRankings)[j].SpScoreCount | 34 | a := (*spRankings)[i] |
| 35 | b := (*spRankings)[j] | ||
| 36 | if a.SpScoreCount == b.SpScoreCount { | ||
| 37 | return a.SteamID < b.SteamID | ||
| 38 | } | ||
| 39 | return a.SpScoreCount < b.SpScoreCount | ||
| 35 | }) | 40 | }) |
| 36 | 41 | ||
| 37 | rank := 1 | 42 | rank := 1 |
| @@ -52,7 +57,12 @@ func filterRankings(spRankings, mpRankings, overallRankings *[]*Player, players | |||
| 52 | } | 57 | } |
| 53 | 58 | ||
| 54 | sort.Slice(*mpRankings, func(i, j int) bool { | 59 | sort.Slice(*mpRankings, func(i, j int) bool { |
| 55 | return (*mpRankings)[i].MpScoreCount < (*mpRankings)[j].MpScoreCount | 60 | a := (*mpRankings)[i] |
| 61 | b := (*mpRankings)[j] | ||
| 62 | if a.MpScoreCount == b.MpScoreCount { | ||
| 63 | return a.SteamID < b.SteamID | ||
| 64 | } | ||
| 65 | return a.MpScoreCount < b.MpScoreCount | ||
| 56 | }) | 66 | }) |
| 57 | 67 | ||
| 58 | rank = 1 | 68 | rank = 1 |
| @@ -73,7 +83,12 @@ func filterRankings(spRankings, mpRankings, overallRankings *[]*Player, players | |||
| 73 | } | 83 | } |
| 74 | 84 | ||
| 75 | sort.Slice(*overallRankings, func(i, j int) bool { | 85 | sort.Slice(*overallRankings, func(i, j int) bool { |
| 76 | return (*overallRankings)[i].OverallScoreCount < (*overallRankings)[j].OverallScoreCount | 86 | a := (*overallRankings)[i] |
| 87 | b := (*overallRankings)[j] | ||
| 88 | if a.OverallScoreCount == b.OverallScoreCount { | ||
| 89 | return a.SteamID < b.SteamID | ||
| 90 | } | ||
| 91 | return a.OverallScoreCount < b.OverallScoreCount | ||
| 77 | }) | 92 | }) |
| 78 | 93 | ||
| 79 | rank = 1 | 94 | rank = 1 |