Skip to content

Commit

Permalink
Merge pull request #17 from coticom/main
Browse files Browse the repository at this point in the history
update special award rank rule
  • Loading branch information
coticom authored Mar 30, 2023
2 parents ff1e6a3 + 317652c commit 5ce5b9b
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion internal/app/service/subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,32 @@ func (svc *SubscribeService) SpecialAwards() (*dto.ChallengeScoreDTO, error) {
}
var challengeScore dto.ChallengeScoreDTO
if len(res) > 0 {
var scoreNums ScoreNums
sMap := make(map[int]int)
for _, v := range res {
sMap[v.FinalScore] += 1
}
for k, v := range sMap {
var scoreNum ScoreNum
scoreNum.Score = k
scoreNum.Num = v
scoreNums = append(scoreNums, scoreNum)
}
sort.Sort(scoreNums)

challengeScore.UpdateTime = res[0].UpdateTime
var scores dto.Scores
for _, v := range res {
var scoreRank dto.ScoreRank
scoreRank.Rank = v.Rank
rank := 1
for _, sn := range scoreNums {
if v.FinalScore == sn.Score {
scoreRank.Rank = rank
break
}
rank += sn.Num
}
//scoreRank.Rank = v.Rank
scoreRank.TeamName = v.TeamName
scoreRank.TaskCompleted = v.TaskCompleted
scoreRank.FinalScore = v.FinalScore
Expand Down

0 comments on commit 5ce5b9b

Please sign in to comment.