mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 13:46:44 -04:00
Implement translation of double-elimination match keys when pushing to TBA.
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Team254/cheesy-arena-lite/game"
|
||||
"sort"
|
||||
"strings"
|
||||
@@ -40,8 +39,6 @@ type Match struct {
|
||||
Status game.MatchStatus
|
||||
}
|
||||
|
||||
var elimRoundNames = map[int]string{1: "F", 2: "SF", 4: "QF", 8: "EF"}
|
||||
|
||||
func (database *Database) CreateMatch(match *Match) error {
|
||||
return database.matchTable.create(match)
|
||||
}
|
||||
@@ -141,16 +138,6 @@ func (match *Match) TypePrefix() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (match *Match) TbaCode() string {
|
||||
if match.Type == "qualification" {
|
||||
return fmt.Sprintf("qm%s", match.DisplayName)
|
||||
} else if match.Type == "elimination" {
|
||||
return fmt.Sprintf("%s%dm%d", strings.ToLower(elimRoundNames[match.ElimRound]), match.ElimGroup,
|
||||
match.ElimInstance)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// Returns true if the match is of a type that allows substitution of teams.
|
||||
func (match *Match) ShouldAllowSubstitution() bool {
|
||||
return match.Type != "qualification"
|
||||
|
||||
@@ -112,18 +112,3 @@ func TestGetMatchesByType(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 1, len(matches))
|
||||
}
|
||||
|
||||
func TestTbaCode(t *testing.T) {
|
||||
match := Match{Type: "practice", DisplayName: "3"}
|
||||
assert.Equal(t, "", match.TbaCode())
|
||||
match = Match{Type: "qualification", DisplayName: "26"}
|
||||
assert.Equal(t, "qm26", match.TbaCode())
|
||||
match = Match{Type: "elimination", DisplayName: "EF2-1", ElimRound: 8, ElimGroup: 2, ElimInstance: 1}
|
||||
assert.Equal(t, "ef2m1", match.TbaCode())
|
||||
match = Match{Type: "elimination", DisplayName: "QF3-2", ElimRound: 4, ElimGroup: 3, ElimInstance: 2}
|
||||
assert.Equal(t, "qf3m2", match.TbaCode())
|
||||
match = Match{Type: "elimination", DisplayName: "SF1-3", ElimRound: 2, ElimGroup: 1, ElimInstance: 3}
|
||||
assert.Equal(t, "sf1m3", match.TbaCode())
|
||||
match = Match{Type: "elimination", DisplayName: "F2", ElimRound: 1, ElimGroup: 1, ElimInstance: 2}
|
||||
assert.Equal(t, "f1m2", match.TbaCode())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user