Skip to content

Commit 8933af2

Browse files
committed
Minor refactoring and reformatting.
1 parent 8659bb9 commit 8933af2

15 files changed

+81
-103
lines changed

field/arena_notifiers.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ func (arena *Arena) configureNotifiers() {
6464
arena.ScoringStatusNotifier = websocket.NewNotifier("scoringStatus", arena.generateScoringStatusMessage)
6565
}
6666

67-
func (arena *Arena) generateAllianceSelectionMessage() interface{} {
67+
func (arena *Arena) generateAllianceSelectionMessage() any {
6868
return &arena.AllianceSelectionAlliances
6969
}
7070

71-
func (arena *Arena) generateAllianceStationDisplayModeMessage() interface{} {
71+
func (arena *Arena) generateAllianceStationDisplayModeMessage() any {
7272
return arena.AllianceStationDisplayMode
7373
}
7474

75-
func (arena *Arena) generateArenaStatusMessage() interface{} {
75+
func (arena *Arena) generateArenaStatusMessage() any {
7676
// Convert AP team wifi network status array to a map by station for ease of client use.
7777
teamWifiStatuses := make(map[string]network.TeamWifiStatus)
7878
for i, station := range []string{"R1", "R2", "R3", "B1", "B2", "B3"} {
@@ -97,11 +97,11 @@ func (arena *Arena) generateArenaStatusMessage() interface{} {
9797
arena.Plc.GetArmorBlockStatuses()}
9898
}
9999

100-
func (arena *Arena) generateAudienceDisplayModeMessage() interface{} {
100+
func (arena *Arena) generateAudienceDisplayModeMessage() any {
101101
return arena.AudienceDisplayMode
102102
}
103103

104-
func (arena *Arena) generateDisplayConfigurationMessage() interface{} {
104+
func (arena *Arena) generateDisplayConfigurationMessage() any {
105105
// Notify() for this notifier must always called from a method that has a lock on the display mutex.
106106
// Make a copy of the map to avoid potential data races; otherwise the same map would get iterated through as it is
107107
// serialized to JSON, outside the mutex lock.
@@ -112,18 +112,18 @@ func (arena *Arena) generateDisplayConfigurationMessage() interface{} {
112112
return displaysCopy
113113
}
114114

115-
func (arena *Arena) generateEventStatusMessage() interface{} {
115+
func (arena *Arena) generateEventStatusMessage() any {
116116
return arena.EventStatus
117117
}
118118

119-
func (arena *Arena) generateLowerThirdMessage() interface{} {
119+
func (arena *Arena) generateLowerThirdMessage() any {
120120
return &struct {
121121
LowerThird *model.LowerThird
122122
ShowLowerThird bool
123123
}{arena.LowerThird, arena.ShowLowerThird}
124124
}
125125

126-
func (arena *Arena) generateMatchLoadMessage() interface{} {
126+
func (arena *Arena) generateMatchLoadMessage() any {
127127
teams := make(map[string]*model.Team)
128128
for station, allianceStation := range arena.AllianceStations {
129129
teams[station] = allianceStation.Team
@@ -172,15 +172,15 @@ func (arena *Arena) generateMatchLoadMessage() interface{} {
172172
}
173173
}
174174

175-
func (arena *Arena) generateMatchTimeMessage() interface{} {
175+
func (arena *Arena) generateMatchTimeMessage() any {
176176
return MatchTimeMessage{arena.MatchState, int(arena.MatchTimeSec())}
177177
}
178178

179-
func (arena *Arena) generateMatchTimingMessage() interface{} {
179+
func (arena *Arena) generateMatchTimingMessage() any {
180180
return &game.MatchTiming
181181
}
182182

183-
func (arena *Arena) generateRealtimeScoreMessage() interface{} {
183+
func (arena *Arena) generateRealtimeScoreMessage() any {
184184
fields := struct {
185185
Red *audienceAllianceScoreFields
186186
Blue *audienceAllianceScoreFields
@@ -192,7 +192,7 @@ func (arena *Arena) generateRealtimeScoreMessage() interface{} {
192192
return &fields
193193
}
194194

195-
func (arena *Arena) generateScorePostedMessage() interface{} {
195+
func (arena *Arena) generateScorePostedMessage() any {
196196
// For elimination matches, summarize the state of the series.
197197
var seriesStatus, seriesLeader string
198198
var matchup *bracket.Matchup
@@ -235,7 +235,7 @@ func (arena *Arena) generateScorePostedMessage() interface{} {
235235
}
236236
}
237237

238-
func (arena *Arena) generateScoringStatusMessage() interface{} {
238+
func (arena *Arena) generateScoringStatusMessage() any {
239239
return &struct {
240240
RefereeScoreReady bool
241241
RedScoreReady bool

field/display.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func (display *Display) ToUrl() string {
139139
return builder.String()
140140
}
141141

142-
func (display *Display) generateDisplayConfigurationMessage() interface{} {
142+
func (display *Display) generateDisplayConfigurationMessage() any {
143143
return display.ToUrl()
144144
}
145145

field/driver_station_connection.go

+2-8
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,9 @@ func (dsConn *DriverStationConnection) encodeControlPacket(arena *Arena) [22]byt
224224
// Remaining number of seconds in match.
225225
var matchSecondsRemaining int
226226
switch arena.MatchState {
227-
case PreMatch:
228-
fallthrough
229-
case TimeoutActive:
230-
fallthrough
231-
case PostTimeout:
227+
case PreMatch, TimeoutActive, PostTimeout:
232228
matchSecondsRemaining = game.MatchTiming.AutoDurationSec
233-
case StartMatch:
234-
fallthrough
235-
case AutoPeriod:
229+
case StartMatch, AutoPeriod:
236230
matchSecondsRemaining = game.MatchTiming.AutoDurationSec - int(arena.MatchTimeSec())
237231
case PausePeriod:
238232
matchSecondsRemaining = game.MatchTiming.TeleopDurationSec

game/grid_test.go

+20-36
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,31 @@ import (
88
"testing"
99
)
1010

11-
type gridTestCase struct {
12-
name string
11+
var gridTestCases = map[string]struct {
1312
gridScoringActions []gridScoringAction
1413
expectedAutoGamePiecePoints int
1514
expectedTeleopGamePiecePoints int
1615
expectedSuperchargedPoints int
1716
expectedLinks []Link
1817
expectedIsCoopertitionThresholdAchieved bool
1918
expectedIsFull bool
20-
}
21-
22-
var gridTestCases = []gridTestCase{
23-
{
24-
name: "No scoring actions",
25-
},
26-
{
27-
name: "Same node scored multiple times in auto",
19+
}{
20+
"No scoring actions": {},
21+
"Same node scored multiple times in auto": {
2822
gridScoringActions: []gridScoringAction{
2923
{rowTop, 7, TwoCubes, true},
3024
},
3125
expectedAutoGamePiecePoints: 6,
3226
expectedTeleopGamePiecePoints: 0,
3327
},
34-
{
35-
name: "Same node scored multiple times in teleop",
28+
"Same node scored multiple times in teleop": {
3629
gridScoringActions: []gridScoringAction{
3730
{rowTop, 7, TwoCubes, false},
3831
},
3932
expectedAutoGamePiecePoints: 0,
4033
expectedTeleopGamePiecePoints: 5,
4134
},
42-
{
43-
name: "Grid with many pieces but no links and no co-op bonus",
35+
"Grid with many pieces but no links and no co-op bonus": {
4436
gridScoringActions: []gridScoringAction{
4537
{rowBottom, 0, Cone, true},
4638
{rowBottom, 1, Cone, false},
@@ -60,8 +52,7 @@ var gridTestCases = []gridTestCase{
6052
expectedAutoGamePiecePoints: 22,
6153
expectedTeleopGamePiecePoints: 30,
6254
},
63-
{
64-
name: "Non-aligned links",
55+
"Non-aligned links": {
6556
gridScoringActions: []gridScoringAction{
6657
{rowMiddle, 1, Cube, false},
6758
{rowMiddle, 2, Cone, false},
@@ -78,8 +69,7 @@ var gridTestCases = []gridTestCase{
7869
},
7970
expectedIsCoopertitionThresholdAchieved: true,
8071
},
81-
{
82-
name: "Coopertition threshold achieved across multiple rows",
72+
"Coopertition threshold achieved across multiple rows": {
8373
gridScoringActions: []gridScoringAction{
8474
{rowBottom, 3, Cone, true},
8575
{rowMiddle, 4, Cube, false},
@@ -89,8 +79,7 @@ var gridTestCases = []gridTestCase{
8979
expectedTeleopGamePiecePoints: 3,
9080
expectedIsCoopertitionThresholdAchieved: true,
9181
},
92-
{
93-
name: "Coopertition threshold not achieved due to wrong game piece",
82+
"Coopertition threshold not achieved due to wrong game piece": {
9483
gridScoringActions: []gridScoringAction{
9584
{rowBottom, 3, Cone, true},
9685
{rowMiddle, 4, Cube, false},
@@ -100,8 +89,7 @@ var gridTestCases = []gridTestCase{
10089
expectedTeleopGamePiecePoints: 3,
10190
expectedIsCoopertitionThresholdAchieved: false,
10291
},
103-
{
104-
name: "Full grid without supercharging",
92+
"Full grid without supercharging": {
10593
gridScoringActions: []gridScoringAction{
10694
{rowBottom, 0, Cone, true},
10795
{rowBottom, 1, Cone, false},
@@ -147,8 +135,7 @@ var gridTestCases = []gridTestCase{
147135
expectedIsCoopertitionThresholdAchieved: true,
148136
expectedIsFull: true,
149137
},
150-
{
151-
name: "Full grid with supercharging",
138+
"Full grid with supercharging": {
152139
gridScoringActions: []gridScoringAction{
153140
{rowBottom, 0, ConeThenCube, true},
154141
{rowBottom, 1, Cone, false},
@@ -195,8 +182,7 @@ var gridTestCases = []gridTestCase{
195182
expectedIsCoopertitionThresholdAchieved: true,
196183
expectedIsFull: true,
197184
},
198-
{
199-
name: "Invalid scoring actions are ignored",
185+
"Invalid scoring actions are ignored": {
200186
gridScoringActions: []gridScoringAction{
201187
{rowMiddle, 0, Cube, false},
202188
{rowMiddle, 1, Cone, true},
@@ -221,17 +207,15 @@ var gridTestCases = []gridTestCase{
221207
}
222208

223209
func TestGrid(t *testing.T) {
224-
for _, testCase := range gridTestCases {
210+
for name, testCase := range gridTestCases {
225211
grid := buildTestGrid(testCase.gridScoringActions)
226212

227-
assert.Equal(t, testCase.expectedAutoGamePiecePoints, grid.AutoGamePiecePoints(), testCase.name)
228-
assert.Equal(t, testCase.expectedTeleopGamePiecePoints, grid.TeleopGamePiecePoints(), testCase.name)
229-
assert.Equal(t, testCase.expectedSuperchargedPoints, grid.SuperchargedPoints(), testCase.name)
230-
assert.Equal(t, 5*len(testCase.expectedLinks), grid.LinkPoints(), testCase.name)
231-
assert.Equal(t, testCase.expectedLinks, grid.Links(), testCase.name)
232-
assert.Equal(
233-
t, testCase.expectedIsCoopertitionThresholdAchieved, grid.IsCoopertitionThresholdAchieved(), testCase.name,
234-
)
235-
assert.Equal(t, testCase.expectedIsFull, grid.IsFull(), testCase.name)
213+
assert.Equal(t, testCase.expectedAutoGamePiecePoints, grid.AutoGamePiecePoints(), name)
214+
assert.Equal(t, testCase.expectedTeleopGamePiecePoints, grid.TeleopGamePiecePoints(), name)
215+
assert.Equal(t, testCase.expectedSuperchargedPoints, grid.SuperchargedPoints(), name)
216+
assert.Equal(t, 5*len(testCase.expectedLinks), grid.LinkPoints(), name)
217+
assert.Equal(t, testCase.expectedLinks, grid.Links(), name)
218+
assert.Equal(t, testCase.expectedIsCoopertitionThresholdAchieved, grid.IsCoopertitionThresholdAchieved(), name)
219+
assert.Equal(t, testCase.expectedIsFull, grid.IsFull(), name)
236220
}
237221
}

partner/tba.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ type TbaClient struct {
3535
}
3636

3737
type TbaMatch struct {
38-
CompLevel string `json:"comp_level"`
39-
SetNumber int `json:"set_number"`
40-
MatchNumber int `json:"match_number"`
41-
Alliances map[string]*TbaAlliance `json:"alliances"`
42-
ScoreBreakdown map[string]map[string]interface{} `json:"score_breakdown"`
43-
TimeString string `json:"time_string"`
44-
TimeUtc string `json:"time_utc"`
45-
DisplayName string `json:"display_name"`
38+
CompLevel string `json:"comp_level"`
39+
SetNumber int `json:"set_number"`
40+
MatchNumber int `json:"match_number"`
41+
Alliances map[string]*TbaAlliance `json:"alliances"`
42+
ScoreBreakdown map[string]map[string]any `json:"score_breakdown"`
43+
TimeString string `json:"time_string"`
44+
TimeUtc string `json:"time_utc"`
45+
DisplayName string `json:"display_name"`
4646
}
4747

4848
type TbaAlliance struct {
@@ -140,8 +140,8 @@ type TbaEvent struct {
140140
}
141141

142142
type TbaMediaItem struct {
143-
Details map[string]interface{} `json:"details"`
144-
Type string `json:"type"`
143+
Details map[string]any `json:"details"`
144+
Type string `json:"type"`
145145
}
146146

147147
type TbaPublishedAward struct {
@@ -356,7 +356,7 @@ func (client *TbaClient) PublishMatches(database *model.Database) error {
356356
matchNumber, _ := strconv.Atoi(match.DisplayName)
357357

358358
// Fill in scores if the match has been played.
359-
var scoreBreakdown map[string]map[string]interface{}
359+
var scoreBreakdown map[string]map[string]any
360360
var redScore, blueScore *int
361361
var redCards, blueCards map[string]string
362362
if match.IsComplete() {
@@ -365,7 +365,7 @@ func (client *TbaClient) PublishMatches(database *model.Database) error {
365365
return err
366366
}
367367
if matchResult != nil {
368-
scoreBreakdown = make(map[string]map[string]interface{})
368+
scoreBreakdown = make(map[string]map[string]any)
369369
scoreBreakdown["red"] = createTbaScoringBreakdown(eventSettings, &match, matchResult, "red")
370370
scoreBreakdown["blue"] = createTbaScoringBreakdown(eventSettings, &match, matchResult, "blue")
371371
redScoreValue := scoreBreakdown["red"]["totalPoints"].(int)
@@ -579,7 +579,7 @@ func createTbaScoringBreakdown(
579579
match *model.Match,
580580
matchResult *model.MatchResult,
581581
alliance string,
582-
) map[string]interface{} {
582+
) map[string]any {
583583
var breakdown TbaScoreBreakdown
584584
var score *game.Score
585585
var scoreSummary, opponentScoreSummary *game.ScoreSummary
@@ -650,7 +650,7 @@ func createTbaScoringBreakdown(
650650

651651
// Turn the breakdown struct into a map in order to be able to remove any fields that are disabled based on the
652652
// event settings.
653-
breakdownMap := make(map[string]interface{})
653+
breakdownMap := make(map[string]any)
654654
_ = mapstructure.Decode(breakdown, &breakdownMap)
655655
if eventSettings.SustainabilityBonusLinkThresholdWithCoop == 0 {
656656
delete(breakdownMap, "quintetAchieved")

plc/plc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ func (plc *ModbusPlc) writeCoils() bool {
384384
return true
385385
}
386386

387-
func (plc *ModbusPlc) generateIoChangeMessage() interface{} {
387+
func (plc *ModbusPlc) generateIoChangeMessage() any {
388388
return &struct {
389389
Inputs []bool
390390
Registers []uint16

web/field_monitor_display_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestFieldMonitorDisplayWebsocket(t *testing.T) {
4242
readWebsocketType(t, ws, "matchLoad")
4343

4444
// Should not be able to update team notes.
45-
ws.Write("updateTeamNotes", map[string]interface{}{"station": "B1", "notes": "Bypassed in M1"})
45+
ws.Write("updateTeamNotes", map[string]any{"station": "B1", "notes": "Bypassed in M1"})
4646
assert.Contains(t, readWebsocketError(t, ws), "Must be in FTA mode to update team notes")
4747
assert.Equal(t, "", web.arena.AllianceStations["B1"].Team.FtaNotes)
4848
}
@@ -70,13 +70,13 @@ func TestFieldMonitorFtaDisplayWebsocket(t *testing.T) {
7070
readWebsocketType(t, ws, "matchLoad")
7171

7272
// Should not be able to update team notes.
73-
ws.Write("updateTeamNotes", map[string]interface{}{"station": "B1", "notes": "Bypassed in M1"})
73+
ws.Write("updateTeamNotes", map[string]any{"station": "B1", "notes": "Bypassed in M1"})
7474
readWebsocketType(t, ws, "arenaStatus")
7575
assert.Equal(t, "Bypassed in M1", web.arena.AllianceStations["B1"].Team.FtaNotes)
7676

7777
// Check error scenarios.
78-
ws.Write("updateTeamNotes", map[string]interface{}{"station": "N", "notes": "Bypassed in M2"})
78+
ws.Write("updateTeamNotes", map[string]any{"station": "N", "notes": "Bypassed in M2"})
7979
assert.Contains(t, readWebsocketError(t, ws), "Invalid alliance station")
80-
ws.Write("updateTeamNotes", map[string]interface{}{"station": "R3", "notes": "Bypassed in M3"})
80+
ws.Write("updateTeamNotes", map[string]any{"station": "R3", "notes": "Bypassed in M3"})
8181
assert.Contains(t, readWebsocketError(t, ws), "No team present")
8282
}

web/match_play_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -313,12 +313,12 @@ func TestMatchPlayWebsocketCommands(t *testing.T) {
313313
// Test match setup commands.
314314
ws.Write("substituteTeam", nil)
315315
assert.Contains(t, readWebsocketError(t, ws), "Invalid alliance station")
316-
ws.Write("substituteTeam", map[string]interface{}{"team": 254, "position": "B5"})
316+
ws.Write("substituteTeam", map[string]any{"team": 254, "position": "B5"})
317317
assert.Contains(t, readWebsocketError(t, ws), "Invalid alliance station")
318-
ws.Write("substituteTeam", map[string]interface{}{"team": 254, "position": "B1"})
318+
ws.Write("substituteTeam", map[string]any{"team": 254, "position": "B1"})
319319
readWebsocketType(t, ws, "arenaStatus")
320320
assert.Equal(t, 254, web.arena.CurrentMatch.Blue1)
321-
ws.Write("substituteTeam", map[string]interface{}{"team": 0, "position": "B1"})
321+
ws.Write("substituteTeam", map[string]any{"team": 0, "position": "B1"})
322322
readWebsocketType(t, ws, "arenaStatus")
323323
assert.Equal(t, 0, web.arena.CurrentMatch.Blue1)
324324
ws.Write("toggleBypass", nil)
@@ -456,7 +456,7 @@ func readWebsocketStatusMatchTime(t *testing.T, ws *websocket.Websocket) (bool,
456456
return getStatusMatchTime(t, readWebsocketMultiple(t, ws, 2))
457457
}
458458

459-
func getStatusMatchTime(t *testing.T, messages map[string]interface{}) (bool, field.MatchTimeMessage) {
459+
func getStatusMatchTime(t *testing.T, messages map[string]any) (bool, field.MatchTimeMessage) {
460460
_, statusReceived := messages["arenaStatus"]
461461
message, ok := messages["matchTime"]
462462
var matchTime field.MatchTimeMessage

web/setup_lower_thirds_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func TestSetupLowerThirds(t *testing.T) {
5454
assert.Equal(t, "Top Text 6", lowerThird.TopText)
5555
assert.Equal(t, false, web.arena.ShowLowerThird)
5656

57-
ws.Write("reorderLowerThird", map[string]interface{}{"Id": 2, "moveUp": false})
57+
ws.Write("reorderLowerThird", map[string]any{"Id": 2, "moveUp": false})
5858
time.Sleep(time.Millisecond * 100)
5959
lowerThirds, _ := web.arena.Database.GetAllLowerThirds()
6060
assert.Equal(t, 3, lowerThirds[0].Id)

0 commit comments

Comments
 (0)