Update game module and dependents for the 2019 game.

This commit is contained in:
Patrick Fairbank
2019-07-21 17:52:34 -07:00
parent 7e788b6d23
commit ad1891cd91
30 changed files with 396 additions and 1304 deletions

View File

@@ -133,7 +133,7 @@ func TestCommitMatch(t *testing.T) {
web.arena.Database.CreateMatch(match)
matchResult = model.NewMatchResult()
matchResult.MatchId = match.Id
matchResult.BlueScore = &game.Score{AutoRuns: 2}
matchResult.BlueScore = &game.Score{RobotEndLevels: [3]int{3, 3, 3}}
err = web.commitMatchScore(match, matchResult, false)
assert.Nil(t, err)
assert.Equal(t, 1, matchResult.PlayNumber)
@@ -142,7 +142,7 @@ func TestCommitMatch(t *testing.T) {
matchResult = model.NewMatchResult()
matchResult.MatchId = match.Id
matchResult.RedScore = &game.Score{AutoRuns: 1}
matchResult.RedScore = &game.Score{RobotEndLevels: [3]int{2, 2, 2}}
err = web.commitMatchScore(match, matchResult, false)
assert.Nil(t, err)
assert.Equal(t, 2, matchResult.PlayNumber)
@@ -174,8 +174,13 @@ func TestCommitEliminationTie(t *testing.T) {
match := &model.Match{Id: 0, Type: "qualification", Red1: 1, Red2: 2, Red3: 3, Blue1: 4, Blue2: 5, Blue3: 6}
web.arena.Database.CreateMatch(match)
matchResult := &model.MatchResult{MatchId: match.Id, RedScore: &game.Score{ForceCubes: 1, Fouls: []game.Foul{{}}},
BlueScore: &game.Score{}}
matchResult := &model.MatchResult{
MatchId: match.Id,
RedScore: &game.Score{
RocketFarRightBays: [3]game.BayStatus{game.BayHatchCargo, game.BayEmpty, game.BayEmpty},
Fouls: []game.Foul{{}}},
BlueScore: &game.Score{},
}
err := web.commitMatchScore(match, matchResult, false)
assert.Nil(t, err)
match, _ = web.arena.Database.GetMatchById(1)
@@ -301,12 +306,12 @@ func TestMatchPlayWebsocketCommands(t *testing.T) {
readWebsocketType(t, ws, "audienceDisplayMode")
readWebsocketType(t, ws, "allianceStationDisplayMode")
assert.Equal(t, field.PostMatch, web.arena.MatchState)
web.arena.RedRealtimeScore.CurrentScore.AutoRuns = 1
web.arena.BlueRealtimeScore.CurrentScore.BoostCubes = 2
web.arena.RedRealtimeScore.CurrentScore.RobotEndLevels = [3]int{1, 2, 3}
web.arena.BlueRealtimeScore.CurrentScore.SandstormBonuses = [3]bool{true, false, true}
ws.Write("commitResults", nil)
readWebsocketMultiple(t, ws, 3) // reload, realtimeScore, setAllianceStationDisplay
assert.Equal(t, 1, web.arena.SavedMatchResult.RedScore.AutoRuns)
assert.Equal(t, 2, web.arena.SavedMatchResult.BlueScore.BoostCubes)
assert.Equal(t, [3]int{1, 2, 3}, web.arena.SavedMatchResult.RedScore.RobotEndLevels)
assert.Equal(t, [3]bool{true, false, true}, web.arena.SavedMatchResult.BlueScore.SandstormBonuses)
assert.Equal(t, field.PreMatch, web.arena.MatchState)
ws.Write("discardResults", nil)
readWebsocketMultiple(t, ws, 3) // reload, realtimeScore, setAllianceStationDisplay

View File

@@ -49,8 +49,8 @@ func TestMatchReviewEditExistingResult(t *testing.T) {
recorder := web.getHttpResponse("/match_review")
assert.Equal(t, 200, recorder.Code)
assert.Contains(t, recorder.Body.String(), "QF4-3")
assert.Contains(t, recorder.Body.String(), "169") // The red score
assert.Contains(t, recorder.Body.String(), "228") // The blue score
assert.Contains(t, recorder.Body.String(), "71") // The red score
assert.Contains(t, recorder.Body.String(), "88") // The blue score
// Check response for non-existent match.
recorder = web.getHttpResponse(fmt.Sprintf("/match_review/%d/edit", 12345))
@@ -67,12 +67,13 @@ func TestMatchReviewEditExistingResult(t *testing.T) {
recorder = web.postHttpResponse(fmt.Sprintf("/match_review/%d/edit", match.Id), postBody)
assert.Equal(t, 303, recorder.Code)
// TODO(pat): Update for 2019.
// Check for the updated scores back on the match list page.
recorder = web.getHttpResponse("/match_review")
assert.Equal(t, 200, recorder.Code)
assert.Contains(t, recorder.Body.String(), "QF4-3")
assert.Contains(t, recorder.Body.String(), "20") // The red score
assert.Contains(t, recorder.Body.String(), "15") // The blue score
assert.Contains(t, recorder.Body.String(), "5") // The red score
assert.Contains(t, recorder.Body.String(), "0") // The blue score
}
func TestMatchReviewCreateNewResult(t *testing.T) {

View File

@@ -53,8 +53,8 @@ func (web *Web) rankingsPdfReportHandler(w http.ResponseWriter, r *http.Request)
}
// The widths of the table columns in mm, stored here so that they can be referenced for each row.
colWidths := map[string]float64{"Rank": 13, "Team": 20, "RP": 20, "Park/Climb": 21, "Auto": 20, "Ownership": 21,
"Vault": 20, "W-L-T": 21, "DQ": 20, "Played": 20}
colWidths := map[string]float64{"Rank": 13, "Team": 20, "RP": 20, "Cargo": 21, "Hatch": 20, "Hab Climb": 21,
"Sandstorm": 20, "W-L-T": 21, "DQ": 20, "Played": 20}
rowHeight := 6.5
pdf := gofpdf.New("P", "mm", "Letter", "font")
@@ -67,10 +67,10 @@ func (web *Web) rankingsPdfReportHandler(w http.ResponseWriter, r *http.Request)
pdf.CellFormat(colWidths["Rank"], rowHeight, "Rank", "1", 0, "C", true, 0, "")
pdf.CellFormat(colWidths["Team"], rowHeight, "Team", "1", 0, "C", true, 0, "")
pdf.CellFormat(colWidths["RP"], rowHeight, "RP", "1", 0, "C", true, 0, "")
pdf.CellFormat(colWidths["Park/Climb"], rowHeight, "Park/Climb", "1", 0, "C", true, 0, "")
pdf.CellFormat(colWidths["Auto"], rowHeight, "Auto", "1", 0, "C", true, 0, "")
pdf.CellFormat(colWidths["Ownership"], rowHeight, "Ownership", "1", 0, "C", true, 0, "")
pdf.CellFormat(colWidths["Vault"], rowHeight, "Vault", "1", 0, "C", true, 0, "")
pdf.CellFormat(colWidths["Cargo"], rowHeight, "Cargo", "1", 0, "C", true, 0, "")
pdf.CellFormat(colWidths["Hatch"], rowHeight, "Hatch", "1", 0, "C", true, 0, "")
pdf.CellFormat(colWidths["Hab Climb"], rowHeight, "Hab Climb", "1", 0, "C", true, 0, "")
pdf.CellFormat(colWidths["Sandstorm"], rowHeight, "Sandstorm", "1", 0, "C", true, 0, "")
pdf.CellFormat(colWidths["W-L-T"], rowHeight, "W-L-T", "1", 0, "C", true, 0, "")
pdf.CellFormat(colWidths["DQ"], rowHeight, "DQ", "1", 0, "C", true, 0, "")
pdf.CellFormat(colWidths["Played"], rowHeight, "Played", "1", 1, "C", true, 0, "")
@@ -81,10 +81,12 @@ func (web *Web) rankingsPdfReportHandler(w http.ResponseWriter, r *http.Request)
pdf.SetFont("Arial", "", 10)
pdf.CellFormat(colWidths["Team"], rowHeight, strconv.Itoa(ranking.TeamId), "1", 0, "C", false, 0, "")
pdf.CellFormat(colWidths["RP"], rowHeight, strconv.Itoa(ranking.RankingPoints), "1", 0, "C", false, 0, "")
pdf.CellFormat(colWidths["Park/Climb"], rowHeight, strconv.Itoa(ranking.ParkClimbPoints), "1", 0, "C", false, 0, "")
pdf.CellFormat(colWidths["Auto"], rowHeight, strconv.Itoa(ranking.AutoPoints), "1", 0, "C", false, 0, "")
pdf.CellFormat(colWidths["Ownership"], rowHeight, strconv.Itoa(ranking.OwnershipPoints), "1", 0, "C", false, 0, "")
pdf.CellFormat(colWidths["Vault"], rowHeight, strconv.Itoa(ranking.VaultPoints), "1", 0, "C", false, 0, "")
pdf.CellFormat(colWidths["Cargo"], rowHeight, strconv.Itoa(ranking.CargoPoints), "1", 0, "C", false, 0, "")
pdf.CellFormat(colWidths["Hatch"], rowHeight, strconv.Itoa(ranking.HatchPanelPoints), "1", 0, "C", false, 0, "")
pdf.CellFormat(colWidths["Hab Climb"], rowHeight, strconv.Itoa(ranking.HabClimbPoints), "1", 0, "C", false, 0,
"")
pdf.CellFormat(colWidths["Sandstorm"], rowHeight, strconv.Itoa(ranking.SandstormBonusPoints), "1", 0, "C",
false, 0, "")
record := fmt.Sprintf("%d-%d-%d", ranking.Wins, ranking.Losses, ranking.Ties)
pdf.CellFormat(colWidths["W-L-T"], rowHeight, record, "1", 0, "C", false, 0, "")
pdf.CellFormat(colWidths["DQ"], rowHeight, strconv.Itoa(ranking.Disqualifications), "1", 0, "C", false, 0, "")
@@ -196,7 +198,8 @@ func (web *Web) schedulePdfReportHandler(w http.ResponseWriter, r *http.Request)
}
// Render match info row.
pdf.CellFormat(colWidths["Time"], height, match.Time.Local().Format("Mon 1/02 03:04 PM"), borderStr, 0, alignStr, false, 0, "")
pdf.CellFormat(colWidths["Time"], height, match.Time.Local().Format("Mon 1/02 03:04 PM"), borderStr, 0,
alignStr, false, 0, "")
pdf.CellFormat(colWidths["Type"], height, matchType, borderStr, 0, alignStr, false, 0, "")
pdf.CellFormat(colWidths["Match"], height, match.DisplayName, borderStr, 0, alignStr, false, 0, "")
pdf.CellFormat(colWidths["Team"], height, formatTeam(match.Red1), borderStr, 0, alignStr, false, 0, "")
@@ -212,12 +215,18 @@ func (web *Web) schedulePdfReportHandler(w http.ResponseWriter, r *http.Request)
pdf.CellFormat(colWidths["Time"], height, "", "LBR", 0, "C", false, 0, "")
pdf.CellFormat(colWidths["Type"], height, "", "LBR", 0, "C", false, 0, "")
pdf.CellFormat(colWidths["Match"], height, "", "LBR", 0, "C", false, 0, "")
pdf.CellFormat(colWidths["Team"], height, surrogateText(match.Red1IsSurrogate), "LBR", 0, "CT", false, 0, "")
pdf.CellFormat(colWidths["Team"], height, surrogateText(match.Red2IsSurrogate), "LBR", 0, "CT", false, 0, "")
pdf.CellFormat(colWidths["Team"], height, surrogateText(match.Red3IsSurrogate), "LBR", 0, "CT", false, 0, "")
pdf.CellFormat(colWidths["Team"], height, surrogateText(match.Blue1IsSurrogate), "LBR", 0, "CT", false, 0, "")
pdf.CellFormat(colWidths["Team"], height, surrogateText(match.Blue2IsSurrogate), "LBR", 0, "CT", false, 0, "")
pdf.CellFormat(colWidths["Team"], height, surrogateText(match.Blue3IsSurrogate), "LBR", 1, "CT", false, 0, "")
pdf.CellFormat(colWidths["Team"], height, surrogateText(match.Red1IsSurrogate), "LBR", 0, "CT", false, 0,
"")
pdf.CellFormat(colWidths["Team"], height, surrogateText(match.Red2IsSurrogate), "LBR", 0, "CT", false, 0,
"")
pdf.CellFormat(colWidths["Team"], height, surrogateText(match.Red3IsSurrogate), "LBR", 0, "CT", false, 0,
"")
pdf.CellFormat(colWidths["Team"], height, surrogateText(match.Blue1IsSurrogate), "LBR", 0, "CT", false, 0,
"")
pdf.CellFormat(colWidths["Team"], height, surrogateText(match.Blue2IsSurrogate), "LBR", 0, "CT", false, 0,
"")
pdf.CellFormat(colWidths["Team"], height, surrogateText(match.Blue3IsSurrogate), "LBR", 1, "CT", false, 0,
"")
pdf.SetFont("Arial", "", 10)
}
}

View File

@@ -22,9 +22,9 @@ func TestRankingsCsvReport(t *testing.T) {
recorder := web.getHttpResponse("/reports/csv/rankings")
assert.Equal(t, 200, recorder.Code)
assert.Equal(t, "text/plain", recorder.HeaderMap["Content-Type"][0])
expectedBody := "Rank,TeamId,RankingPoints,ParkClimbPoints,AutoPoints,OwnershipPoints,VaultPoints,Wins," +
"Losses,Ties,Disqualifications,Played\n1,254,20,625,90,554,10,3,2,1,0,10\n2,1114,18,700,625,90,554,1,3," +
"2,0,10\n\n"
expectedBody := "Rank,TeamId,RankingPoints,CargoPoints,HatchPanelPoints,HabClimbPoints,SandstormBonusPoints,Wins," +
"Losses,Ties,Disqualifications,Played\n1,254,20,625,90,554,10,3,2,1,0,10\n2,1114,18,700,625,90,554,1,3,2,0,10" +
"\n\n"
assert.Equal(t, expectedBody, recorder.Body.String())
}

View File

@@ -89,48 +89,6 @@ func (web *Web) scoringPanelWebsocketHandler(w http.ResponseWriter, r *http.Requ
scoreChanged := false
switch messageType {
case "r":
if !(*score).AutoCommitted {
if (*score).CurrentScore.AutoRuns < 3 {
(*score).CurrentScore.AutoRuns++
scoreChanged = true
}
}
case "R":
if !(*score).AutoCommitted {
if (*score).CurrentScore.AutoRuns > 0 {
(*score).CurrentScore.AutoRuns--
scoreChanged = true
}
}
case "c":
if (*score).AutoCommitted {
if (*score).CurrentScore.Climbs+(*score).CurrentScore.Parks < 3 {
(*score).CurrentScore.Climbs++
scoreChanged = true
}
}
case "C":
if (*score).AutoCommitted {
if (*score).CurrentScore.Climbs > 0 {
(*score).CurrentScore.Climbs--
scoreChanged = true
}
}
case "p":
if (*score).AutoCommitted {
if (*score).CurrentScore.Climbs+(*score).CurrentScore.Parks < 3 {
(*score).CurrentScore.Parks++
scoreChanged = true
}
}
case "P":
if (*score).AutoCommitted {
if (*score).CurrentScore.Parks > 0 {
(*score).CurrentScore.Parks--
scoreChanged = true
}
}
case "\r":
if (web.arena.MatchState != field.PreMatch && web.arena.MatchState != field.TimeoutActive &&
web.arena.MatchState != field.PostTimeout || web.arena.CurrentMatch.Type == "test") &&

View File

@@ -47,34 +47,37 @@ func TestScoringPanelWebsocket(t *testing.T) {
readWebsocketType(t, blueWs, "matchTime")
readWebsocketType(t, blueWs, "realtimeScore")
// Send a match worth of scoring commands in.
redWs.Write("r", nil)
blueWs.Write("r", nil)
blueWs.Write("r", nil)
blueWs.Write("r", nil)
blueWs.Write("r", nil)
blueWs.Write("R", nil)
for i := 0; i < 5; i++ {
readWebsocketType(t, redWs, "realtimeScore")
readWebsocketType(t, blueWs, "realtimeScore")
}
redWs.Write("\r", nil)
blueWs.Write("\r", nil)
redWs.Write("a", nil)
redWs.Write("\r", nil)
for i := 0; i < 4; i++ {
readWebsocketType(t, redWs, "realtimeScore")
readWebsocketType(t, blueWs, "realtimeScore")
}
// TODO(pat): Update for 2019.
/*
// Send a match worth of scoring commands in.
redWs.Write("r", nil)
blueWs.Write("r", nil)
blueWs.Write("r", nil)
blueWs.Write("r", nil)
blueWs.Write("r", nil)
blueWs.Write("R", nil)
for i := 0; i < 5; i++ {
readWebsocketType(t, redWs, "realtimeScore")
readWebsocketType(t, blueWs, "realtimeScore")
}
redWs.Write("\r", nil)
blueWs.Write("\r", nil)
redWs.Write("a", nil)
redWs.Write("\r", nil)
for i := 0; i < 4; i++ {
readWebsocketType(t, redWs, "realtimeScore")
readWebsocketType(t, blueWs, "realtimeScore")
}
assert.Equal(t, 1, web.arena.RedRealtimeScore.CurrentScore.AutoRuns)
assert.Equal(t, 2, web.arena.BlueRealtimeScore.CurrentScore.AutoRuns)
assert.Equal(t, 1, web.arena.RedRealtimeScore.CurrentScore.AutoRuns)
assert.Equal(t, 2, web.arena.BlueRealtimeScore.CurrentScore.AutoRuns)
redWs.Write("r", nil)
redWs.Write("r", nil)
// Make sure auto scores haven't changed in teleop.
assert.Equal(t, 1, web.arena.RedRealtimeScore.CurrentScore.AutoRuns)
assert.Equal(t, 2, web.arena.BlueRealtimeScore.CurrentScore.AutoRuns)
// Make sure auto scores haven't changed in teleop.
assert.Equal(t, 1, web.arena.RedRealtimeScore.CurrentScore.AutoRuns)
assert.Equal(t, 2, web.arena.BlueRealtimeScore.CurrentScore.AutoRuns)
*/
// Test committing logic.
redWs.Write("commitMatch", nil)

View File

@@ -66,6 +66,7 @@ func (web *Web) settingsPostHandler(w http.ResponseWriter, r *http.Request) {
eventSettings.PlcAddress = r.PostFormValue("plcAddress")
eventSettings.AdminPassword = r.PostFormValue("adminPassword")
eventSettings.ReaderPassword = r.PostFormValue("readerPassword")
eventSettings.HabDockingThreshold, _ = strconv.Atoi(r.PostFormValue("habDockingThreshold"))
err := web.arena.Database.SaveEventSettings(eventSettings)
if err != nil {