mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 13:46:44 -04:00
Remove game-specific scoring
This commit is contained in:
68
tournament/qualification_rankings.go
Normal file → Executable file
68
tournament/qualification_rankings.go
Normal file → Executable file
@@ -9,7 +9,6 @@ import (
|
||||
"github.com/Team254/cheesy-arena/game"
|
||||
"github.com/Team254/cheesy-arena/model"
|
||||
"sort"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Determines the rankings from the stored match results, and saves them to the database.
|
||||
@@ -76,57 +75,6 @@ func CalculateRankings(database *model.Database, preservePreviousRank bool) (gam
|
||||
return sortedRankings, nil
|
||||
}
|
||||
|
||||
// Checks all the match results for yellow and red cards, and updates the team model accordingly.
|
||||
func CalculateTeamCards(database *model.Database, matchType string) error {
|
||||
teams, err := database.GetAllTeams()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
teamsMap := make(map[string]model.Team)
|
||||
for _, team := range teams {
|
||||
team.YellowCard = false
|
||||
teamsMap[strconv.Itoa(team.Id)] = team
|
||||
}
|
||||
|
||||
matches, err := database.GetMatchesByType(matchType)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, match := range matches {
|
||||
if !match.IsComplete() {
|
||||
continue
|
||||
}
|
||||
matchResult, err := database.GetMatchResultForMatch(match.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Mark the team as having a yellow card if they got either a yellow or red in a previous match.
|
||||
for teamId, card := range matchResult.RedCards {
|
||||
if team, ok := teamsMap[teamId]; ok && card != "" {
|
||||
team.YellowCard = true
|
||||
teamsMap[teamId] = team
|
||||
}
|
||||
}
|
||||
for teamId, card := range matchResult.BlueCards {
|
||||
if team, ok := teamsMap[teamId]; ok && card != "" {
|
||||
team.YellowCard = true
|
||||
teamsMap[teamId] = team
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Save the teams to the database.
|
||||
for _, team := range teamsMap {
|
||||
err = database.SaveTeam(&team)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Incrementally accounts for the given match result in the set of rankings that are being built.
|
||||
func addMatchResultToRankings(rankings map[int]*game.Ranking, teamId int, matchResult *model.MatchResult, isRed bool) {
|
||||
ranking := rankings[teamId]
|
||||
@@ -135,22 +83,10 @@ func addMatchResultToRankings(rankings map[int]*game.Ranking, teamId int, matchR
|
||||
rankings[teamId] = ranking
|
||||
}
|
||||
|
||||
// Determine whether the team was disqualified.
|
||||
var cards map[string]string
|
||||
if isRed {
|
||||
cards = matchResult.RedCards
|
||||
ranking.AddScoreSummary(matchResult.RedScoreSummary(), matchResult.BlueScoreSummary())
|
||||
} else {
|
||||
cards = matchResult.BlueCards
|
||||
}
|
||||
disqualified := false
|
||||
if card, ok := cards[strconv.Itoa(teamId)]; ok && card == "red" {
|
||||
disqualified = true
|
||||
}
|
||||
|
||||
if isRed {
|
||||
ranking.AddScoreSummary(matchResult.RedScoreSummary(true), matchResult.BlueScoreSummary(true), disqualified)
|
||||
} else {
|
||||
ranking.AddScoreSummary(matchResult.BlueScoreSummary(true), matchResult.RedScoreSummary(true), disqualified)
|
||||
ranking.AddScoreSummary(matchResult.BlueScoreSummary(), matchResult.RedScoreSummary())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,17 +19,17 @@ func TestCalculateRankings(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, updatedRankings, rankings)
|
||||
if assert.Equal(t, 6, len(rankings)) {
|
||||
assert.Equal(t, 4, rankings[0].TeamId)
|
||||
assert.Equal(t, 2, rankings[0].TeamId)
|
||||
assert.Equal(t, 0, rankings[0].PreviousRank)
|
||||
assert.Equal(t, 5, rankings[1].TeamId)
|
||||
assert.Equal(t, 3, rankings[1].TeamId)
|
||||
assert.Equal(t, 0, rankings[1].PreviousRank)
|
||||
assert.Equal(t, 6, rankings[2].TeamId)
|
||||
assert.Equal(t, 4, rankings[2].TeamId)
|
||||
assert.Equal(t, 0, rankings[2].PreviousRank)
|
||||
assert.Equal(t, 1, rankings[3].TeamId)
|
||||
assert.Equal(t, 0, rankings[3].PreviousRank)
|
||||
assert.Equal(t, 3, rankings[4].TeamId)
|
||||
assert.Equal(t, 6, rankings[4].TeamId)
|
||||
assert.Equal(t, 0, rankings[4].PreviousRank)
|
||||
assert.Equal(t, 2, rankings[5].TeamId)
|
||||
assert.Equal(t, 5, rankings[5].TeamId)
|
||||
assert.Equal(t, 0, rankings[5].PreviousRank)
|
||||
}
|
||||
|
||||
@@ -44,18 +44,18 @@ func TestCalculateRankings(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, updatedRankings, rankings)
|
||||
if assert.Equal(t, 6, len(rankings)) {
|
||||
assert.Equal(t, 6, rankings[0].TeamId)
|
||||
assert.Equal(t, 3, rankings[0].PreviousRank)
|
||||
assert.Equal(t, 5, rankings[1].TeamId)
|
||||
assert.Equal(t, 2, rankings[0].TeamId)
|
||||
assert.Equal(t, 1, rankings[0].PreviousRank)
|
||||
assert.Equal(t, 3, rankings[1].TeamId)
|
||||
assert.Equal(t, 2, rankings[1].PreviousRank)
|
||||
assert.Equal(t, 4, rankings[2].TeamId)
|
||||
assert.Equal(t, 1, rankings[2].PreviousRank)
|
||||
assert.Equal(t, 1, rankings[3].TeamId)
|
||||
assert.Equal(t, 4, rankings[3].PreviousRank)
|
||||
assert.Equal(t, 3, rankings[4].TeamId)
|
||||
assert.Equal(t, 5, rankings[4].PreviousRank)
|
||||
assert.Equal(t, 2, rankings[5].TeamId)
|
||||
assert.Equal(t, 6, rankings[5].PreviousRank)
|
||||
assert.Equal(t, 1, rankings[2].TeamId)
|
||||
assert.Equal(t, 4, rankings[2].PreviousRank)
|
||||
assert.Equal(t, 4, rankings[3].TeamId)
|
||||
assert.Equal(t, 3, rankings[3].PreviousRank)
|
||||
assert.Equal(t, 5, rankings[4].TeamId)
|
||||
assert.Equal(t, 6, rankings[4].PreviousRank)
|
||||
assert.Equal(t, 6, rankings[5].TeamId)
|
||||
assert.Equal(t, 5, rankings[5].PreviousRank)
|
||||
}
|
||||
|
||||
matchResult3 = model.BuildTestMatchResult(3, 4)
|
||||
@@ -68,34 +68,35 @@ func TestCalculateRankings(t *testing.T) {
|
||||
assert.Equal(t, updatedRankings, rankings)
|
||||
if assert.Equal(t, 6, len(rankings)) {
|
||||
assert.Equal(t, 4, rankings[0].TeamId)
|
||||
assert.Equal(t, 1, rankings[0].PreviousRank)
|
||||
assert.Equal(t, 5, rankings[1].TeamId)
|
||||
assert.Equal(t, 2, rankings[1].PreviousRank)
|
||||
assert.Equal(t, 1, rankings[2].TeamId)
|
||||
assert.Equal(t, 4, rankings[2].PreviousRank)
|
||||
assert.Equal(t, 3, rankings[3].TeamId)
|
||||
assert.Equal(t, 3, rankings[0].PreviousRank)
|
||||
assert.Equal(t, 2, rankings[1].TeamId)
|
||||
assert.Equal(t, 1, rankings[1].PreviousRank)
|
||||
assert.Equal(t, 3, rankings[2].TeamId)
|
||||
assert.Equal(t, 2, rankings[2].PreviousRank)
|
||||
assert.Equal(t, 6, rankings[3].TeamId)
|
||||
assert.Equal(t, 5, rankings[3].PreviousRank)
|
||||
assert.Equal(t, 6, rankings[4].TeamId)
|
||||
assert.Equal(t, 3, rankings[4].PreviousRank)
|
||||
assert.Equal(t, 2, rankings[5].TeamId)
|
||||
assert.Equal(t, 6, rankings[5].PreviousRank)
|
||||
assert.Equal(t, 5, rankings[4].TeamId)
|
||||
assert.Equal(t, 6, rankings[4].PreviousRank)
|
||||
assert.Equal(t, 1, rankings[5].TeamId)
|
||||
assert.Equal(t, 4, rankings[5].PreviousRank)
|
||||
}
|
||||
}
|
||||
|
||||
// Sets up a schedule and results that touches on all possible variables.
|
||||
func setupMatchResultsForRankings(database *model.Database) {
|
||||
match1 := model.Match{Type: "qualification", DisplayName: "1", Red1: 1, Red2: 2, Red3: 3, Blue1: 4, Blue2: 5,
|
||||
Blue3: 6, Status: model.RedWonMatch}
|
||||
Blue3: 6, Status: model.RedWonMatch, Red2IsSurrogate: true}
|
||||
database.CreateMatch(&match1)
|
||||
matchResult1 := model.BuildTestMatchResult(match1.Id, 1)
|
||||
matchResult1.RedCards = map[string]string{"2": "red"}
|
||||
database.CreateMatchResult(matchResult1)
|
||||
|
||||
match2 := model.Match{Type: "qualification", DisplayName: "2", Red1: 1, Red2: 3, Red3: 5, Blue1: 2, Blue2: 4,
|
||||
Blue3: 6, Status: model.BlueWonMatch, Red2IsSurrogate: true, Blue3IsSurrogate: true}
|
||||
database.CreateMatch(&match2)
|
||||
matchResult2 := model.BuildTestMatchResult(match2.Id, 1)
|
||||
matchResult2.BlueScore = matchResult2.RedScore
|
||||
matchResult2.BlueScore, matchResult2.RedScore = matchResult2.RedScore, matchResult2.BlueScore
|
||||
matchResult2.RedScore.AutoPoints += 2
|
||||
matchResult2.BlueScore.AutoPoints += 2
|
||||
database.CreateMatchResult(matchResult2)
|
||||
|
||||
match3 := model.Match{Type: "qualification", DisplayName: "3", Red1: 6, Red2: 5, Red3: 4, Blue1: 3, Blue2: 2,
|
||||
|
||||
Reference in New Issue
Block a user