diff --git a/model/match_result.go b/model/match_result.go
index 41168178..a4efb45d 100644
--- a/model/match_result.go
+++ b/model/match_result.go
@@ -76,12 +76,12 @@ func (matchResult *MatchResult) BlueScoreSummary() *game.ScoreSummary {
func (matchResult *MatchResult) CorrectPlayoffScore() {
matchResult.RedScore.PlayoffDq = false
for _, card := range matchResult.RedCards {
- if card == "red" {
+ if card == "red" || card == "dq" {
matchResult.RedScore.PlayoffDq = true
}
}
for _, card := range matchResult.BlueCards {
- if card == "red" {
+ if card == "red" || card == "dq" {
matchResult.BlueScore.PlayoffDq = true
}
}
diff --git a/templates/edit_match_result.html b/templates/edit_match_result.html
index 845f49b2..1dbfc2e8 100644
--- a/templates/edit_match_result.html
+++ b/templates/edit_match_result.html
@@ -216,6 +216,12 @@
Notes in Traps
Red
+
+
+
diff --git a/tournament/qualification_rankings.go b/tournament/qualification_rankings.go
index c734669d..2a7603fb 100644
--- a/tournament/qualification_rankings.go
+++ b/tournament/qualification_rankings.go
@@ -107,13 +107,13 @@ func CalculateTeamCards(database *model.Database, matchType model.MatchType) 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 != "" {
+ if team, ok := teamsMap[teamId]; ok && (card == "red" || card == "yellow") {
team.YellowCard = true
teamsMap[teamId] = team
}
}
for teamId, card := range matchResult.BlueCards {
- if team, ok := teamsMap[teamId]; ok && card != "" {
+ if team, ok := teamsMap[teamId]; ok && (card == "red" || card == "yellow") {
team.YellowCard = true
teamsMap[teamId] = team
}
@@ -149,7 +149,7 @@ func addMatchResultToRankings(
cards = matchResult.BlueCards
}
disqualified := false
- if card, ok := cards[strconv.Itoa(teamId)]; ok && card == "red" {
+ if card, ok := cards[strconv.Itoa(teamId)]; ok && (card == "red" || card == "dq") {
disqualified = true
}
diff --git a/tournament/qualification_rankings_test.go b/tournament/qualification_rankings_test.go
index 812df295..dd6e455c 100644
--- a/tournament/qualification_rankings_test.go
+++ b/tournament/qualification_rankings_test.go
@@ -104,6 +104,25 @@ func TestCalculateRankings(t *testing.T) {
}
+func TestAddMatchResultToRankingsHandleCards(t *testing.T) {
+ rankings := map[int]*game.Ranking{}
+ matchResult := model.BuildTestMatchResult(1, 1)
+ matchResult.RedCards = map[string]string{"1": "yellow", "2": "red", "3": "dq"}
+ matchResult.BlueCards = map[string]string{"4": "red", "5": "dq", "6": "yellow"}
+ addMatchResultToRankings(rankings, 1, matchResult, true)
+ addMatchResultToRankings(rankings, 2, matchResult, true)
+ addMatchResultToRankings(rankings, 3, matchResult, true)
+ addMatchResultToRankings(rankings, 4, matchResult, false)
+ addMatchResultToRankings(rankings, 5, matchResult, false)
+ addMatchResultToRankings(rankings, 6, matchResult, false)
+ assert.Equal(t, 0, rankings[1].Disqualifications)
+ assert.Equal(t, 1, rankings[2].Disqualifications)
+ assert.Equal(t, 1, rankings[3].Disqualifications)
+ assert.Equal(t, 1, rankings[4].Disqualifications)
+ assert.Equal(t, 1, rankings[5].Disqualifications)
+ assert.Equal(t, 0, rankings[6].Disqualifications)
+}
+
// Sets up a schedule and results that touches on all possible variables.
func setupMatchResultsForRankings(database *model.Database) {
match1 := model.Match{Type: model.Qualification, TypeOrder: 1, Red1: 1, Red2: 2, Red3: 3, Blue1: 4, Blue2: 5,
diff --git a/web/match_play_test.go b/web/match_play_test.go
index 16be78ac..721d075c 100644
--- a/web/match_play_test.go
+++ b/web/match_play_test.go
@@ -190,34 +190,56 @@ func TestCommitCards(t *testing.T) {
web := setupTestWeb(t)
// Check that a yellow card sticks with a team.
- team := &model.Team{Id: 5}
- web.arena.Database.CreateTeam(team)
+ team1 := &model.Team{Id: 3}
+ team2 := &model.Team{Id: 5}
+ web.arena.Database.CreateTeam(team1)
+ web.arena.Database.CreateTeam(team2)
match := &model.Match{Id: 0, Type: model.Qualification, Red1: 1, Red2: 2, Red3: 3, Blue1: 4, Blue2: 5, Blue3: 6}
assert.Nil(t, web.arena.Database.CreateMatch(match))
matchResult := model.NewMatchResult()
matchResult.MatchId = match.Id
+ matchResult.RedCards = map[string]string{"3": "yellow"}
matchResult.BlueCards = map[string]string{"5": "yellow"}
err := web.commitMatchScore(match, matchResult, true)
assert.Nil(t, err)
- team, _ = web.arena.Database.GetTeamById(5)
- assert.True(t, team.YellowCard)
+ team1, _ = web.arena.Database.GetTeamById(3)
+ assert.True(t, team1.YellowCard)
+ team2, _ = web.arena.Database.GetTeamById(5)
+ assert.True(t, team2.YellowCard)
// Check that editing a match result removes a yellow card from a team.
matchResult = model.NewMatchResult()
matchResult.MatchId = match.Id
err = web.commitMatchScore(match, matchResult, true)
assert.Nil(t, err)
- team, _ = web.arena.Database.GetTeamById(5)
- assert.False(t, team.YellowCard)
+ team1, _ = web.arena.Database.GetTeamById(3)
+ assert.False(t, team1.YellowCard)
+ team2, _ = web.arena.Database.GetTeamById(5)
+ assert.False(t, team2.YellowCard)
// Check that a red card causes a yellow card to stick with a team.
matchResult = model.NewMatchResult()
matchResult.MatchId = match.Id
+ matchResult.RedCards = map[string]string{"3": "red"}
matchResult.BlueCards = map[string]string{"5": "red"}
err = web.commitMatchScore(match, matchResult, true)
assert.Nil(t, err)
- team, _ = web.arena.Database.GetTeamById(5)
- assert.True(t, team.YellowCard)
+ team1, _ = web.arena.Database.GetTeamById(3)
+ assert.True(t, team1.YellowCard)
+ team2, _ = web.arena.Database.GetTeamById(5)
+ assert.True(t, team2.YellowCard)
+
+ // Check that a DQ does not cause a yellow card to stick with a team.
+ matchResult = model.NewMatchResult()
+ matchResult.MatchId = match.Id
+ matchResult.RedCards = map[string]string{"3": "dq"}
+ matchResult.BlueCards = map[string]string{"5": "dq"}
+ err = web.commitMatchScore(match, matchResult, true)
+ assert.Nil(t, err)
+ team1, _ = web.arena.Database.GetTeamById(3)
+ assert.False(t, team1.YellowCard)
+ team2, _ = web.arena.Database.GetTeamById(5)
+ assert.False(t, team2.YellowCard)
// Check that a red card in playoffs zeroes out the score.
tournament.CreateTestAlliances(web.arena.Database, 2)
@@ -235,6 +257,13 @@ func TestCommitCards(t *testing.T) {
assert.Nil(t, web.commitMatchScore(match, matchResult, true))
assert.Equal(t, 0, matchResult.RedScoreSummary().Score)
assert.NotEqual(t, 0, matchResult.BlueScoreSummary().Score)
+
+ // Check that a DQ in playoffs zeroes out the score.
+ matchResult.RedCards = map[string]string{}
+ matchResult.BlueCards = map[string]string{"5": "dq"}
+ assert.Nil(t, web.commitMatchScore(match, matchResult, true))
+ assert.NotEqual(t, 0, matchResult.RedScoreSummary().Score)
+ assert.Equal(t, 0, matchResult.BlueScoreSummary().Score)
}
func TestMatchPlayWebsocketCommands(t *testing.T) {