mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 13:46:44 -04:00
Save and report which teams have successfully connected to the field.
This commit is contained in:
@@ -10,7 +10,8 @@ CREATE TABLE teams (
|
||||
robotname VARCHAR(255),
|
||||
accomplishments VARCHAR(1000),
|
||||
wpakey VARCHAR(16),
|
||||
yellowcard bool
|
||||
yellowcard bool,
|
||||
hasconnected bool
|
||||
);
|
||||
|
||||
-- +goose Down
|
||||
|
||||
@@ -338,6 +338,13 @@ func (arena *Arena) StartMatch() error {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Save the teams that have successfully connected to the field.
|
||||
if allianceStation.Team != nil && !allianceStation.Team.HasConnected && allianceStation.DsConn != nil &&
|
||||
allianceStation.DsConn.RobotLinked {
|
||||
allianceStation.Team.HasConnected = true
|
||||
arena.Database.SaveTeam(allianceStation.Team)
|
||||
}
|
||||
}
|
||||
|
||||
arena.MatchState = StartMatch
|
||||
|
||||
@@ -595,3 +595,40 @@ func TestArenaTimeout(t *testing.T) {
|
||||
assert.NotNil(t, arena.StartTimeout(1))
|
||||
}
|
||||
}
|
||||
|
||||
func TestSaveTeamHasConnected(t *testing.T) {
|
||||
arena := setupTestArena(t)
|
||||
|
||||
arena.Database.CreateTeam(&model.Team{Id: 101})
|
||||
arena.Database.CreateTeam(&model.Team{Id: 102})
|
||||
arena.Database.CreateTeam(&model.Team{Id: 103})
|
||||
arena.Database.CreateTeam(&model.Team{Id: 104})
|
||||
arena.Database.CreateTeam(&model.Team{Id: 105})
|
||||
arena.Database.CreateTeam(&model.Team{Id: 106, City: "San Jose", HasConnected: true})
|
||||
match := model.Match{Red1: 101, Red2: 102, Red3: 103, Blue1: 104, Blue2: 105, Blue3: 106}
|
||||
arena.Database.CreateMatch(&match)
|
||||
arena.LoadMatch(&match)
|
||||
arena.AllianceStations["R1"].DsConn = &DriverStationConnection{TeamId: 101}
|
||||
arena.AllianceStations["R1"].Bypass = true
|
||||
arena.AllianceStations["R2"].DsConn = &DriverStationConnection{TeamId: 102, RobotLinked: true}
|
||||
arena.AllianceStations["R3"].DsConn = &DriverStationConnection{TeamId: 103}
|
||||
arena.AllianceStations["R3"].Bypass = true
|
||||
arena.AllianceStations["B1"].DsConn = &DriverStationConnection{TeamId: 104}
|
||||
arena.AllianceStations["B1"].Bypass = true
|
||||
arena.AllianceStations["B2"].DsConn = &DriverStationConnection{TeamId: 105, RobotLinked: true}
|
||||
arena.AllianceStations["B3"].DsConn = &DriverStationConnection{TeamId: 106, RobotLinked: true}
|
||||
arena.AllianceStations["B3"].Team.City = "Sand Hosay" // Change some other field to verify that it isn't saved.
|
||||
assert.Nil(t, arena.StartMatch())
|
||||
|
||||
// Check that the connection status was saved for the teams that just linked for the first time.
|
||||
teams, _ := arena.Database.GetAllTeams()
|
||||
if assert.Equal(t, 6, len(teams)) {
|
||||
assert.False(t, teams[0].HasConnected)
|
||||
assert.True(t, teams[1].HasConnected)
|
||||
assert.False(t, teams[2].HasConnected)
|
||||
assert.False(t, teams[3].HasConnected)
|
||||
assert.True(t, teams[4].HasConnected)
|
||||
assert.True(t, teams[5].HasConnected)
|
||||
assert.Equal(t, "San Jose", teams[5].City)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ type Team struct {
|
||||
Accomplishments string
|
||||
WpaKey string
|
||||
YellowCard bool
|
||||
HasConnected bool
|
||||
}
|
||||
|
||||
func (database *Database) CreateTeam(team *Team) error {
|
||||
|
||||
@@ -65,6 +65,7 @@
|
||||
<li><a target="_blank" href="/reports/pdf/schedule/qualification">Qualification Schedule</a></li>
|
||||
<li><a target="_blank" href="/reports/pdf/schedule/elimination">Playoff Schedule</a></li>
|
||||
<li><a target="_blank" href="/reports/pdf/rankings">Standings</a></li>
|
||||
<li><a target="_blank" href="/reports/pdf/teams?showHasConnected=true">Team Connection Status</a></li>
|
||||
<li class="divider"></li>
|
||||
<li class="dropdown-header">CSV Data Export</li>
|
||||
<li><a target="_blank" href="/reports/csv/teams">Team List</a></li>
|
||||
|
||||
@@ -60,6 +60,12 @@
|
||||
<textarea class="form-control" rows="5" name="accomplishments">{{.Team.Accomplishments}}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-lg-5 control-label">Has Connected to Field?</label>
|
||||
<div class="col-lg-1 checkbox">
|
||||
<input type="checkbox" name="hasConnected"{{if .Team.HasConnected}} checked{{end}} />
|
||||
</div>
|
||||
</div>
|
||||
{{if .EventSettings.NetworkSecurityEnabled}}
|
||||
<div class="form-group">
|
||||
<label class="col-lg-3 control-label">WPA Key</label>
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
Number,Name,Nickname,City,StateProv,Country,RookieYear,RobotName
|
||||
{{range $team := .}}{{$team.Id}},"{{$team.Name}}","{{$team.Nickname}}","{{$team.City}}","{{$team.StateProv}}","{{$team.Country}}",{{$team.RookieYear}},"{{$team.RobotName}}"
|
||||
Number,Name,Nickname,City,StateProv,Country,RookieYear,RobotName,HasConnected
|
||||
{{range $team := .}}{{$team.Id}},"{{$team.Name}}","{{$team.Nickname}}","{{$team.City}}","{{$team.StateProv}}","{{$team.Country}}",{{$team.RookieYear}},"{{$team.RobotName}}",{{$team.HasConnected}}
|
||||
{{end}}
|
||||
|
||||
|
@@ -274,8 +274,15 @@ func (web *Web) teamsPdfReportHandler(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
showHasConnected := r.URL.Query().Get("showHasConnected") == "true"
|
||||
|
||||
// The widths of the table columns in mm, stored here so that they can be referenced for each row.
|
||||
colWidths := map[string]float64{"Id": 12, "Name": 80, "Location": 80, "RookieYear": 23}
|
||||
var colWidths map[string]float64
|
||||
if showHasConnected {
|
||||
colWidths = map[string]float64{"Id": 12, "Name": 70, "Location": 65, "RookieYear": 23, "HasConnected": 25}
|
||||
} else {
|
||||
colWidths = map[string]float64{"Id": 12, "Name": 80, "Location": 80, "RookieYear": 23}
|
||||
}
|
||||
rowHeight := 6.5
|
||||
|
||||
pdf := gofpdf.New("P", "mm", "Letter", "font")
|
||||
@@ -288,7 +295,12 @@ func (web *Web) teamsPdfReportHandler(w http.ResponseWriter, r *http.Request) {
|
||||
pdf.CellFormat(colWidths["Id"], rowHeight, "Team", "1", 0, "C", true, 0, "")
|
||||
pdf.CellFormat(colWidths["Name"], rowHeight, "Name", "1", 0, "C", true, 0, "")
|
||||
pdf.CellFormat(colWidths["Location"], rowHeight, "Location", "1", 0, "C", true, 0, "")
|
||||
pdf.CellFormat(colWidths["RookieYear"], rowHeight, "Rookie Year", "1", 1, "C", true, 0, "")
|
||||
if showHasConnected {
|
||||
pdf.CellFormat(colWidths["RookieYear"], rowHeight, "Rookie Year", "1", 0, "C", true, 0, "")
|
||||
pdf.CellFormat(colWidths["HasConnected"], rowHeight, "Connected?", "1", 1, "C", true, 0, "")
|
||||
} else {
|
||||
pdf.CellFormat(colWidths["RookieYear"], rowHeight, "Rookie Year", "1", 1, "C", true, 0, "")
|
||||
}
|
||||
pdf.SetFont("Arial", "", 10)
|
||||
for _, team := range teams {
|
||||
// Render team info row.
|
||||
@@ -296,7 +308,16 @@ func (web *Web) teamsPdfReportHandler(w http.ResponseWriter, r *http.Request) {
|
||||
pdf.CellFormat(colWidths["Name"], rowHeight, team.Nickname, "1", 0, "L", false, 0, "")
|
||||
location := fmt.Sprintf("%s, %s, %s", team.City, team.StateProv, team.Country)
|
||||
pdf.CellFormat(colWidths["Location"], rowHeight, location, "1", 0, "L", false, 0, "")
|
||||
pdf.CellFormat(colWidths["RookieYear"], rowHeight, strconv.Itoa(team.RookieYear), "1", 1, "L", false, 0, "")
|
||||
if showHasConnected {
|
||||
pdf.CellFormat(colWidths["RookieYear"], rowHeight, strconv.Itoa(team.RookieYear), "1", 0, "L", false, 0, "")
|
||||
var hasConnected string
|
||||
if team.HasConnected {
|
||||
hasConnected = "Yes"
|
||||
}
|
||||
pdf.CellFormat(colWidths["HasConnected"], rowHeight, hasConnected, "1", 1, "L", false, 0, "")
|
||||
} else {
|
||||
pdf.CellFormat(colWidths["RookieYear"], rowHeight, strconv.Itoa(team.RookieYear), "1", 1, "L", false, 0, "")
|
||||
}
|
||||
}
|
||||
|
||||
// Write out the PDF file as the HTTP response.
|
||||
|
||||
@@ -96,9 +96,9 @@ func TestTeamsCsvReport(t *testing.T) {
|
||||
recorder := web.getHttpResponse("/reports/csv/teams")
|
||||
assert.Equal(t, 200, recorder.Code)
|
||||
assert.Equal(t, "text/plain", recorder.HeaderMap["Content-Type"][0])
|
||||
expectedBody := "Number,Name,Nickname,City,StateProv,Country,RookieYear,RobotName\n254,\"NASA\"," +
|
||||
"\"The Cheesy Poofs\",\"San Jose\",\"CA\",\"USA\",1999,\"Barrage\"\n1114,\"GM\",\"Simbotics\"," +
|
||||
"\"St. Catharines\",\"ON\",\"Canada\",2003,\"Simbot Evolution\"\n\n"
|
||||
expectedBody := "Number,Name,Nickname,City,StateProv,Country,RookieYear,RobotName,HasConnected\n254,\"NASA\"," +
|
||||
"\"The Cheesy Poofs\",\"San Jose\",\"CA\",\"USA\",1999,\"Barrage\",false\n1114,\"GM\",\"Simbotics\"," +
|
||||
"\"St. Catharines\",\"ON\",\"Canada\",2003,\"Simbot Evolution\",false\n\n"
|
||||
assert.Equal(t, expectedBody, recorder.Body.String())
|
||||
}
|
||||
|
||||
|
||||
@@ -148,6 +148,7 @@ func (web *Web) teamEditPostHandler(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
}
|
||||
team.HasConnected = r.PostFormValue("hasConnected") == "on"
|
||||
err = web.arena.Database.SaveTeam(team)
|
||||
if err != nil {
|
||||
handleWebErr(w, err)
|
||||
|
||||
Reference in New Issue
Block a user