mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 13:46:44 -04:00
Refactor to merge Match.Status and Match.Winner fields into one.
This commit is contained in:
@@ -137,7 +137,7 @@ func (web *Web) rankingsApiHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
highestPlayedMatch := ""
|
||||
for _, match := range matches {
|
||||
if match.Status == "complete" {
|
||||
if match.IsComplete() {
|
||||
highestPlayedMatch = match.DisplayName
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ func TestRankingsApi(t *testing.T) {
|
||||
ranking2 := RankingWithNickname{*game.TestRanking1(), "ChezyPof"}
|
||||
web.arena.Database.CreateRanking(&ranking1.Ranking)
|
||||
web.arena.Database.CreateRanking(&ranking2.Ranking)
|
||||
web.arena.Database.CreateMatch(&model.Match{Type: "qualification", DisplayName: "29", Status: "complete"})
|
||||
web.arena.Database.CreateMatch(&model.Match{Type: "qualification", DisplayName: "29", Status: model.RedWonMatch})
|
||||
web.arena.Database.CreateMatch(&model.Match{Type: "qualification", DisplayName: "30"})
|
||||
web.arena.Database.CreateTeam(&model.Team{Id: 254, Nickname: "ChezyPof"})
|
||||
web.arena.Database.CreateTeam(&model.Team{Id: 1114, Nickname: "Simbots"})
|
||||
|
||||
@@ -25,7 +25,7 @@ type MatchPlayListItem struct {
|
||||
Id int
|
||||
DisplayName string
|
||||
Time string
|
||||
Status string
|
||||
Status model.MatchStatus
|
||||
ColorClass string
|
||||
}
|
||||
|
||||
@@ -357,16 +357,15 @@ func (web *Web) commitMatchScore(match *model.Match, matchResult *model.MatchRes
|
||||
}
|
||||
|
||||
// Update and save the match record to the database.
|
||||
match.Status = "complete"
|
||||
match.ScoreCommittedAt = time.Now()
|
||||
redScore := matchResult.RedScoreSummary(true)
|
||||
blueScore := matchResult.BlueScoreSummary(true)
|
||||
if redScore.Score > blueScore.Score {
|
||||
match.Winner = "R"
|
||||
match.Status = model.RedWonMatch
|
||||
} else if redScore.Score < blueScore.Score {
|
||||
match.Winner = "B"
|
||||
match.Status = model.BlueWonMatch
|
||||
} else {
|
||||
match.Winner = "T"
|
||||
match.Status = model.TieMatch
|
||||
}
|
||||
err := web.arena.Database.SaveMatch(match)
|
||||
if err != nil {
|
||||
@@ -407,10 +406,10 @@ func (web *Web) commitMatchScore(match *model.Match, matchResult *model.MatchRes
|
||||
// Generate awards if the tournament is over.
|
||||
if isTournamentWon {
|
||||
var winnerAllianceId, finalistAllianceId int
|
||||
if match.Winner == "R" {
|
||||
if match.Status == model.RedWonMatch {
|
||||
winnerAllianceId = match.ElimRedAlliance
|
||||
finalistAllianceId = match.ElimBlueAlliance
|
||||
} else if match.Winner == "B" {
|
||||
} else if match.Status == model.BlueWonMatch {
|
||||
winnerAllianceId = match.ElimBlueAlliance
|
||||
finalistAllianceId = match.ElimRedAlliance
|
||||
}
|
||||
@@ -474,7 +473,7 @@ func (list MatchPlayList) Len() int {
|
||||
|
||||
// Helper function to implement the required interface for Sort.
|
||||
func (list MatchPlayList) Less(i, j int) bool {
|
||||
return list[i].Status != "complete" && list[j].Status == "complete"
|
||||
return list[i].Status == model.MatchNotPlayed && list[j].Status != model.MatchNotPlayed
|
||||
}
|
||||
|
||||
// Helper function to implement the required interface for Sort.
|
||||
@@ -495,12 +494,12 @@ func (web *Web) buildMatchPlayList(matchType string) (MatchPlayList, error) {
|
||||
matchPlayList[i].DisplayName = match.TypePrefix() + match.DisplayName
|
||||
matchPlayList[i].Time = match.Time.Local().Format("3:04 PM")
|
||||
matchPlayList[i].Status = match.Status
|
||||
switch match.Winner {
|
||||
case "R":
|
||||
switch match.Status {
|
||||
case model.RedWonMatch:
|
||||
matchPlayList[i].ColorClass = "danger"
|
||||
case "B":
|
||||
case model.BlueWonMatch:
|
||||
matchPlayList[i].ColorClass = "info"
|
||||
case "T":
|
||||
case model.TieMatch:
|
||||
matchPlayList[i].ColorClass = "warning"
|
||||
default:
|
||||
matchPlayList[i].ColorClass = ""
|
||||
|
||||
@@ -22,10 +22,10 @@ import (
|
||||
func TestMatchPlay(t *testing.T) {
|
||||
web := setupTestWeb(t)
|
||||
|
||||
match1 := model.Match{Type: "practice", DisplayName: "1", Status: "complete", Winner: "R"}
|
||||
match1 := model.Match{Type: "practice", DisplayName: "1", Status: model.RedWonMatch}
|
||||
match2 := model.Match{Type: "practice", DisplayName: "2"}
|
||||
match3 := model.Match{Type: "qualification", DisplayName: "1", Status: "complete", Winner: "B"}
|
||||
match4 := model.Match{Type: "elimination", DisplayName: "SF1-1", Status: "complete", Winner: "T"}
|
||||
match3 := model.Match{Type: "qualification", DisplayName: "1", Status: model.BlueWonMatch}
|
||||
match4 := model.Match{Type: "elimination", DisplayName: "SF1-1", Status: model.TieMatch}
|
||||
match5 := model.Match{Type: "elimination", DisplayName: "SF1-2"}
|
||||
web.arena.Database.CreateMatch(&match1)
|
||||
web.arena.Database.CreateMatch(&match2)
|
||||
@@ -52,7 +52,7 @@ func TestMatchPlayLoad(t *testing.T) {
|
||||
web.arena.Database.CreateTeam(&model.Team{Id: 104})
|
||||
web.arena.Database.CreateTeam(&model.Team{Id: 105})
|
||||
web.arena.Database.CreateTeam(&model.Team{Id: 106})
|
||||
match := model.Match{Type: "elimination", DisplayName: "QF4-3", Status: "complete", Winner: "R", Red1: 101,
|
||||
match := model.Match{Type: "elimination", DisplayName: "QF4-3", Status: model.RedWonMatch, Red1: 101,
|
||||
Red2: 102, Red3: 103, Blue1: 104, Blue2: 105, Blue3: 106}
|
||||
web.arena.Database.CreateMatch(&match)
|
||||
recorder := web.getHttpResponse("/match_play")
|
||||
@@ -95,7 +95,7 @@ func TestMatchPlayShowResult(t *testing.T) {
|
||||
recorder := web.getHttpResponse("/match_play/1/show_result")
|
||||
assert.Equal(t, 500, recorder.Code)
|
||||
assert.Contains(t, recorder.Body.String(), "Invalid match")
|
||||
match := model.Match{Type: "qualification", DisplayName: "1", Status: "complete"}
|
||||
match := model.Match{Type: "qualification", DisplayName: "1", Status: model.TieMatch}
|
||||
web.arena.Database.CreateMatch(&match)
|
||||
recorder = web.getHttpResponse(fmt.Sprintf("/match_play/%d/show_result", match.Id))
|
||||
assert.Equal(t, 500, recorder.Code)
|
||||
@@ -138,7 +138,7 @@ func TestCommitMatch(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 1, matchResult.PlayNumber)
|
||||
match, _ = web.arena.Database.GetMatchById(1)
|
||||
assert.Equal(t, "B", match.Winner)
|
||||
assert.Equal(t, model.BlueWonMatch, match.Status)
|
||||
|
||||
matchResult = model.NewMatchResult()
|
||||
matchResult.MatchId = match.Id
|
||||
@@ -147,7 +147,7 @@ func TestCommitMatch(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 2, matchResult.PlayNumber)
|
||||
match, _ = web.arena.Database.GetMatchById(1)
|
||||
assert.Equal(t, "R", match.Winner)
|
||||
assert.Equal(t, model.RedWonMatch, match.Status)
|
||||
|
||||
matchResult = model.NewMatchResult()
|
||||
matchResult.MatchId = match.Id
|
||||
@@ -155,7 +155,7 @@ func TestCommitMatch(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 3, matchResult.PlayNumber)
|
||||
match, _ = web.arena.Database.GetMatchById(1)
|
||||
assert.Equal(t, "T", match.Winner)
|
||||
assert.Equal(t, model.TieMatch, match.Status)
|
||||
|
||||
// Verify TBA publishing by checking the log for the expected failure messages.
|
||||
web.arena.TbaClient.BaseUrl = "fakeUrl"
|
||||
@@ -184,12 +184,12 @@ func TestCommitEliminationTie(t *testing.T) {
|
||||
err := web.commitMatchScore(match, matchResult, true)
|
||||
assert.Nil(t, err)
|
||||
match, _ = web.arena.Database.GetMatchById(1)
|
||||
assert.Equal(t, "T", match.Winner)
|
||||
assert.Equal(t, model.TieMatch, match.Status)
|
||||
match.Type = "elimination"
|
||||
web.arena.Database.SaveMatch(match)
|
||||
web.commitMatchScore(match, matchResult, true)
|
||||
match, _ = web.arena.Database.GetMatchById(1)
|
||||
assert.Equal(t, "T", match.Winner) // No elimination tiebreakers.
|
||||
assert.Equal(t, model.TieMatch, match.Status) // No elimination tiebreakers.
|
||||
}
|
||||
|
||||
func TestCommitCards(t *testing.T) {
|
||||
|
||||
@@ -196,12 +196,12 @@ func (web *Web) buildMatchReviewList(matchType string) ([]MatchReviewListItem, e
|
||||
matchReviewList[i].RedScore = matchResult.RedScoreSummary(true).Score
|
||||
matchReviewList[i].BlueScore = matchResult.BlueScoreSummary(true).Score
|
||||
}
|
||||
switch match.Winner {
|
||||
case "R":
|
||||
switch match.Status {
|
||||
case model.RedWonMatch:
|
||||
matchReviewList[i].ColorClass = "danger"
|
||||
case "B":
|
||||
case model.BlueWonMatch:
|
||||
matchReviewList[i].ColorClass = "info"
|
||||
case "T":
|
||||
case model.TieMatch:
|
||||
matchReviewList[i].ColorClass = "warning"
|
||||
default:
|
||||
matchReviewList[i].ColorClass = ""
|
||||
|
||||
@@ -14,10 +14,10 @@ import (
|
||||
func TestMatchReview(t *testing.T) {
|
||||
web := setupTestWeb(t)
|
||||
|
||||
match1 := model.Match{Type: "practice", DisplayName: "1", Status: "complete", Winner: "R"}
|
||||
match1 := model.Match{Type: "practice", DisplayName: "1", Status: model.RedWonMatch}
|
||||
match2 := model.Match{Type: "practice", DisplayName: "2"}
|
||||
match3 := model.Match{Type: "qualification", DisplayName: "1", Status: "complete", Winner: "B"}
|
||||
match4 := model.Match{Type: "elimination", DisplayName: "SF1-1", Status: "complete", Winner: "T"}
|
||||
match3 := model.Match{Type: "qualification", DisplayName: "1", Status: model.BlueWonMatch}
|
||||
match4 := model.Match{Type: "elimination", DisplayName: "SF1-1", Status: model.TieMatch}
|
||||
match5 := model.Match{Type: "elimination", DisplayName: "SF1-2"}
|
||||
web.arena.Database.CreateMatch(&match1)
|
||||
web.arena.Database.CreateMatch(&match2)
|
||||
@@ -38,7 +38,7 @@ func TestMatchReview(t *testing.T) {
|
||||
func TestMatchReviewEditExistingResult(t *testing.T) {
|
||||
web := setupTestWeb(t)
|
||||
|
||||
match := model.Match{Type: "elimination", DisplayName: "QF4-3", Status: "complete", Winner: "R", Red1: 1001,
|
||||
match := model.Match{Type: "elimination", DisplayName: "QF4-3", Status: model.RedWonMatch, Red1: 1001,
|
||||
Red2: 1002, Red3: 1003, Blue1: 1004, Blue2: 1005, Blue3: 1006, ElimRedAlliance: 1, ElimBlueAlliance: 2}
|
||||
web.arena.Database.CreateMatch(&match)
|
||||
matchResult := model.BuildTestMatchResult(match.Id, 1)
|
||||
@@ -78,7 +78,7 @@ func TestMatchReviewEditExistingResult(t *testing.T) {
|
||||
func TestMatchReviewCreateNewResult(t *testing.T) {
|
||||
web := setupTestWeb(t)
|
||||
|
||||
match := model.Match{Type: "elimination", DisplayName: "QF4-3", Status: "complete", Winner: "R", Red1: 1001,
|
||||
match := model.Match{Type: "elimination", DisplayName: "QF4-3", Status: model.RedWonMatch, Red1: 1001,
|
||||
Red2: 1002, Red3: 1003, Blue1: 1004, Blue2: 1005, Blue3: 1006, ElimRedAlliance: 1, ElimBlueAlliance: 2}
|
||||
web.arena.Database.CreateMatch(&match)
|
||||
tournament.CreateTestAlliances(web.arena.Database, 2)
|
||||
|
||||
@@ -30,7 +30,7 @@ func (web *Web) queueingDisplayHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
var upcomingMatches []model.Match
|
||||
for i, match := range matches {
|
||||
if match.Status == "complete" {
|
||||
if match.IsComplete() {
|
||||
continue
|
||||
}
|
||||
upcomingMatches = append(upcomingMatches, match)
|
||||
|
||||
Reference in New Issue
Block a user