mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-10 14:16:47 -04:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
642116bd62 | ||
|
|
3d566f4866 | ||
|
|
d7c3b9df6c | ||
|
|
8e46617706 | ||
|
|
cf58a2174e | ||
|
|
4bee40e66b | ||
|
|
baaf3b694b | ||
|
|
1acf221ac8 | ||
|
|
600b50d840 | ||
|
|
1c2197e690 | ||
|
|
3ea4e26af3 |
@@ -90,8 +90,8 @@ var doubleEliminationBracketMatchupTemplates = []matchupTemplate{
|
|||||||
matchupKey: newMatchupKey(4, 1),
|
matchupKey: newMatchupKey(4, 1),
|
||||||
displayName: "11",
|
displayName: "11",
|
||||||
NumWinsToAdvance: 1,
|
NumWinsToAdvance: 1,
|
||||||
redAllianceSource: newWinnerAllianceSource(3, 1),
|
redAllianceSource: newWinnerAllianceSource(3, 2),
|
||||||
blueAllianceSource: newWinnerAllianceSource(3, 2),
|
blueAllianceSource: newWinnerAllianceSource(3, 1),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
matchupKey: newMatchupKey(4, 2),
|
matchupKey: newMatchupKey(4, 2),
|
||||||
|
|||||||
@@ -122,11 +122,11 @@ func TestDoubleEliminationProgression(t *testing.T) {
|
|||||||
matches, err = database.GetMatchesByType("elimination")
|
matches, err = database.GetMatchesByType("elimination")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
if assert.Equal(t, 12, len(matches)) {
|
if assert.Equal(t, 12, len(matches)) {
|
||||||
assertMatch(t, matches[10], "11", 8, 7)
|
assertMatch(t, matches[10], "11", 7, 8)
|
||||||
assertMatch(t, matches[11], "12", 4, 3)
|
assertMatch(t, matches[11], "12", 4, 3)
|
||||||
}
|
}
|
||||||
|
|
||||||
scoreMatch(database, "11", game.BlueWonMatch)
|
scoreMatch(database, "11", game.RedWonMatch)
|
||||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||||
matches, err = database.GetMatchesByType("elimination")
|
matches, err = database.GetMatchesByType("elimination")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/Team254/cheesy-arena-lite/game"
|
"github.com/Team254/cheesy-arena-lite/game"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -40,8 +39,6 @@ type Match struct {
|
|||||||
Status game.MatchStatus
|
Status game.MatchStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
var elimRoundNames = map[int]string{1: "F", 2: "SF", 4: "QF", 8: "EF"}
|
|
||||||
|
|
||||||
func (database *Database) CreateMatch(match *Match) error {
|
func (database *Database) CreateMatch(match *Match) error {
|
||||||
return database.matchTable.create(match)
|
return database.matchTable.create(match)
|
||||||
}
|
}
|
||||||
@@ -141,16 +138,6 @@ func (match *Match) TypePrefix() string {
|
|||||||
return ""
|
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.
|
// Returns true if the match is of a type that allows substitution of teams.
|
||||||
func (match *Match) ShouldAllowSubstitution() bool {
|
func (match *Match) ShouldAllowSubstitution() bool {
|
||||||
return match.Type != "qualification"
|
return match.Type != "qualification"
|
||||||
|
|||||||
@@ -112,18 +112,3 @@ func TestGetMatchesByType(t *testing.T) {
|
|||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, 1, len(matches))
|
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())
|
|
||||||
}
|
|
||||||
|
|||||||
107
partner/tba.go
107
partner/tba.go
@@ -15,6 +15,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -38,6 +39,7 @@ type TbaMatch struct {
|
|||||||
Alliances map[string]*TbaAlliance `json:"alliances"`
|
Alliances map[string]*TbaAlliance `json:"alliances"`
|
||||||
TimeString string `json:"time_string"`
|
TimeString string `json:"time_string"`
|
||||||
TimeUtc string `json:"time_utc"`
|
TimeUtc string `json:"time_utc"`
|
||||||
|
DisplayName string `json:"display_name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TbaAlliance struct {
|
type TbaAlliance struct {
|
||||||
@@ -48,15 +50,17 @@ type TbaAlliance struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type TbaRanking struct {
|
type TbaRanking struct {
|
||||||
TeamKey string `json:"team_key"`
|
TeamKey string `json:"team_key"`
|
||||||
Rank int `json:"rank"`
|
Rank int `json:"rank"`
|
||||||
RP float32
|
RP float32
|
||||||
Auto int
|
Auto int
|
||||||
Endgame int
|
Endgame int
|
||||||
Teleop int
|
Teleop int
|
||||||
WinLossTie string
|
Wins int `json:"wins"`
|
||||||
Dqs int `json:"dqs"`
|
Losses int `json:"losses"`
|
||||||
Played int `json:"played"`
|
Ties int `json:"ties"`
|
||||||
|
Dqs int `json:"dqs"`
|
||||||
|
Played int `json:"played"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TbaRankings struct {
|
type TbaRankings struct {
|
||||||
@@ -101,6 +105,33 @@ type TbaPublishedAward struct {
|
|||||||
Awardee string `json:"awardee"`
|
Awardee string `json:"awardee"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type elimMatchKey struct {
|
||||||
|
elimRound int
|
||||||
|
elimGroup int
|
||||||
|
}
|
||||||
|
|
||||||
|
type tbaElimMatchKey struct {
|
||||||
|
compLevel string
|
||||||
|
setNumber int
|
||||||
|
}
|
||||||
|
|
||||||
|
var doubleEliminationMatchKeyMapping = map[elimMatchKey]tbaElimMatchKey{
|
||||||
|
{1, 1}: {"ef", 1},
|
||||||
|
{1, 2}: {"ef", 2},
|
||||||
|
{1, 3}: {"ef", 3},
|
||||||
|
{1, 4}: {"ef", 4},
|
||||||
|
{2, 1}: {"ef", 5},
|
||||||
|
{2, 2}: {"ef", 6},
|
||||||
|
{2, 3}: {"qf", 1},
|
||||||
|
{2, 4}: {"qf", 2},
|
||||||
|
{3, 1}: {"qf", 3},
|
||||||
|
{3, 2}: {"qf", 4},
|
||||||
|
{4, 1}: {"sf", 1},
|
||||||
|
{4, 2}: {"sf", 2},
|
||||||
|
{5, 1}: {"f", 1},
|
||||||
|
{6, 1}: {"f", 2},
|
||||||
|
}
|
||||||
|
|
||||||
func NewTbaClient(eventCode, secretId, secret string) *TbaClient {
|
func NewTbaClient(eventCode, secretId, secret string) *TbaClient {
|
||||||
return &TbaClient{BaseUrl: tbaBaseUrl, eventCode: eventCode, secretId: secretId, secret: secret,
|
return &TbaClient{BaseUrl: tbaBaseUrl, eventCode: eventCode, secretId: secretId, secret: secret,
|
||||||
eventNamesCache: make(map[string]string)}
|
eventNamesCache: make(map[string]string)}
|
||||||
@@ -266,6 +297,10 @@ func (client *TbaClient) PublishMatches(database *model.Database) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
eventSettings, err := database.GetEventSettings()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
matches := append(qualMatches, elimMatches...)
|
matches := append(qualMatches, elimMatches...)
|
||||||
tbaMatches := make([]TbaMatch, len(matches))
|
tbaMatches := make([]TbaMatch, len(matches))
|
||||||
|
|
||||||
@@ -298,12 +333,16 @@ func (client *TbaClient) PublishMatches(database *model.Database) error {
|
|||||||
alliances["blue"] = createTbaAlliance([3]int{match.Blue1, match.Blue2, match.Blue3},
|
alliances["blue"] = createTbaAlliance([3]int{match.Blue1, match.Blue2, match.Blue3},
|
||||||
[3]bool{match.Blue1IsSurrogate, match.Blue2IsSurrogate, match.Blue3IsSurrogate}, blueScore)
|
[3]bool{match.Blue1IsSurrogate, match.Blue2IsSurrogate, match.Blue3IsSurrogate}, blueScore)
|
||||||
|
|
||||||
tbaMatches[i] = TbaMatch{"qm", 0, matchNumber, alliances, match.Time.Local().Format("3:04 PM"),
|
tbaMatches[i] = TbaMatch{
|
||||||
match.Time.UTC().Format("2006-01-02T15:04:05")}
|
CompLevel: "qm",
|
||||||
|
SetNumber: 0,
|
||||||
|
MatchNumber: matchNumber,
|
||||||
|
Alliances: alliances,
|
||||||
|
TimeString: match.Time.Local().Format("3:04 PM"),
|
||||||
|
TimeUtc: match.Time.UTC().Format("2006-01-02T15:04:05"),
|
||||||
|
}
|
||||||
if match.Type == "elimination" {
|
if match.Type == "elimination" {
|
||||||
tbaMatches[i].CompLevel = map[int]string{1: "f", 2: "sf", 4: "qf", 8: "ef"}[match.ElimRound]
|
setElimMatchKey(&tbaMatches[i], &match, eventSettings.ElimType)
|
||||||
tbaMatches[i].SetNumber = match.ElimGroup
|
|
||||||
tbaMatches[i].MatchNumber = match.ElimInstance
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
jsonBody, err := json.Marshal(tbaMatches)
|
jsonBody, err := json.Marshal(tbaMatches)
|
||||||
@@ -331,14 +370,21 @@ func (client *TbaClient) PublishRankings(database *model.Database) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Build a JSON object of TBA-format rankings.
|
// Build a JSON object of TBA-format rankings.
|
||||||
breakdowns := []string{"RP", "Auto", "Endgame", "Teleop", "WinLossTie"}
|
breakdowns := []string{"RP", "Auto", "Endgame", "Teleop"}
|
||||||
tbaRankings := make([]TbaRanking, len(rankings))
|
tbaRankings := make([]TbaRanking, len(rankings))
|
||||||
for i, ranking := range rankings {
|
for i, ranking := range rankings {
|
||||||
tbaRankings[i] = TbaRanking{getTbaTeam(ranking.TeamId), ranking.Rank,
|
tbaRankings[i] = TbaRanking{
|
||||||
float32(ranking.RankingPoints) / float32(ranking.Played), ranking.AutoPoints, ranking.EndgamePoints,
|
TeamKey: getTbaTeam(ranking.TeamId),
|
||||||
ranking.TeleopPoints,
|
Rank: ranking.Rank,
|
||||||
fmt.Sprintf("%d-%d-%d", ranking.Wins, ranking.Losses, ranking.Ties), 0,
|
RP: float32(ranking.RankingPoints) / float32(ranking.Played),
|
||||||
ranking.Played}
|
Auto: ranking.AutoPoints,
|
||||||
|
Endgame: ranking.EndgamePoints,
|
||||||
|
Teleop: ranking.TeleopPoints,
|
||||||
|
Wins: ranking.Wins,
|
||||||
|
Losses: ranking.Losses,
|
||||||
|
Ties: ranking.Ties,
|
||||||
|
Played: ranking.Played,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
jsonBody, err := json.Marshal(TbaRankings{breakdowns, tbaRankings})
|
jsonBody, err := json.Marshal(TbaRankings{breakdowns, tbaRankings})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -503,11 +549,20 @@ func (client *TbaClient) PublishAwards(database *model.Database) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the sum of all values in the slice representing different stages for a power cell goal.
|
// Sets the match key attributes on TbaMatch based on the match and bracket type.
|
||||||
func sumPowerCells(cells []int) int {
|
func setElimMatchKey(tbaMatch *TbaMatch, match *model.Match, elimType string) {
|
||||||
var total int
|
if elimType == "single" {
|
||||||
for _, cell := range cells {
|
tbaMatch.CompLevel = map[int]string{1: "ef", 2: "qf", 3: "sf", 4: "f"}[match.ElimRound]
|
||||||
total += cell
|
tbaMatch.SetNumber = match.ElimGroup
|
||||||
|
tbaMatch.MatchNumber = match.ElimInstance
|
||||||
|
} else if elimType == "double" {
|
||||||
|
if tbaKey, ok := doubleEliminationMatchKeyMapping[elimMatchKey{match.ElimRound, match.ElimGroup}]; ok {
|
||||||
|
tbaMatch.CompLevel = tbaKey.compLevel
|
||||||
|
tbaMatch.SetNumber = tbaKey.setNumber
|
||||||
|
}
|
||||||
|
tbaMatch.MatchNumber = match.ElimInstance
|
||||||
|
if !strings.HasPrefix(match.DisplayName, "F") {
|
||||||
|
tbaMatch.DisplayName = "Match " + match.DisplayName
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return total
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ func TestPublishMatches(t *testing.T) {
|
|||||||
|
|
||||||
match1 := model.Match{Type: "qualification", DisplayName: "2", Time: time.Unix(600, 0), Red1: 7, Red2: 8, Red3: 9,
|
match1 := model.Match{Type: "qualification", DisplayName: "2", Time: time.Unix(600, 0), Red1: 7, Red2: 8, Red3: 9,
|
||||||
Blue1: 10, Blue2: 11, Blue3: 12, Status: game.RedWonMatch}
|
Blue1: 10, Blue2: 11, Blue3: 12, Status: game.RedWonMatch}
|
||||||
match2 := model.Match{Type: "elimination", DisplayName: "SF2-2", ElimRound: 2, ElimGroup: 2, ElimInstance: 2}
|
match2 := model.Match{Type: "elimination", DisplayName: "SF2-2", ElimRound: 3, ElimGroup: 2, ElimInstance: 2}
|
||||||
database.CreateMatch(&match1)
|
database.CreateMatch(&match1)
|
||||||
database.CreateMatch(&match2)
|
database.CreateMatch(&match2)
|
||||||
matchResult1 := model.BuildTestMatchResult(match1.Id, 1)
|
matchResult1 := model.BuildTestMatchResult(match1.Id, 1)
|
||||||
|
|||||||
@@ -120,8 +120,8 @@ body[data-position=right] #inMatch #blueScore {
|
|||||||
left: 0;
|
left: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
font-size: 550px;
|
font-size: 450px;
|
||||||
line-height: 550px;
|
line-height: 450px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
#preMatch .databar {
|
#preMatch .databar {
|
||||||
|
|||||||
@@ -80,6 +80,9 @@
|
|||||||
.label-scoring[data-ready=true] {
|
.label-scoring[data-ready=true] {
|
||||||
background-color: #0c6;
|
background-color: #0c6;
|
||||||
}
|
}
|
||||||
|
.label-saved-match {
|
||||||
|
background-color: #999;
|
||||||
|
}
|
||||||
.nowrap {
|
.nowrap {
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -382,9 +382,8 @@
|
|||||||
<line class="loser" x1="1246.485" y1="746.485" x2="1229.515" y2="729.515"/>
|
<line class="loser" x1="1246.485" y1="746.485" x2="1229.515" y2="729.515"/>
|
||||||
<text transform="translate(926.2617 775.3125)">W</text>
|
<text transform="translate(926.2617 775.3125)">W</text>
|
||||||
<text transform="translate(926.2617 585.3125)">W</text>
|
<text transform="translate(926.2617 585.3125)">W</text>
|
||||||
<polyline points="1008,725 984,725 954.488,593.142"/>
|
<polyline points="955,593 955,655 1008,655"/>
|
||||||
<polyline class="coverup" points="1008,656 984,656 955.118,784.297"/>
|
<polyline points="955,783 955,725 1008,725"/>
|
||||||
<polyline points="1008,655 984,655 955.118,783 898,783"/>
|
|
||||||
</g>
|
</g>
|
||||||
<g id="connectors_4_2"{{if (index .Matchups "4_2").IsActive}} class="active"{{end}}>
|
<g id="connectors_4_2"{{if (index .Matchups "4_2").IsActive}} class="active"{{end}}>
|
||||||
<rect class="coverup" x="699.216" y="241.054" width="312.117" height="199.156"/>
|
<rect class="coverup" x="699.216" y="241.054" width="312.117" height="199.156"/>
|
||||||
|
|||||||
@@ -56,7 +56,11 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="col-lg-8">
|
<div class="col-lg-8">
|
||||||
<div class="row text-center">
|
<div class="row text-center">
|
||||||
<div id="matchState" class="col-lg-2 col-lg-offset-2 well well-sm text-center"> </div>
|
<div class="col-lg-3 well well-sm text-center" style="text-transform: uppercase;">
|
||||||
|
{{if eq .Match.Type "elimination"}}playoff{{else}}{{.Match.Type}}{{end}}
|
||||||
|
{{if ne .Match.Type "test" }}{{.Match.DisplayName}}{{end}}
|
||||||
|
</div>
|
||||||
|
<div id="matchState" class="col-lg-3 well well-sm text-center"> </div>
|
||||||
<div id="matchTime" class="col-lg-2 well well-sm text-center"> </div>
|
<div id="matchTime" class="col-lg-2 well well-sm text-center"> </div>
|
||||||
<div id="redScore" class="col-lg-2 well well-sm well-red text-center"> </div>
|
<div id="redScore" class="col-lg-2 well well-sm well-red text-center"> </div>
|
||||||
<div id="blueScore" class="col-lg-2 well well-sm well-blue text-center"> </div>
|
<div id="blueScore" class="col-lg-2 well well-sm well-blue text-center"> </div>
|
||||||
@@ -290,6 +294,14 @@
|
|||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<p>Shown Match Result</p>
|
||||||
|
<span class="label label-saved-match">
|
||||||
|
{{if .SavedMatch.DisplayName}}{{.SavedMatchType}} {{.SavedMatch.DisplayName}}{{else}}None{{end}}
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<a href="/match_play/clear_result">
|
||||||
|
<b class="btn btn-info btn-xs">Clear</b>
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-lg-3">
|
<div class="col-lg-3">
|
||||||
<p>Match Sounds</p>
|
<p>Match Sounds</p>
|
||||||
|
|||||||
14
web/api.go
14
web/api.go
@@ -228,19 +228,27 @@ func (web *Web) teamAvatarsApiHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (web *Web) bracketSvgApiHandler(w http.ResponseWriter, r *http.Request) {
|
func (web *Web) bracketSvgApiHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
hideActive := false
|
||||||
|
if hideActiveValue, ok := r.URL.Query()["hideActive"]; ok {
|
||||||
|
hideActive = hideActiveValue[0] == "true"
|
||||||
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "image/svg+xml")
|
w.Header().Set("Content-Type", "image/svg+xml")
|
||||||
if err := web.generateBracketSvg(w); err != nil {
|
if err := web.generateBracketSvg(w, hideActive); err != nil {
|
||||||
handleWebErr(w, err)
|
handleWebErr(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (web *Web) generateBracketSvg(w io.Writer) error {
|
func (web *Web) generateBracketSvg(w io.Writer, hideActive bool) error {
|
||||||
alliances, err := web.arena.Database.GetAllAlliances()
|
alliances, err := web.arena.Database.GetAllAlliances()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
activeMatch := web.arena.SavedMatch
|
var activeMatch *model.Match
|
||||||
|
if !hideActive {
|
||||||
|
activeMatch = web.arena.SavedMatch
|
||||||
|
}
|
||||||
|
|
||||||
matchups := make(map[string]*allianceMatchup)
|
matchups := make(map[string]*allianceMatchup)
|
||||||
if web.arena.PlayoffBracket != nil {
|
if web.arena.PlayoffBracket != nil {
|
||||||
|
|||||||
@@ -89,6 +89,8 @@ func (web *Web) matchPlayHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
BlueScore *game.Score
|
BlueScore *game.Score
|
||||||
AllowSubstitution bool
|
AllowSubstitution bool
|
||||||
IsReplay bool
|
IsReplay bool
|
||||||
|
SavedMatchType string
|
||||||
|
SavedMatch *model.Match
|
||||||
PlcArmorBlockStatuses map[string]bool
|
PlcArmorBlockStatuses map[string]bool
|
||||||
}{
|
}{
|
||||||
web.arena.EventSettings,
|
web.arena.EventSettings,
|
||||||
@@ -102,6 +104,8 @@ func (web *Web) matchPlayHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
web.arena.BlueScore,
|
web.arena.BlueScore,
|
||||||
web.arena.CurrentMatch.ShouldAllowSubstitution(),
|
web.arena.CurrentMatch.ShouldAllowSubstitution(),
|
||||||
isReplay,
|
isReplay,
|
||||||
|
web.arena.SavedMatch.CapitalizedType(),
|
||||||
|
web.arena.SavedMatch,
|
||||||
web.arena.Plc.GetArmorBlockStatuses(),
|
web.arena.Plc.GetArmorBlockStatuses(),
|
||||||
}
|
}
|
||||||
err = template.ExecuteTemplate(w, "base", data)
|
err = template.ExecuteTemplate(w, "base", data)
|
||||||
@@ -185,6 +189,20 @@ func (web *Web) matchPlayShowResultHandler(w http.ResponseWriter, r *http.Reques
|
|||||||
http.Redirect(w, r, "/match_play", 303)
|
http.Redirect(w, r, "/match_play", 303)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clears the match results display buffer.
|
||||||
|
func (web *Web) matchPlayClearResultHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if !web.userIsAdmin(w, r) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load an empty match to effectively clear the buffer.
|
||||||
|
web.arena.SavedMatch = &model.Match{}
|
||||||
|
web.arena.SavedMatchResult = model.NewMatchResult()
|
||||||
|
web.arena.ScorePostedNotifier.Notify()
|
||||||
|
|
||||||
|
http.Redirect(w, r, "/match_play", 303)
|
||||||
|
}
|
||||||
|
|
||||||
// The websocket endpoint for the match play client to send control commands and receive status updates.
|
// The websocket endpoint for the match play client to send control commands and receive status updates.
|
||||||
func (web *Web) matchPlayWebsocketHandler(w http.ResponseWriter, r *http.Request) {
|
func (web *Web) matchPlayWebsocketHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if !web.userIsAdmin(w, r) {
|
if !web.userIsAdmin(w, r) {
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ func TestMatchPlayLoad(t *testing.T) {
|
|||||||
assert.NotContains(t, recorder.Body.String(), "106")
|
assert.NotContains(t, recorder.Body.String(), "106")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMatchPlayShowResult(t *testing.T) {
|
func TestMatchPlayShowAndClearResult(t *testing.T) {
|
||||||
web := setupTestWeb(t)
|
web := setupTestWeb(t)
|
||||||
|
|
||||||
recorder := web.getHttpResponse("/match_play/1/show_result")
|
recorder := web.getHttpResponse("/match_play/1/show_result")
|
||||||
@@ -107,6 +107,11 @@ func TestMatchPlayShowResult(t *testing.T) {
|
|||||||
assert.Equal(t, 303, recorder.Code)
|
assert.Equal(t, 303, recorder.Code)
|
||||||
assert.Equal(t, match.Id, web.arena.SavedMatch.Id)
|
assert.Equal(t, match.Id, web.arena.SavedMatch.Id)
|
||||||
assert.Equal(t, match.Id, web.arena.SavedMatchResult.MatchId)
|
assert.Equal(t, match.Id, web.arena.SavedMatchResult.MatchId)
|
||||||
|
|
||||||
|
recorder = web.getHttpResponse("/match_play/clear_result")
|
||||||
|
assert.Equal(t, 303, recorder.Code)
|
||||||
|
assert.Equal(t, model.Match{}, *web.arena.SavedMatch)
|
||||||
|
assert.Equal(t, *model.NewMatchResult(), *web.arena.SavedMatchResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMatchPlayErrors(t *testing.T) {
|
func TestMatchPlayErrors(t *testing.T) {
|
||||||
|
|||||||
@@ -681,7 +681,7 @@ func (web *Web) alliancesPdfReportHandler(w http.ResponseWriter, r *http.Request
|
|||||||
// suitable Go library for doing so appears to exist).
|
// suitable Go library for doing so appears to exist).
|
||||||
func (web *Web) bracketPdfReportHandler(w http.ResponseWriter, r *http.Request) {
|
func (web *Web) bracketPdfReportHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
buffer := new(bytes.Buffer)
|
buffer := new(bytes.Buffer)
|
||||||
err := web.generateBracketSvg(buffer)
|
err := web.generateBracketSvg(buffer, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleWebErr(w, err)
|
handleWebErr(w, err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ func (web *Web) scheduleGetHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
matchType := getMatchType(r)
|
matchType := getMatchType(r)
|
||||||
if matchType == "" {
|
if matchType == "" {
|
||||||
http.Redirect(w, r, "/setup/schedule?matchType=practice", 302)
|
http.Redirect(w, r, "/setup/schedule?matchType=practice", 302)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if matchType != "practice" && matchType != "qualification" {
|
if matchType != "practice" && matchType != "qualification" {
|
||||||
|
|||||||
@@ -145,6 +145,7 @@ func (web *Web) newHandler() http.Handler {
|
|||||||
router.HandleFunc("/match_play", web.matchPlayHandler).Methods("GET")
|
router.HandleFunc("/match_play", web.matchPlayHandler).Methods("GET")
|
||||||
router.HandleFunc("/match_play/{matchId}/load", web.matchPlayLoadHandler).Methods("GET")
|
router.HandleFunc("/match_play/{matchId}/load", web.matchPlayLoadHandler).Methods("GET")
|
||||||
router.HandleFunc("/match_play/{matchId}/show_result", web.matchPlayShowResultHandler).Methods("GET")
|
router.HandleFunc("/match_play/{matchId}/show_result", web.matchPlayShowResultHandler).Methods("GET")
|
||||||
|
router.HandleFunc("/match_play/clear_result", web.matchPlayClearResultHandler).Methods("GET")
|
||||||
router.HandleFunc("/match_play/websocket", web.matchPlayWebsocketHandler).Methods("GET")
|
router.HandleFunc("/match_play/websocket", web.matchPlayWebsocketHandler).Methods("GET")
|
||||||
router.HandleFunc("/match_review", web.matchReviewHandler).Methods("GET")
|
router.HandleFunc("/match_review", web.matchReviewHandler).Methods("GET")
|
||||||
router.HandleFunc("/match_review/{matchId}/edit", web.matchReviewEditGetHandler).Methods("GET")
|
router.HandleFunc("/match_review/{matchId}/edit", web.matchReviewEditGetHandler).Methods("GET")
|
||||||
|
|||||||
Reference in New Issue
Block a user