blob: 26fad0ff8d1e8e37bc0b2c89bca0f6a53eec0062 [file] [log] [blame]
Philipp Schradercdb5cfc2022-02-20 14:57:07 -08001package requests
2
3import (
Philipp Schradercdb5cfc2022-02-20 14:57:07 -08004 "net/http"
Philipp Schradercbf5c6a2022-02-27 23:25:19 -08005 "reflect"
Philipp Schradercdb5cfc2022-02-20 14:57:07 -08006 "testing"
7
Philipp Schrader8747f1b2022-02-23 23:56:22 -08008 "github.com/frc971/971-Robot-Code/scouting/db"
Philipp Schradercbf5c6a2022-02-27 23:25:19 -08009 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/debug"
Filip Kujawac1ded372023-05-27 14:33:43 -070010 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/delete_2023_data_scouting"
Emily Markova8cb91312024-02-02 12:30:37 -080011 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/delete_2024_data_scouting"
Emily Markova290147d2023-03-03 22:40:06 -080012 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_2023_data_scouting"
13 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_2023_data_scouting_response"
Emily Markova8cb91312024-02-02 12:30:37 -080014 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_2024_data_scouting"
15 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_2024_data_scouting_response"
Filip Kujawaf882e022022-12-14 13:14:08 -080016 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_all_driver_rankings"
17 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_all_driver_rankings_response"
Philipp Schradercbf5c6a2022-02-27 23:25:19 -080018 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_all_matches"
19 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_all_matches_response"
Filip Kujawaf882e022022-12-14 13:14:08 -080020 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_all_notes"
21 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_all_notes_response"
Emily Markova8e39f452023-12-23 12:17:30 -080022 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_all_pit_images"
23 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_all_pit_images_response"
Alex Perry81f96ba2022-03-13 18:26:19 -070024 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_notes_for_team"
Emily Markovafaecfe12023-07-01 12:40:03 -070025 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_pit_images"
26 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_pit_images_response"
Milo Lin1d59f0c2022-06-22 20:30:58 -070027 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_shift_schedule"
28 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_shift_schedule_response"
Emily Markova8cb91312024-02-02 12:30:37 -080029 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/submit_2024_actions"
Emily Markova1abe9782023-03-11 19:45:38 -080030 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/submit_actions"
Filip Kujawa210a03b2022-11-24 14:41:11 -080031 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/submit_driver_ranking"
Alex Perry81f96ba2022-03-13 18:26:19 -070032 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/submit_notes"
Emily Markovafaecfe12023-07-01 12:40:03 -070033 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/submit_pit_image"
Milo Lin1d59f0c2022-06-22 20:30:58 -070034 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/submit_shift_schedule"
Philipp Schradercdb5cfc2022-02-20 14:57:07 -080035 "github.com/frc971/971-Robot-Code/scouting/webserver/server"
36 flatbuffers "github.com/google/flatbuffers/go"
37)
38
39// Validates that an unhandled address results in a 404.
40func Test404(t *testing.T) {
Philipp Schrader8747f1b2022-02-23 23:56:22 -080041 db := MockDatabase{}
Philipp Schradercdb5cfc2022-02-20 14:57:07 -080042 scoutingServer := server.NewScoutingServer()
Philipp Schrader43c730b2023-02-26 20:27:44 -080043 HandleRequests(&db, scoutingServer)
Philipp Schradercdb5cfc2022-02-20 14:57:07 -080044 scoutingServer.Start(8080)
45 defer scoutingServer.Stop()
46
47 resp, err := http.Get("http://localhost:8080/requests/foo")
48 if err != nil {
49 t.Fatalf("Failed to get data: %v", err)
50 }
51 if resp.StatusCode != http.StatusNotFound {
52 t.Fatalf("Expected error code 404, but got %d instead", resp.Status)
53 }
54}
55
Philipp Schradercbf5c6a2022-02-27 23:25:19 -080056// Validates that we can request the full match list.
57func TestRequestAllMatches(t *testing.T) {
58 db := MockDatabase{
Emily Markovabf24c9e2023-02-08 20:31:11 -080059 matches: []db.TeamMatch{
Philipp Schradercbf5c6a2022-02-27 23:25:19 -080060 {
Emily Markovaabcac6e2023-02-18 17:50:03 -080061 MatchNumber: 1, SetNumber: 1, CompLevel: "qm",
Emily Markovab8551572023-03-22 19:49:39 -070062 Alliance: "R", AlliancePosition: 1, TeamNumber: "5",
Emily Markovabf24c9e2023-02-08 20:31:11 -080063 },
64 {
Emily Markovaabcac6e2023-02-18 17:50:03 -080065 MatchNumber: 1, SetNumber: 1, CompLevel: "qm",
Emily Markovab8551572023-03-22 19:49:39 -070066 Alliance: "R", AlliancePosition: 2, TeamNumber: "42",
Emily Markovabf24c9e2023-02-08 20:31:11 -080067 },
68 {
Emily Markovaabcac6e2023-02-18 17:50:03 -080069 MatchNumber: 1, SetNumber: 1, CompLevel: "qm",
Emily Markovab8551572023-03-22 19:49:39 -070070 Alliance: "R", AlliancePosition: 3, TeamNumber: "600",
Emily Markovabf24c9e2023-02-08 20:31:11 -080071 },
72 {
Emily Markovaabcac6e2023-02-18 17:50:03 -080073 MatchNumber: 1, SetNumber: 1, CompLevel: "qm",
Emily Markovab8551572023-03-22 19:49:39 -070074 Alliance: "B", AlliancePosition: 1, TeamNumber: "971",
Emily Markovabf24c9e2023-02-08 20:31:11 -080075 },
76 {
Emily Markovaabcac6e2023-02-18 17:50:03 -080077 MatchNumber: 1, SetNumber: 1, CompLevel: "qm",
Emily Markovab8551572023-03-22 19:49:39 -070078 Alliance: "B", AlliancePosition: 2, TeamNumber: "400",
Emily Markovabf24c9e2023-02-08 20:31:11 -080079 },
80 {
Emily Markovaabcac6e2023-02-18 17:50:03 -080081 MatchNumber: 1, SetNumber: 1, CompLevel: "qm",
Emily Markovab8551572023-03-22 19:49:39 -070082 Alliance: "B", AlliancePosition: 3, TeamNumber: "200",
Philipp Schradercbf5c6a2022-02-27 23:25:19 -080083 },
84 {
Emily Markovaabcac6e2023-02-18 17:50:03 -080085 MatchNumber: 2, SetNumber: 1, CompLevel: "qm",
Emily Markovab8551572023-03-22 19:49:39 -070086 Alliance: "R", AlliancePosition: 1, TeamNumber: "6",
Emily Markovabf24c9e2023-02-08 20:31:11 -080087 },
88 {
Emily Markovaabcac6e2023-02-18 17:50:03 -080089 MatchNumber: 2, SetNumber: 1, CompLevel: "qm",
Emily Markovab8551572023-03-22 19:49:39 -070090 Alliance: "R", AlliancePosition: 2, TeamNumber: "43",
Emily Markovabf24c9e2023-02-08 20:31:11 -080091 },
92 {
Emily Markovaabcac6e2023-02-18 17:50:03 -080093 MatchNumber: 2, SetNumber: 1, CompLevel: "qm",
Emily Markovab8551572023-03-22 19:49:39 -070094 Alliance: "R", AlliancePosition: 3, TeamNumber: "601",
Emily Markovabf24c9e2023-02-08 20:31:11 -080095 },
96 {
Emily Markovaabcac6e2023-02-18 17:50:03 -080097 MatchNumber: 2, SetNumber: 1, CompLevel: "qm",
Emily Markovab8551572023-03-22 19:49:39 -070098 Alliance: "B", AlliancePosition: 1, TeamNumber: "972",
Emily Markovabf24c9e2023-02-08 20:31:11 -080099 },
100 {
Emily Markovaabcac6e2023-02-18 17:50:03 -0800101 MatchNumber: 2, SetNumber: 1, CompLevel: "qm",
Emily Markovab8551572023-03-22 19:49:39 -0700102 Alliance: "B", AlliancePosition: 2, TeamNumber: "401",
Emily Markovabf24c9e2023-02-08 20:31:11 -0800103 },
104 {
Emily Markovaabcac6e2023-02-18 17:50:03 -0800105 MatchNumber: 2, SetNumber: 1, CompLevel: "qm",
Emily Markovab8551572023-03-22 19:49:39 -0700106 Alliance: "B", AlliancePosition: 3, TeamNumber: "201",
Philipp Schradercbf5c6a2022-02-27 23:25:19 -0800107 },
108 {
Emily Markovaabcac6e2023-02-18 17:50:03 -0800109 MatchNumber: 3, SetNumber: 1, CompLevel: "qm",
Emily Markovab8551572023-03-22 19:49:39 -0700110 Alliance: "R", AlliancePosition: 1, TeamNumber: "7",
Emily Markovabf24c9e2023-02-08 20:31:11 -0800111 },
112 {
Emily Markovaabcac6e2023-02-18 17:50:03 -0800113 MatchNumber: 3, SetNumber: 1, CompLevel: "qm",
Emily Markovab8551572023-03-22 19:49:39 -0700114 Alliance: "R", AlliancePosition: 2, TeamNumber: "44",
Emily Markovabf24c9e2023-02-08 20:31:11 -0800115 },
116 {
Emily Markovaabcac6e2023-02-18 17:50:03 -0800117 MatchNumber: 3, SetNumber: 1, CompLevel: "qm",
Emily Markovab8551572023-03-22 19:49:39 -0700118 Alliance: "R", AlliancePosition: 3, TeamNumber: "602",
Emily Markovabf24c9e2023-02-08 20:31:11 -0800119 },
120 {
Emily Markovaabcac6e2023-02-18 17:50:03 -0800121 MatchNumber: 3, SetNumber: 1, CompLevel: "qm",
Emily Markovab8551572023-03-22 19:49:39 -0700122 Alliance: "B", AlliancePosition: 1, TeamNumber: "973",
Emily Markovabf24c9e2023-02-08 20:31:11 -0800123 },
124 {
Emily Markovaabcac6e2023-02-18 17:50:03 -0800125 MatchNumber: 3, SetNumber: 1, CompLevel: "qm",
Emily Markovab8551572023-03-22 19:49:39 -0700126 Alliance: "B", AlliancePosition: 2, TeamNumber: "402",
Emily Markovabf24c9e2023-02-08 20:31:11 -0800127 },
128 {
Emily Markovaabcac6e2023-02-18 17:50:03 -0800129 MatchNumber: 3, SetNumber: 1, CompLevel: "qm",
Emily Markovab8551572023-03-22 19:49:39 -0700130 Alliance: "B", AlliancePosition: 3, TeamNumber: "202",
Philipp Schradercbf5c6a2022-02-27 23:25:19 -0800131 },
132 },
Philipp Schrader0f7b6362023-03-11 14:02:48 -0800133 // Pretend that we have some data scouting data.
Emily Markovadcadcb62024-02-03 13:07:17 -0800134 stats2024: []db.Stats2024{
Philipp Schrader0f7b6362023-03-11 14:02:48 -0800135 {
Emily Markovadcadcb62024-02-03 13:07:17 -0800136 PreScouting: false, TeamNumber: "5",
137 MatchNumber: 1, SetNumber: 1, CompLevel: "qm", StartingQuadrant: 3,
138 SpeakerAuto: 2, AmpAuto: 4, NotesDroppedAuto: 1, MobilityAuto: true,
139 Speaker: 0, Amp: 1, SpeakerAmplified: 2, AmpAmplified: 1,
Emily Markova040123c2024-02-27 09:48:37 -0800140 NotesDropped: 0, Penalties: 1, TrapNote: true, Spotlight: false, AvgCycle: 233,
141 Park: false, OnStage: true, Harmony: false, RobotDied: false, CollectedBy: "alex",
Philipp Schrader0f7b6362023-03-11 14:02:48 -0800142 },
143 {
Emily Markovadcadcb62024-02-03 13:07:17 -0800144 PreScouting: false, TeamNumber: "973",
145 MatchNumber: 3, SetNumber: 1, CompLevel: "qm", StartingQuadrant: 1,
146 SpeakerAuto: 0, AmpAuto: 2, NotesDroppedAuto: 0, MobilityAuto: false,
147 Speaker: 0, Amp: 4, SpeakerAmplified: 3, AmpAmplified: 1,
Emily Markova6079e2f2024-02-17 13:17:24 -0800148 NotesDropped: 0, Penalties: 1, TrapNote: true, Spotlight: false, AvgCycle: 120,
Emily Markova040123c2024-02-27 09:48:37 -0800149 Park: true, OnStage: false, Harmony: false, RobotDied: true, CollectedBy: "bob",
Philipp Schrader0f7b6362023-03-11 14:02:48 -0800150 },
151 },
Philipp Schradercbf5c6a2022-02-27 23:25:19 -0800152 }
153 scoutingServer := server.NewScoutingServer()
Philipp Schrader43c730b2023-02-26 20:27:44 -0800154 HandleRequests(&db, scoutingServer)
Philipp Schradercbf5c6a2022-02-27 23:25:19 -0800155 scoutingServer.Start(8080)
156 defer scoutingServer.Stop()
157
158 builder := flatbuffers.NewBuilder(1024)
159 builder.Finish((&request_all_matches.RequestAllMatchesT{}).Pack(builder))
160
161 response, err := debug.RequestAllMatches("http://localhost:8080", builder.FinishedBytes())
162 if err != nil {
163 t.Fatal("Failed to request all matches: ", err)
164 }
165
166 expected := request_all_matches_response.RequestAllMatchesResponseT{
167 MatchList: []*request_all_matches_response.MatchT{
Philipp Schrader30b4a682022-04-16 14:36:17 -0700168 // MatchNumber, SetNumber, CompLevel
Philipp Schradercbf5c6a2022-02-27 23:25:19 -0800169 // R1, R2, R3, B1, B2, B3
170 {
Emily Markovaabcac6e2023-02-18 17:50:03 -0800171 1, 1, "qm",
Emily Markovab8551572023-03-22 19:49:39 -0700172 "5", "42", "600", "971", "400", "200",
Philipp Schrader0f7b6362023-03-11 14:02:48 -0800173 &request_all_matches_response.ScoutedLevelT{
174 // The R1 team has already been data
175 // scouted.
176 true, false, false, false, false, false,
177 },
Philipp Schradercbf5c6a2022-02-27 23:25:19 -0800178 },
179 {
Emily Markovaabcac6e2023-02-18 17:50:03 -0800180 2, 1, "qm",
Emily Markovab8551572023-03-22 19:49:39 -0700181 "6", "43", "601", "972", "401", "201",
Philipp Schrader0f7b6362023-03-11 14:02:48 -0800182 &request_all_matches_response.ScoutedLevelT{
183 false, false, false, false, false, false,
184 },
Philipp Schradercbf5c6a2022-02-27 23:25:19 -0800185 },
186 {
Emily Markovaabcac6e2023-02-18 17:50:03 -0800187 3, 1, "qm",
Emily Markovab8551572023-03-22 19:49:39 -0700188 "7", "44", "602", "973", "402", "202",
Philipp Schrader0f7b6362023-03-11 14:02:48 -0800189 &request_all_matches_response.ScoutedLevelT{
190 // The B1 team has already been data
191 // scouted.
192 false, false, false, true, false, false,
193 },
Philipp Schradercbf5c6a2022-02-27 23:25:19 -0800194 },
195 },
196 }
197 if len(expected.MatchList) != len(response.MatchList) {
198 t.Fatal("Expected ", expected, ", but got ", *response)
199 }
200 for i, match := range expected.MatchList {
201 if !reflect.DeepEqual(*match, *response.MatchList[i]) {
202 t.Fatal("Expected for match", i, ":", *match, ", but got:", *response.MatchList[i])
203 }
204 }
Philipp Schrader30005e42022-03-06 13:53:58 -0800205
Philipp Schradercbf5c6a2022-02-27 23:25:19 -0800206}
207
Emily Markova8cb91312024-02-02 12:30:37 -0800208// Validates that we can request the 2024 stats.
209func TestRequest2024DataScouting(t *testing.T) {
210 db := MockDatabase{
211 stats2024: []db.Stats2024{
212 {
213 PreScouting: false, TeamNumber: "342",
214 MatchNumber: 3, SetNumber: 1, CompLevel: "quals", StartingQuadrant: 4,
215 SpeakerAuto: 1, AmpAuto: 1, NotesDroppedAuto: 0, MobilityAuto: true,
216 Speaker: 4, Amp: 2, SpeakerAmplified: 1, AmpAmplified: 0,
Emily Markova6079e2f2024-02-17 13:17:24 -0800217 NotesDropped: 2, Penalties: 2, TrapNote: true, Spotlight: true, AvgCycle: 0,
Emily Markova040123c2024-02-27 09:48:37 -0800218 Park: true, OnStage: false, Harmony: false, RobotDied: false, CollectedBy: "alex",
Emily Markova8cb91312024-02-02 12:30:37 -0800219 },
220 {
221 PreScouting: false, TeamNumber: "982",
222 MatchNumber: 3, SetNumber: 1, CompLevel: "quals", StartingQuadrant: 2,
223 SpeakerAuto: 0, AmpAuto: 0, NotesDroppedAuto: 0, MobilityAuto: false,
224 Speaker: 0, Amp: 2, SpeakerAmplified: 3, AmpAmplified: 2,
Emily Markova6079e2f2024-02-17 13:17:24 -0800225 NotesDropped: 1, Penalties: 0, TrapNote: false, Spotlight: true, AvgCycle: 0,
Emily Markova040123c2024-02-27 09:48:37 -0800226 Park: false, OnStage: true, Harmony: false, RobotDied: false, CollectedBy: "george",
Emily Markova8cb91312024-02-02 12:30:37 -0800227 },
228 },
229 }
230 scoutingServer := server.NewScoutingServer()
231 HandleRequests(&db, scoutingServer)
232 scoutingServer.Start(8080)
233 defer scoutingServer.Stop()
234
235 builder := flatbuffers.NewBuilder(1024)
236 builder.Finish((&request_2024_data_scouting.Request2024DataScoutingT{}).Pack(builder))
237
238 response, err := debug.Request2024DataScouting("http://localhost:8080", builder.FinishedBytes())
239 if err != nil {
240 t.Fatal("Failed to request all matches: ", err)
241 }
242
243 expected := request_2024_data_scouting_response.Request2024DataScoutingResponseT{
244 StatsList: []*request_2024_data_scouting_response.Stats2024T{
245 {
246 PreScouting: false, TeamNumber: "342",
247 MatchNumber: 3, SetNumber: 1, CompLevel: "quals", StartingQuadrant: 4,
248 SpeakerAuto: 1, AmpAuto: 1, NotesDroppedAuto: 0, MobilityAuto: true,
249 Speaker: 4, Amp: 2, SpeakerAmplified: 1, AmpAmplified: 0,
Emily Markova6079e2f2024-02-17 13:17:24 -0800250 NotesDropped: 2, Penalties: 2, TrapNote: true, Spotlight: true, AvgCycle: 0,
Emily Markova040123c2024-02-27 09:48:37 -0800251 Park: true, OnStage: false, Harmony: false, RobotDied: false, CollectedBy: "alex",
Emily Markova8cb91312024-02-02 12:30:37 -0800252 },
253 {
254 PreScouting: false, TeamNumber: "982",
255 MatchNumber: 3, SetNumber: 1, CompLevel: "quals", StartingQuadrant: 2,
256 SpeakerAuto: 0, AmpAuto: 0, NotesDroppedAuto: 0, MobilityAuto: false,
257 Speaker: 0, Amp: 2, SpeakerAmplified: 3, AmpAmplified: 2,
Emily Markova6079e2f2024-02-17 13:17:24 -0800258 NotesDropped: 1, Penalties: 0, TrapNote: false, Spotlight: true, AvgCycle: 0,
Emily Markova040123c2024-02-27 09:48:37 -0800259 Park: false, OnStage: true, Harmony: false, RobotDied: false, CollectedBy: "george",
Emily Markova8cb91312024-02-02 12:30:37 -0800260 },
261 },
262 }
263 if len(expected.StatsList) != len(response.StatsList) {
264 t.Fatal("Expected ", expected, ", but got ", *response)
265 }
266 for i, match := range expected.StatsList {
267 if !reflect.DeepEqual(*match, *response.StatsList[i]) {
268 t.Fatal("Expected for stats", i, ":", *match, ", but got:", *response.StatsList[i])
269 }
270 }
271}
272
Emily Markova290147d2023-03-03 22:40:06 -0800273// Validates that we can request the 2023 stats.
274func TestRequest2023DataScouting(t *testing.T) {
275 db := MockDatabase{
276 stats2023: []db.Stats2023{
277 {
278 TeamNumber: "3634", MatchNumber: 1, SetNumber: 2,
279 CompLevel: "quals", StartingQuadrant: 3, LowCubesAuto: 10,
280 MiddleCubesAuto: 1, HighCubesAuto: 1, CubesDroppedAuto: 0,
281 LowConesAuto: 1, MiddleConesAuto: 2, HighConesAuto: 1,
282 ConesDroppedAuto: 0, LowCubes: 1, MiddleCubes: 1,
283 HighCubes: 2, CubesDropped: 1, LowCones: 1,
Filip Kujawa7a045e72023-04-13 08:41:09 -0700284 MiddleCones: 2, HighCones: 0, ConesDropped: 1, SuperchargedPieces: 0,
Filip Kujawa0b4b1e52023-04-15 14:05:40 -0700285 AvgCycle: 34, Mobility: false, DockedAuto: true, EngagedAuto: false,
Emily Markova63c63f62023-03-29 20:57:35 -0700286 BalanceAttemptAuto: false, Docked: false, Engaged: false,
287 BalanceAttempt: true, CollectedBy: "isaac",
Emily Markova290147d2023-03-03 22:40:06 -0800288 },
289 {
290 TeamNumber: "2343", MatchNumber: 1, SetNumber: 2,
291 CompLevel: "quals", StartingQuadrant: 1, LowCubesAuto: 0,
292 MiddleCubesAuto: 1, HighCubesAuto: 1, CubesDroppedAuto: 2,
293 LowConesAuto: 0, MiddleConesAuto: 0, HighConesAuto: 0,
294 ConesDroppedAuto: 1, LowCubes: 0, MiddleCubes: 0,
295 HighCubes: 1, CubesDropped: 0, LowCones: 0,
Filip Kujawa7a045e72023-04-13 08:41:09 -0700296 MiddleCones: 2, HighCones: 1, ConesDropped: 1, SuperchargedPieces: 0,
Filip Kujawa0b4b1e52023-04-15 14:05:40 -0700297 AvgCycle: 53, Mobility: false, DockedAuto: false, EngagedAuto: false,
Emily Markova63c63f62023-03-29 20:57:35 -0700298 BalanceAttemptAuto: true, Docked: false, Engaged: false,
299 BalanceAttempt: true, CollectedBy: "unknown",
Emily Markova290147d2023-03-03 22:40:06 -0800300 },
301 },
302 }
303 scoutingServer := server.NewScoutingServer()
304 HandleRequests(&db, scoutingServer)
305 scoutingServer.Start(8080)
306 defer scoutingServer.Stop()
307
308 builder := flatbuffers.NewBuilder(1024)
309 builder.Finish((&request_2023_data_scouting.Request2023DataScoutingT{}).Pack(builder))
310
311 response, err := debug.Request2023DataScouting("http://localhost:8080", builder.FinishedBytes())
312 if err != nil {
313 t.Fatal("Failed to request all matches: ", err)
314 }
315
316 expected := request_2023_data_scouting_response.Request2023DataScoutingResponseT{
317 StatsList: []*request_2023_data_scouting_response.Stats2023T{
318 {
319 TeamNumber: "3634", MatchNumber: 1, SetNumber: 2,
320 CompLevel: "quals", StartingQuadrant: 3, LowCubesAuto: 10,
321 MiddleCubesAuto: 1, HighCubesAuto: 1, CubesDroppedAuto: 0,
322 LowConesAuto: 1, MiddleConesAuto: 2, HighConesAuto: 1,
323 ConesDroppedAuto: 0, LowCubes: 1, MiddleCubes: 1,
324 HighCubes: 2, CubesDropped: 1, LowCones: 1,
Filip Kujawa7a045e72023-04-13 08:41:09 -0700325 MiddleCones: 2, HighCones: 0, ConesDropped: 1, SuperchargedPieces: 0,
Filip Kujawa0b4b1e52023-04-15 14:05:40 -0700326 AvgCycle: 34, Mobility: false, DockedAuto: true, EngagedAuto: false,
Emily Markova63c63f62023-03-29 20:57:35 -0700327 BalanceAttemptAuto: false, Docked: false, Engaged: false,
328 BalanceAttempt: true, CollectedBy: "isaac",
Emily Markova290147d2023-03-03 22:40:06 -0800329 },
330 {
331 TeamNumber: "2343", MatchNumber: 1, SetNumber: 2,
332 CompLevel: "quals", StartingQuadrant: 1, LowCubesAuto: 0,
333 MiddleCubesAuto: 1, HighCubesAuto: 1, CubesDroppedAuto: 2,
334 LowConesAuto: 0, MiddleConesAuto: 0, HighConesAuto: 0,
335 ConesDroppedAuto: 1, LowCubes: 0, MiddleCubes: 0,
336 HighCubes: 1, CubesDropped: 0, LowCones: 0,
Filip Kujawa7a045e72023-04-13 08:41:09 -0700337 MiddleCones: 2, HighCones: 1, ConesDropped: 1, SuperchargedPieces: 0,
Filip Kujawa0b4b1e52023-04-15 14:05:40 -0700338 AvgCycle: 53, Mobility: false, DockedAuto: false, EngagedAuto: false,
Emily Markova63c63f62023-03-29 20:57:35 -0700339 BalanceAttemptAuto: true, Docked: false, Engaged: false,
340 BalanceAttempt: true, CollectedBy: "unknown",
Emily Markova290147d2023-03-03 22:40:06 -0800341 },
342 },
343 }
344 if len(expected.StatsList) != len(response.StatsList) {
345 t.Fatal("Expected ", expected, ", but got ", *response)
346 }
347 for i, match := range expected.StatsList {
348 if !reflect.DeepEqual(*match, *response.StatsList[i]) {
349 t.Fatal("Expected for stats", i, ":", *match, ", but got:", *response.StatsList[i])
350 }
351 }
352}
353
Emily Markova8cb91312024-02-02 12:30:37 -0800354// Validates that we can request the 2024 stats.
355func TestConvertActionsToStat2024(t *testing.T) {
356 builder := flatbuffers.NewBuilder(1024)
357 builder.Finish((&submit_2024_actions.Submit2024ActionsT{
358 TeamNumber: "4244",
359 MatchNumber: 3,
360 SetNumber: 1,
361 CompLevel: "quals",
362 ActionsList: []*submit_2024_actions.ActionT{
363 {
364 ActionTaken: &submit_2024_actions.ActionTypeT{
365 Type: submit_2024_actions.ActionTypeStartMatchAction,
366 Value: &submit_2024_actions.StartMatchActionT{
367 Position: 2,
368 },
369 },
370 Timestamp: 0,
371 },
372 {
373 ActionTaken: &submit_2024_actions.ActionTypeT{
374 Type: submit_2024_actions.ActionTypePickupNoteAction,
375 Value: &submit_2024_actions.PickupNoteActionT{
376 Auto: true,
377 },
378 },
379 Timestamp: 400,
380 },
381 {
382 ActionTaken: &submit_2024_actions.ActionTypeT{
383 Type: submit_2024_actions.ActionTypePickupNoteAction,
384 Value: &submit_2024_actions.PickupNoteActionT{
385 Auto: true,
386 },
387 },
388 Timestamp: 800,
389 },
390 {
391 ActionTaken: &submit_2024_actions.ActionTypeT{
392 Type: submit_2024_actions.ActionTypePlaceNoteAction,
393 Value: &submit_2024_actions.PlaceNoteActionT{
394 ScoreType: submit_2024_actions.ScoreTypekAMP,
395 Auto: true,
396 },
397 },
398 Timestamp: 2000,
399 },
400 {
401 ActionTaken: &submit_2024_actions.ActionTypeT{
402 Type: submit_2024_actions.ActionTypeMobilityAction,
403 Value: &submit_2024_actions.MobilityActionT{
404 Mobility: true,
405 },
406 },
407 Timestamp: 2200,
408 },
409 {
410 ActionTaken: &submit_2024_actions.ActionTypeT{
Emily Markovadcadcb62024-02-03 13:07:17 -0800411 Type: submit_2024_actions.ActionTypePenaltyAction,
412 Value: &submit_2024_actions.PenaltyActionT{
413 Penalties: 5,
414 },
Emily Markova8cb91312024-02-02 12:30:37 -0800415 },
416 Timestamp: 2400,
417 },
418 {
419 ActionTaken: &submit_2024_actions.ActionTypeT{
420 Type: submit_2024_actions.ActionTypePickupNoteAction,
421 Value: &submit_2024_actions.PickupNoteActionT{
422 Auto: false,
423 },
424 },
425 Timestamp: 2800,
426 },
427 {
428 ActionTaken: &submit_2024_actions.ActionTypeT{
429 Type: submit_2024_actions.ActionTypePlaceNoteAction,
430 Value: &submit_2024_actions.PlaceNoteActionT{
431 ScoreType: submit_2024_actions.ScoreTypekAMP_AMPLIFIED,
432 Auto: false,
433 },
434 },
435 Timestamp: 3100,
436 },
437 {
438 ActionTaken: &submit_2024_actions.ActionTypeT{
439 Type: submit_2024_actions.ActionTypePickupNoteAction,
440 Value: &submit_2024_actions.PickupNoteActionT{
441 Auto: false,
442 },
443 },
Emily Markova040123c2024-02-27 09:48:37 -0800444 Timestamp: 3200,
445 },
446 {
447 ActionTaken: &submit_2024_actions.ActionTypeT{
448 Type: submit_2024_actions.ActionTypePlaceNoteAction,
449 Value: &submit_2024_actions.PlaceNoteActionT{
450 ScoreType: submit_2024_actions.ScoreTypekDROPPED,
451 Auto: false,
452 },
453 },
454 Timestamp: 3300,
455 },
456 {
457 ActionTaken: &submit_2024_actions.ActionTypeT{
458 Type: submit_2024_actions.ActionTypeRobotDeathAction,
459 Value: &submit_2024_actions.RobotDeathActionT{
460 RobotDead: true,
461 },
462 },
463 Timestamp: 3400,
464 },
465 {
466 ActionTaken: &submit_2024_actions.ActionTypeT{
467 Type: submit_2024_actions.ActionTypeRobotDeathAction,
468 Value: &submit_2024_actions.RobotDeathActionT{
469 RobotDead: false,
470 },
471 },
472 Timestamp: 3450,
473 },
474 {
475 ActionTaken: &submit_2024_actions.ActionTypeT{
476 Type: submit_2024_actions.ActionTypePickupNoteAction,
477 Value: &submit_2024_actions.PickupNoteActionT{
478 Auto: false,
479 },
480 },
Emily Markova8cb91312024-02-02 12:30:37 -0800481 Timestamp: 3500,
482 },
483 {
484 ActionTaken: &submit_2024_actions.ActionTypeT{
485 Type: submit_2024_actions.ActionTypePlaceNoteAction,
486 Value: &submit_2024_actions.PlaceNoteActionT{
487 ScoreType: submit_2024_actions.ScoreTypekSPEAKER_AMPLIFIED,
488 Auto: false,
489 },
490 },
491 Timestamp: 3900,
492 },
493 {
494 ActionTaken: &submit_2024_actions.ActionTypeT{
495 Type: submit_2024_actions.ActionTypeEndMatchAction,
496 Value: &submit_2024_actions.EndMatchActionT{
497 StageType: submit_2024_actions.StageTypekHARMONY,
498 TrapNote: false,
Emily Markova6079e2f2024-02-17 13:17:24 -0800499 Spotlight: false,
Emily Markova8cb91312024-02-02 12:30:37 -0800500 },
501 },
502 Timestamp: 4200,
503 },
504 },
505 PreScouting: false,
506 }).Pack(builder))
507
508 submit2024Actions := submit_2024_actions.GetRootAsSubmit2024Actions(builder.FinishedBytes(), 0)
509 response, err := ConvertActionsToStat2024(submit2024Actions)
510
511 if err != nil {
512 t.Fatal("Failed to convert actions to stats: ", err)
513 }
514
515 expected := db.Stats2024{
516 PreScouting: false, TeamNumber: "4244",
517 MatchNumber: 3, SetNumber: 1, CompLevel: "quals", StartingQuadrant: 2,
Emily Markova040123c2024-02-27 09:48:37 -0800518 SpeakerAuto: 0, AmpAuto: 1, NotesDroppedAuto: 0, MobilityAuto: true,
Emily Markova8cb91312024-02-02 12:30:37 -0800519 Speaker: 0, Amp: 0, SpeakerAmplified: 1, AmpAmplified: 1,
Emily Markova040123c2024-02-27 09:48:37 -0800520 NotesDropped: 1, Penalties: 5, TrapNote: false, Spotlight: false, AvgCycle: 633,
521 Park: false, OnStage: false, Harmony: true, RobotDied: true, CollectedBy: "",
Emily Markova8cb91312024-02-02 12:30:37 -0800522 }
523
524 if expected != response {
525 t.Fatal("Expected ", expected, ", but got ", response)
526 }
527}
528
Emily Markova1abe9782023-03-11 19:45:38 -0800529// Validates that we can request the 2023 stats.
530func TestConvertActionsToStat(t *testing.T) {
531 builder := flatbuffers.NewBuilder(1024)
532 builder.Finish((&submit_actions.SubmitActionsT{
533 TeamNumber: "4244",
534 MatchNumber: 3,
535 SetNumber: 1,
536 CompLevel: "quals",
Emily Markova1abe9782023-03-11 19:45:38 -0800537 ActionsList: []*submit_actions.ActionT{
538 {
539 ActionTaken: &submit_actions.ActionTypeT{
540 Type: submit_actions.ActionTypeStartMatchAction,
541 Value: &submit_actions.StartMatchActionT{
542 Position: 1,
543 },
544 },
545 Timestamp: 0,
546 },
547 {
548 ActionTaken: &submit_actions.ActionTypeT{
549 Type: submit_actions.ActionTypePickupObjectAction,
550 Value: &submit_actions.PickupObjectActionT{
551 ObjectType: submit_actions.ObjectTypekCube,
552 Auto: true,
553 },
554 },
555 Timestamp: 400,
556 },
557 {
558 ActionTaken: &submit_actions.ActionTypeT{
559 Type: submit_actions.ActionTypePickupObjectAction,
560 Value: &submit_actions.PickupObjectActionT{
561 ObjectType: submit_actions.ObjectTypekCube,
562 Auto: true,
563 },
564 },
565 Timestamp: 800,
566 },
567 {
568 ActionTaken: &submit_actions.ActionTypeT{
569 Type: submit_actions.ActionTypePlaceObjectAction,
570 Value: &submit_actions.PlaceObjectActionT{
571 ObjectType: submit_actions.ObjectTypekCube,
572 ScoreLevel: submit_actions.ScoreLevelkLow,
573 Auto: true,
574 },
575 },
576 Timestamp: 2000,
577 },
578 {
579 ActionTaken: &submit_actions.ActionTypeT{
Filip Kujawa0b4b1e52023-04-15 14:05:40 -0700580 Type: submit_actions.ActionTypeMobilityAction,
581 Value: &submit_actions.MobilityActionT{
582 Mobility: true,
583 },
584 },
585 Timestamp: 2200,
586 },
587 {
588 ActionTaken: &submit_actions.ActionTypeT{
Emily Markova46a69bf2023-03-22 20:45:52 -0700589 Type: submit_actions.ActionTypeAutoBalanceAction,
590 Value: &submit_actions.AutoBalanceActionT{
Emily Markova63c63f62023-03-29 20:57:35 -0700591 Docked: true,
592 Engaged: true,
593 BalanceAttempt: false,
Emily Markova46a69bf2023-03-22 20:45:52 -0700594 },
595 },
596 Timestamp: 2400,
597 },
598 {
599 ActionTaken: &submit_actions.ActionTypeT{
Emily Markova1abe9782023-03-11 19:45:38 -0800600 Type: submit_actions.ActionTypePickupObjectAction,
601 Value: &submit_actions.PickupObjectActionT{
602 ObjectType: submit_actions.ObjectTypekCone,
603 Auto: false,
604 },
605 },
606 Timestamp: 2800,
607 },
608 {
609 ActionTaken: &submit_actions.ActionTypeT{
610 Type: submit_actions.ActionTypePlaceObjectAction,
611 Value: &submit_actions.PlaceObjectActionT{
612 ObjectType: submit_actions.ObjectTypekCone,
613 ScoreLevel: submit_actions.ScoreLevelkHigh,
614 Auto: false,
615 },
616 },
617 Timestamp: 3100,
618 },
Emily Markova46a69bf2023-03-22 20:45:52 -0700619 {
620 ActionTaken: &submit_actions.ActionTypeT{
Filip Kujawa7a045e72023-04-13 08:41:09 -0700621 Type: submit_actions.ActionTypePickupObjectAction,
622 Value: &submit_actions.PickupObjectActionT{
623 ObjectType: submit_actions.ObjectTypekCube,
624 Auto: false,
625 },
626 },
627 Timestamp: 3500,
628 },
629 {
630 ActionTaken: &submit_actions.ActionTypeT{
631 Type: submit_actions.ActionTypePlaceObjectAction,
632 Value: &submit_actions.PlaceObjectActionT{
633 ObjectType: submit_actions.ObjectTypekCube,
634 ScoreLevel: submit_actions.ScoreLevelkSupercharged,
635 Auto: false,
636 },
637 },
638 Timestamp: 3900,
639 },
640 {
641 ActionTaken: &submit_actions.ActionTypeT{
Emily Markova46a69bf2023-03-22 20:45:52 -0700642 Type: submit_actions.ActionTypeEndMatchAction,
643 Value: &submit_actions.EndMatchActionT{
Emily Markova63c63f62023-03-29 20:57:35 -0700644 Docked: true,
645 Engaged: false,
646 BalanceAttempt: true,
Emily Markova46a69bf2023-03-22 20:45:52 -0700647 },
648 },
Filip Kujawa7a045e72023-04-13 08:41:09 -0700649 Timestamp: 4200,
Emily Markova46a69bf2023-03-22 20:45:52 -0700650 },
Emily Markova1abe9782023-03-11 19:45:38 -0800651 },
Philipp Schrader4b489222023-04-15 16:40:16 -0700652 PreScouting: false,
Emily Markova1abe9782023-03-11 19:45:38 -0800653 }).Pack(builder))
654
655 submitActions := submit_actions.GetRootAsSubmitActions(builder.FinishedBytes(), 0)
656 response, err := ConvertActionsToStat(submitActions)
657
658 if err != nil {
659 t.Fatal("Failed to convert actions to stats: ", err)
660 }
661
662 expected := db.Stats2023{
Philipp Schrader4b489222023-04-15 16:40:16 -0700663 PreScouting: false,
664 TeamNumber: "4244", MatchNumber: 3, SetNumber: 1,
Emily Markova1abe9782023-03-11 19:45:38 -0800665 CompLevel: "quals", StartingQuadrant: 1, LowCubesAuto: 1,
666 MiddleCubesAuto: 0, HighCubesAuto: 0, CubesDroppedAuto: 1,
667 LowConesAuto: 0, MiddleConesAuto: 0, HighConesAuto: 0,
668 ConesDroppedAuto: 0, LowCubes: 0, MiddleCubes: 0,
669 HighCubes: 0, CubesDropped: 0, LowCones: 0,
Filip Kujawa7a045e72023-04-13 08:41:09 -0700670 MiddleCones: 0, HighCones: 1, ConesDropped: 0, SuperchargedPieces: 1,
Filip Kujawa0b4b1e52023-04-15 14:05:40 -0700671 AvgCycle: 950, Mobility: true, DockedAuto: true, EngagedAuto: true,
Emily Markova63c63f62023-03-29 20:57:35 -0700672 BalanceAttemptAuto: false, Docked: true, Engaged: false,
Philipp Schradere11114f2023-04-15 17:04:25 -0700673 BalanceAttempt: true, CollectedBy: "",
Emily Markova1abe9782023-03-11 19:45:38 -0800674 }
675
676 if expected != response {
677 t.Fatal("Expected ", expected, ", but got ", response)
678 }
679}
680
Alex Perry81f96ba2022-03-13 18:26:19 -0700681func TestSubmitNotes(t *testing.T) {
682 database := MockDatabase{}
683 scoutingServer := server.NewScoutingServer()
Philipp Schrader43c730b2023-02-26 20:27:44 -0800684 HandleRequests(&database, scoutingServer)
Alex Perry81f96ba2022-03-13 18:26:19 -0700685 scoutingServer.Start(8080)
686 defer scoutingServer.Stop()
687
688 builder := flatbuffers.NewBuilder(1024)
689 builder.Finish((&submit_notes.SubmitNotesT{
Emily Markovae68b7632023-12-30 14:17:55 -0800690 Team: "971",
Filip Kujawa7ddd5652023-03-07 19:56:15 -0800691 Notes: "Notes",
692 GoodDriving: true,
693 BadDriving: false,
Filip Kujawa11dc4c92023-04-13 08:55:43 -0700694 SolidPlacing: true,
Filip Kujawa7ddd5652023-03-07 19:56:15 -0800695 SketchyPlacing: false,
696 GoodDefense: true,
697 BadDefense: false,
698 EasilyDefended: true,
Alex Perry81f96ba2022-03-13 18:26:19 -0700699 }).Pack(builder))
700
701 _, err := debug.SubmitNotes("http://localhost:8080", builder.FinishedBytes())
702 if err != nil {
703 t.Fatal("Failed to submit notes: ", err)
704 }
705
706 expected := []db.NotesData{
Filip Kujawaf947cb42022-11-21 10:00:30 -0800707 {
Emily Markovae68b7632023-12-30 14:17:55 -0800708 TeamNumber: "971",
Filip Kujawa7ddd5652023-03-07 19:56:15 -0800709 Notes: "Notes",
710 GoodDriving: true,
711 BadDriving: false,
Filip Kujawa11dc4c92023-04-13 08:55:43 -0700712 SolidPlacing: true,
Filip Kujawa7ddd5652023-03-07 19:56:15 -0800713 SketchyPlacing: false,
714 GoodDefense: true,
715 BadDefense: false,
716 EasilyDefended: true,
Filip Kujawaf947cb42022-11-21 10:00:30 -0800717 },
Alex Perry81f96ba2022-03-13 18:26:19 -0700718 }
719
720 if !reflect.DeepEqual(database.notes, expected) {
721 t.Fatal("Submitted notes did not match", expected, database.notes)
722 }
723}
724
725func TestRequestNotes(t *testing.T) {
726 database := MockDatabase{
727 notes: []db.NotesData{{
Emily Markovae68b7632023-12-30 14:17:55 -0800728 TeamNumber: "971A",
Filip Kujawa7ddd5652023-03-07 19:56:15 -0800729 Notes: "Notes",
730 GoodDriving: true,
731 BadDriving: false,
Filip Kujawa11dc4c92023-04-13 08:55:43 -0700732 SolidPlacing: true,
Filip Kujawa7ddd5652023-03-07 19:56:15 -0800733 SketchyPlacing: false,
734 GoodDefense: true,
735 BadDefense: false,
736 EasilyDefended: true,
Alex Perry81f96ba2022-03-13 18:26:19 -0700737 }},
738 }
739 scoutingServer := server.NewScoutingServer()
Philipp Schrader43c730b2023-02-26 20:27:44 -0800740 HandleRequests(&database, scoutingServer)
Alex Perry81f96ba2022-03-13 18:26:19 -0700741 scoutingServer.Start(8080)
742 defer scoutingServer.Stop()
743
744 builder := flatbuffers.NewBuilder(1024)
745 builder.Finish((&request_notes_for_team.RequestNotesForTeamT{
Emily Markovae68b7632023-12-30 14:17:55 -0800746 Team: "971A",
Alex Perry81f96ba2022-03-13 18:26:19 -0700747 }).Pack(builder))
748 response, err := debug.RequestNotes("http://localhost:8080", builder.FinishedBytes())
749 if err != nil {
750 t.Fatal("Failed to submit notes: ", err)
751 }
752
753 if response.Notes[0].Data != "Notes" {
754 t.Fatal("requested notes did not match", response)
755 }
756}
757
Emily Markovafaecfe12023-07-01 12:40:03 -0700758func TestSubmitPitImage(t *testing.T) {
759 database := MockDatabase{}
760 scoutingServer := server.NewScoutingServer()
761 HandleRequests(&database, scoutingServer)
762 scoutingServer.Start(8080)
763 defer scoutingServer.Stop()
764
765 builder := flatbuffers.NewBuilder(1024)
766 builder.Finish((&submit_pit_image.SubmitPitImageT{
767 TeamNumber: "483A", ImagePath: "483Arobot.jpg",
768 ImageData: []byte{12, 43, 54, 34, 98},
769 }).Pack(builder))
770
771 _, err := debug.SubmitPitImage("http://localhost:8080", builder.FinishedBytes())
772 if err != nil {
773 t.Fatal("Failed to submit pit image: ", err)
774 }
775
776 expected := []db.PitImage{
777 {
778 TeamNumber: "483A", CheckSum: "177d9dc52bc25f391232e82521259c378964c068832a9178d73448ba4ac5e0b1",
779 ImagePath: "483Arobot.jpg", ImageData: []byte{12, 43, 54, 34, 98},
780 },
781 }
782
783 if !reflect.DeepEqual(database.images, expected) {
784 t.Fatal("Submitted image did not match", expected, database.images)
785 }
786}
787
788func TestRequestPitImages(t *testing.T) {
789 db := MockDatabase{
790 images: []db.PitImage{
791 {
792 TeamNumber: "932", ImagePath: "pitimage.jpg",
793 ImageData: []byte{3, 34, 44, 65}, CheckSum: "abcdf",
794 },
795 {
796 TeamNumber: "234", ImagePath: "234robot.png",
797 ImageData: []byte{64, 54, 21, 21, 76, 32}, CheckSum: "egrfd",
798 },
799 {
800 TeamNumber: "93A", ImagePath: "abcd.jpg",
801 ImageData: []byte{92, 94, 10, 30, 57, 32, 32}, CheckSum: "rgegfd",
802 },
803 },
804 }
805
806 scoutingServer := server.NewScoutingServer()
807 HandleRequests(&db, scoutingServer)
808 scoutingServer.Start(8080)
809 defer scoutingServer.Stop()
810
811 builder := flatbuffers.NewBuilder(1024)
812 builder.Finish((&request_pit_images.RequestPitImagesT{"932"}).Pack(builder))
813
814 response, err := debug.RequestPitImages("http://localhost:8080", builder.FinishedBytes())
815 if err != nil {
816 t.Fatal("Failed to request pit images: ", err)
817 }
818
819 expected := request_pit_images_response.RequestPitImagesResponseT{
820 PitImageList: []*request_pit_images_response.PitImageT{
821 {
822 TeamNumber: "932", ImagePath: "pitimage.jpg", CheckSum: "abcdf",
823 },
824 },
825 }
826
827 if len(expected.PitImageList) != len(response.PitImageList) {
828 t.Fatal("Expected ", expected, ", but got ", *response)
829 }
830
831 for i, pit_image := range expected.PitImageList {
832 if !reflect.DeepEqual(*pit_image, *response.PitImageList[i]) {
833 t.Fatal("Expected for pit image", i, ":", *pit_image, ", but got:", *response.PitImageList[i])
834 }
835 }
836}
837
Emily Markova8e39f452023-12-23 12:17:30 -0800838func TestRequestAllPitImages(t *testing.T) {
839 db := MockDatabase{
840 images: []db.PitImage{
841 {
842 TeamNumber: "32", ImagePath: "pitimage.jpg",
843 ImageData: []byte{3, 43, 44, 32}, CheckSum: "cdhrj",
844 },
845 {
846 TeamNumber: "231", ImagePath: "232robot.png",
847 ImageData: []byte{64, 54, 54, 21, 76, 32}, CheckSum: "rgre",
848 },
849 {
850 TeamNumber: "90", ImagePath: "abcd.jpg",
851 ImageData: []byte{92, 94, 10, 30, 57, 32, 32}, CheckSum: "erfer",
852 },
853 },
854 }
855
856 scoutingServer := server.NewScoutingServer()
857 HandleRequests(&db, scoutingServer)
858 scoutingServer.Start(8080)
859 defer scoutingServer.Stop()
860
861 builder := flatbuffers.NewBuilder(1024)
862 builder.Finish((&request_all_pit_images.RequestAllPitImagesT{}).Pack(builder))
863
864 response, err := debug.RequestAllPitImages("http://localhost:8080", builder.FinishedBytes())
865 if err != nil {
866 t.Fatal("Failed to request pit images: ", err)
867 }
868
869 expected := request_all_pit_images_response.RequestAllPitImagesResponseT{
870 PitImageList: []*request_all_pit_images_response.PitImageT{
871 {
872 TeamNumber: "32", ImagePath: "pitimage.jpg", CheckSum: "cdhrj",
873 },
874 {
875 TeamNumber: "231", ImagePath: "232robot.png", CheckSum: "rgre",
876 },
877 {
878 TeamNumber: "90", ImagePath: "abcd.jpg", CheckSum: "erfer",
879 },
880 },
881 }
882
883 if len(expected.PitImageList) != len(response.PitImageList) {
884 t.Fatal("Expected ", expected, ", but got ", *response)
885 }
886
887 for i, pit_image := range expected.PitImageList {
888 if !reflect.DeepEqual(*pit_image, *response.PitImageList[i]) {
889 t.Fatal("Expected for pit image", i, ":", *pit_image, ", but got:", *response.PitImageList[i])
890 }
891 }
892}
893
Milo Lin1d59f0c2022-06-22 20:30:58 -0700894func TestRequestShiftSchedule(t *testing.T) {
895 db := MockDatabase{
896 shiftSchedule: []db.Shift{
897 {
898 MatchNumber: 1,
899 R1scouter: "Bob",
900 R2scouter: "James",
901 R3scouter: "Robert",
902 B1scouter: "Alice",
903 B2scouter: "Mary",
904 B3scouter: "Patricia",
905 },
906 {
907 MatchNumber: 2,
908 R1scouter: "Liam",
909 R2scouter: "Noah",
910 R3scouter: "Oliver",
911 B1scouter: "Emma",
912 B2scouter: "Charlotte",
913 B3scouter: "Amelia",
914 },
915 },
916 }
917 scoutingServer := server.NewScoutingServer()
Philipp Schrader43c730b2023-02-26 20:27:44 -0800918 HandleRequests(&db, scoutingServer)
Milo Lin1d59f0c2022-06-22 20:30:58 -0700919 scoutingServer.Start(8080)
920 defer scoutingServer.Stop()
921
922 builder := flatbuffers.NewBuilder(1024)
923 builder.Finish((&request_shift_schedule.RequestShiftScheduleT{}).Pack(builder))
924
925 response, err := debug.RequestShiftSchedule("http://localhost:8080", builder.FinishedBytes())
926 if err != nil {
927 t.Fatal("Failed to request shift schedule: ", err)
928 }
929
930 expected := request_shift_schedule_response.RequestShiftScheduleResponseT{
931 ShiftSchedule: []*request_shift_schedule_response.MatchAssignmentT{
932 {
933 MatchNumber: 1,
Philipp Schrader2ff455b2023-05-03 22:11:50 -0700934 R1Scouter: "Bob",
935 R2Scouter: "James",
936 R3Scouter: "Robert",
937 B1Scouter: "Alice",
938 B2Scouter: "Mary",
939 B3Scouter: "Patricia",
Milo Lin1d59f0c2022-06-22 20:30:58 -0700940 },
941 {
942 MatchNumber: 2,
Philipp Schrader2ff455b2023-05-03 22:11:50 -0700943 R1Scouter: "Liam",
944 R2Scouter: "Noah",
945 R3Scouter: "Oliver",
946 B1Scouter: "Emma",
947 B2Scouter: "Charlotte",
948 B3Scouter: "Amelia",
Milo Lin1d59f0c2022-06-22 20:30:58 -0700949 },
950 },
951 }
952 if len(expected.ShiftSchedule) != len(response.ShiftSchedule) {
953 t.Fatal("Expected ", expected, ", but got ", *response)
954 }
955 for i, match := range expected.ShiftSchedule {
956 if !reflect.DeepEqual(*match, *response.ShiftSchedule[i]) {
957 t.Fatal("Expected for shift schedule", i, ":", *match, ", but got:", *response.ShiftSchedule[i])
958 }
959 }
960}
961
962func TestSubmitShiftSchedule(t *testing.T) {
963 database := MockDatabase{}
964 scoutingServer := server.NewScoutingServer()
Philipp Schrader43c730b2023-02-26 20:27:44 -0800965 HandleRequests(&database, scoutingServer)
Milo Lin1d59f0c2022-06-22 20:30:58 -0700966 scoutingServer.Start(8080)
967 defer scoutingServer.Stop()
968
969 builder := flatbuffers.NewBuilder(1024)
970 builder.Finish((&submit_shift_schedule.SubmitShiftScheduleT{
971 ShiftSchedule: []*submit_shift_schedule.MatchAssignmentT{
972 {MatchNumber: 1,
Philipp Schrader2ff455b2023-05-03 22:11:50 -0700973 R1Scouter: "Bob",
974 R2Scouter: "James",
975 R3Scouter: "Robert",
976 B1Scouter: "Alice",
977 B2Scouter: "Mary",
978 B3Scouter: "Patricia"},
Milo Lin1d59f0c2022-06-22 20:30:58 -0700979 },
980 }).Pack(builder))
981
982 _, err := debug.SubmitShiftSchedule("http://localhost:8080", builder.FinishedBytes())
983 if err != nil {
984 t.Fatal("Failed to submit shift schedule: ", err)
985 }
986
987 expected := []db.Shift{
988 {MatchNumber: 1,
989 R1scouter: "Bob",
990 R2scouter: "James",
991 R3scouter: "Robert",
992 B1scouter: "Alice",
993 B2scouter: "Mary",
994 B3scouter: "Patricia"},
995 }
996 if !reflect.DeepEqual(expected, database.shiftSchedule) {
997 t.Fatal("Expected ", expected, ", but got:", database.shiftSchedule)
998 }
999}
1000
Filip Kujawa210a03b2022-11-24 14:41:11 -08001001func TestSubmitDriverRanking(t *testing.T) {
1002 database := MockDatabase{}
1003 scoutingServer := server.NewScoutingServer()
Philipp Schrader43c730b2023-02-26 20:27:44 -08001004 HandleRequests(&database, scoutingServer)
Filip Kujawa210a03b2022-11-24 14:41:11 -08001005 scoutingServer.Start(8080)
1006 defer scoutingServer.Stop()
1007
1008 builder := flatbuffers.NewBuilder(1024)
1009 builder.Finish((&submit_driver_ranking.SubmitDriverRankingT{
1010 MatchNumber: 36,
Emily Markovae68b7632023-12-30 14:17:55 -08001011 Rank1: "1234",
1012 Rank2: "1235",
1013 Rank3: "1236",
Filip Kujawa210a03b2022-11-24 14:41:11 -08001014 }).Pack(builder))
1015
1016 _, err := debug.SubmitDriverRanking("http://localhost:8080", builder.FinishedBytes())
1017 if err != nil {
1018 t.Fatal("Failed to submit driver ranking: ", err)
1019 }
1020
1021 expected := []db.DriverRankingData{
Emily Markovae68b7632023-12-30 14:17:55 -08001022 {MatchNumber: 36, Rank1: "1234", Rank2: "1235", Rank3: "1236"},
Filip Kujawa210a03b2022-11-24 14:41:11 -08001023 }
1024
1025 if !reflect.DeepEqual(database.driver_ranking, expected) {
1026 t.Fatal("Submitted notes did not match", expected, database.notes)
1027 }
1028}
1029
Filip Kujawaf882e022022-12-14 13:14:08 -08001030// Validates that we can request the driver rankings.
1031func TestRequestDriverRankings(t *testing.T) {
1032 db := MockDatabase{
1033 driver_ranking: []db.DriverRankingData{
1034 {
1035 MatchNumber: 36,
Emily Markovae68b7632023-12-30 14:17:55 -08001036 Rank1: "1234",
1037 Rank2: "1235",
1038 Rank3: "1236",
Filip Kujawaf882e022022-12-14 13:14:08 -08001039 },
1040 {
1041 MatchNumber: 36,
Emily Markovae68b7632023-12-30 14:17:55 -08001042 Rank1: "101",
1043 Rank2: "202",
1044 Rank3: "303",
Filip Kujawaf882e022022-12-14 13:14:08 -08001045 },
1046 },
1047 }
1048 scoutingServer := server.NewScoutingServer()
Philipp Schrader43c730b2023-02-26 20:27:44 -08001049 HandleRequests(&db, scoutingServer)
Filip Kujawaf882e022022-12-14 13:14:08 -08001050 scoutingServer.Start(8080)
1051 defer scoutingServer.Stop()
1052
1053 builder := flatbuffers.NewBuilder(1024)
1054 builder.Finish((&request_all_driver_rankings.RequestAllDriverRankingsT{}).Pack(builder))
1055
1056 response, err := debug.RequestAllDriverRankings("http://localhost:8080", builder.FinishedBytes())
1057 if err != nil {
1058 t.Fatal("Failed to request all driver rankings: ", err)
1059 }
1060
1061 expected := request_all_driver_rankings_response.RequestAllDriverRankingsResponseT{
1062 DriverRankingList: []*request_all_driver_rankings_response.RankingT{
1063 {
1064 MatchNumber: 36,
Emily Markovae68b7632023-12-30 14:17:55 -08001065 Rank1: "1234",
1066 Rank2: "1235",
1067 Rank3: "1236",
Filip Kujawaf882e022022-12-14 13:14:08 -08001068 },
1069 {
1070 MatchNumber: 36,
Emily Markovae68b7632023-12-30 14:17:55 -08001071 Rank1: "101",
1072 Rank2: "202",
1073 Rank3: "303",
Filip Kujawaf882e022022-12-14 13:14:08 -08001074 },
1075 },
1076 }
1077 if len(expected.DriverRankingList) != len(response.DriverRankingList) {
1078 t.Fatal("Expected ", expected, ", but got ", *response)
1079 }
1080 for i, match := range expected.DriverRankingList {
1081 if !reflect.DeepEqual(*match, *response.DriverRankingList[i]) {
1082 t.Fatal("Expected for driver ranking", i, ":", *match, ", but got:", *response.DriverRankingList[i])
1083 }
1084 }
1085}
1086
1087// Validates that we can request all notes.
1088func TestRequestAllNotes(t *testing.T) {
1089 db := MockDatabase{
1090 notes: []db.NotesData{
1091 {
Emily Markovae68b7632023-12-30 14:17:55 -08001092 TeamNumber: "971",
Filip Kujawa7ddd5652023-03-07 19:56:15 -08001093 Notes: "Notes",
1094 GoodDriving: true,
1095 BadDriving: false,
Filip Kujawa11dc4c92023-04-13 08:55:43 -07001096 SolidPlacing: true,
Filip Kujawa7ddd5652023-03-07 19:56:15 -08001097 SketchyPlacing: false,
1098 GoodDefense: true,
1099 BadDefense: false,
1100 EasilyDefended: false,
Filip Kujawaf882e022022-12-14 13:14:08 -08001101 },
1102 {
Emily Markovae68b7632023-12-30 14:17:55 -08001103 TeamNumber: "972",
Filip Kujawa7ddd5652023-03-07 19:56:15 -08001104 Notes: "More Notes",
1105 GoodDriving: false,
1106 BadDriving: false,
Filip Kujawa11dc4c92023-04-13 08:55:43 -07001107 SolidPlacing: false,
Filip Kujawa7ddd5652023-03-07 19:56:15 -08001108 SketchyPlacing: true,
1109 GoodDefense: false,
1110 BadDefense: true,
1111 EasilyDefended: false,
Filip Kujawaf882e022022-12-14 13:14:08 -08001112 },
1113 },
1114 }
1115 scoutingServer := server.NewScoutingServer()
Philipp Schrader43c730b2023-02-26 20:27:44 -08001116 HandleRequests(&db, scoutingServer)
Filip Kujawaf882e022022-12-14 13:14:08 -08001117 scoutingServer.Start(8080)
1118 defer scoutingServer.Stop()
1119
1120 builder := flatbuffers.NewBuilder(1024)
1121 builder.Finish((&request_all_notes.RequestAllNotesT{}).Pack(builder))
1122
1123 response, err := debug.RequestAllNotes("http://localhost:8080", builder.FinishedBytes())
1124 if err != nil {
1125 t.Fatal("Failed to request all notes: ", err)
1126 }
1127
1128 expected := request_all_notes_response.RequestAllNotesResponseT{
1129 NoteList: []*request_all_notes_response.NoteT{
1130 {
Emily Markovae68b7632023-12-30 14:17:55 -08001131 Team: "971",
Filip Kujawa7ddd5652023-03-07 19:56:15 -08001132 Notes: "Notes",
1133 GoodDriving: true,
1134 BadDriving: false,
Filip Kujawa11dc4c92023-04-13 08:55:43 -07001135 SolidPlacing: true,
Filip Kujawa7ddd5652023-03-07 19:56:15 -08001136 SketchyPlacing: false,
1137 GoodDefense: true,
1138 BadDefense: false,
1139 EasilyDefended: false,
Filip Kujawaf882e022022-12-14 13:14:08 -08001140 },
1141 {
Emily Markovae68b7632023-12-30 14:17:55 -08001142 Team: "972",
Filip Kujawa7ddd5652023-03-07 19:56:15 -08001143 Notes: "More Notes",
1144 GoodDriving: false,
1145 BadDriving: false,
Filip Kujawa11dc4c92023-04-13 08:55:43 -07001146 SolidPlacing: false,
Filip Kujawa7ddd5652023-03-07 19:56:15 -08001147 SketchyPlacing: true,
1148 GoodDefense: false,
1149 BadDefense: true,
1150 EasilyDefended: false,
Filip Kujawaf882e022022-12-14 13:14:08 -08001151 },
1152 },
1153 }
1154 if len(expected.NoteList) != len(response.NoteList) {
1155 t.Fatal("Expected ", expected, ", but got ", *response)
1156 }
1157 for i, note := range expected.NoteList {
1158 if !reflect.DeepEqual(*note, *response.NoteList[i]) {
1159 t.Fatal("Expected for note", i, ":", *note, ", but got:", *response.NoteList[i])
1160 }
1161 }
1162}
1163
Sabina Leaver9b4eb312023-02-20 19:58:17 -08001164func packAction(action *submit_actions.ActionT) []byte {
1165 builder := flatbuffers.NewBuilder(50 * 1024)
1166 builder.Finish((action).Pack(builder))
1167 return (builder.FinishedBytes())
1168}
1169
Emily Markova8cb91312024-02-02 12:30:37 -08001170func TestAddingActions2024(t *testing.T) {
1171 database := MockDatabase{}
1172 scoutingServer := server.NewScoutingServer()
1173 HandleRequests(&database, scoutingServer)
1174 scoutingServer.Start(8080)
1175 defer scoutingServer.Stop()
1176
1177 builder := flatbuffers.NewBuilder(1024)
1178 builder.Finish((&submit_2024_actions.Submit2024ActionsT{
1179 TeamNumber: "3421",
1180 MatchNumber: 2,
1181 SetNumber: 1,
1182 CompLevel: "quals",
1183 ActionsList: []*submit_2024_actions.ActionT{
1184 {
1185 ActionTaken: &submit_2024_actions.ActionTypeT{
1186 Type: submit_2024_actions.ActionTypePickupNoteAction,
1187 Value: &submit_2024_actions.PickupNoteActionT{
1188 Auto: true,
1189 },
1190 },
1191 Timestamp: 1800,
1192 },
1193 {
1194 ActionTaken: &submit_2024_actions.ActionTypeT{
1195 Type: submit_2024_actions.ActionTypePlaceNoteAction,
1196 Value: &submit_2024_actions.PlaceNoteActionT{
1197 ScoreType: submit_2024_actions.ScoreTypekSPEAKER,
1198 Auto: false,
1199 },
1200 },
1201 Timestamp: 2500,
1202 },
1203 },
1204 PreScouting: true,
1205 }).Pack(builder))
1206
1207 _, err := debug.Submit2024Actions("http://localhost:8080", builder.FinishedBytes())
1208 if err != nil {
1209 t.Fatal("Failed to submit actions: ", err)
1210 }
1211
1212 expectedActions := []db.Action{
1213 {
1214 PreScouting: true,
1215 TeamNumber: "3421",
1216 MatchNumber: 2,
1217 SetNumber: 1,
1218 CompLevel: "quals",
1219 CollectedBy: "debug_cli",
1220 CompletedAction: []byte{},
1221 Timestamp: 1800,
1222 },
1223 {
1224 PreScouting: true,
1225 TeamNumber: "3421",
1226 MatchNumber: 2,
1227 SetNumber: 1,
1228 CompLevel: "quals",
1229 CollectedBy: "debug_cli",
1230 CompletedAction: []byte{},
1231 Timestamp: 2500,
1232 },
1233 }
1234
1235 expectedStats := []db.Stats2024{
1236 db.Stats2024{
1237 PreScouting: true, TeamNumber: "3421",
1238 MatchNumber: 2, SetNumber: 1, CompLevel: "quals", StartingQuadrant: 0,
1239 SpeakerAuto: 0, AmpAuto: 0, NotesDroppedAuto: 0, MobilityAuto: false,
1240 Speaker: 1, Amp: 0, SpeakerAmplified: 0, AmpAmplified: 0,
Emily Markova6079e2f2024-02-17 13:17:24 -08001241 NotesDropped: 0, Penalties: 0, TrapNote: false, Spotlight: false, AvgCycle: 0,
Emily Markova040123c2024-02-27 09:48:37 -08001242 Park: false, OnStage: false, Harmony: false, RobotDied: false, CollectedBy: "debug_cli",
Emily Markova8cb91312024-02-02 12:30:37 -08001243 },
1244 }
1245
1246 if !reflect.DeepEqual(expectedActions, database.actions) {
1247 t.Fatal("Expected ", expectedActions, ", but got:", database.actions)
1248 }
1249 if !reflect.DeepEqual(expectedStats, database.stats2024) {
1250 t.Fatal("Expected ", expectedStats, ", but got:", database.stats2024)
1251 }
1252}
1253
Sabina Leaver9b4eb312023-02-20 19:58:17 -08001254func TestAddingActions(t *testing.T) {
1255 database := MockDatabase{}
1256 scoutingServer := server.NewScoutingServer()
1257 HandleRequests(&database, scoutingServer)
1258 scoutingServer.Start(8080)
1259 defer scoutingServer.Stop()
1260
1261 builder := flatbuffers.NewBuilder(1024)
1262 builder.Finish((&submit_actions.SubmitActionsT{
1263 TeamNumber: "1234",
1264 MatchNumber: 4,
1265 SetNumber: 1,
1266 CompLevel: "qual",
1267 ActionsList: []*submit_actions.ActionT{
1268 {
1269 ActionTaken: &submit_actions.ActionTypeT{
1270 Type: submit_actions.ActionTypePickupObjectAction,
1271 Value: &submit_actions.PickupObjectActionT{
1272 ObjectType: submit_actions.ObjectTypekCube,
1273 Auto: true,
1274 },
1275 },
1276 Timestamp: 2400,
1277 },
1278 {
1279 ActionTaken: &submit_actions.ActionTypeT{
1280 Type: submit_actions.ActionTypePlaceObjectAction,
1281 Value: &submit_actions.PlaceObjectActionT{
1282 ObjectType: submit_actions.ObjectTypekCube,
1283 ScoreLevel: submit_actions.ScoreLevelkLow,
1284 Auto: false,
1285 },
1286 },
1287 Timestamp: 1009,
1288 },
1289 },
Philipp Schrader4b489222023-04-15 16:40:16 -07001290 PreScouting: true,
Sabina Leaver9b4eb312023-02-20 19:58:17 -08001291 }).Pack(builder))
1292
1293 _, err := debug.SubmitActions("http://localhost:8080", builder.FinishedBytes())
1294 if err != nil {
1295 t.Fatal("Failed to submit actions: ", err)
1296 }
1297
1298 // Make sure that the data made it into the database.
1299 // TODO: Add this back when we figure out how to add the serialized action into the database.
1300
1301 /* expectedActionsT := []*submit_actions.ActionT{
1302 {
1303 ActionTaken: &submit_actions.ActionTypeT{
1304 Type: submit_actions.ActionTypePickupObjectAction,
1305 Value: &submit_actions.PickupObjectActionT{
1306 ObjectType: submit_actions.ObjectTypekCube,
1307 Auto: true,
1308 },
1309 },
1310 Timestamp: 2400,
1311 },
1312 {
1313 ActionTaken: &submit_actions.ActionTypeT{
1314 Type: submit_actions.ActionTypePlaceObjectAction,
1315 Value: &submit_actions.PlaceObjectActionT{
1316 ObjectType: submit_actions.ObjectTypekCube,
1317 ScoreLevel: submit_actions.ScoreLevelkLow,
1318 Auto: false,
1319 },
1320 },
1321 Timestamp: 1009,
1322 },
1323 } */
1324
1325 expectedActions := []db.Action{
1326 {
Philipp Schrader4b489222023-04-15 16:40:16 -07001327 PreScouting: true,
Sabina Leaver9b4eb312023-02-20 19:58:17 -08001328 TeamNumber: "1234",
1329 MatchNumber: 4,
1330 SetNumber: 1,
1331 CompLevel: "qual",
1332 CollectedBy: "debug_cli",
1333 CompletedAction: []byte{},
Philipp Schrader670a1c82023-05-17 19:42:43 -07001334 Timestamp: 2400,
Sabina Leaver9b4eb312023-02-20 19:58:17 -08001335 },
1336 {
Philipp Schrader4b489222023-04-15 16:40:16 -07001337 PreScouting: true,
Sabina Leaver9b4eb312023-02-20 19:58:17 -08001338 TeamNumber: "1234",
1339 MatchNumber: 4,
1340 SetNumber: 1,
1341 CompLevel: "qual",
1342 CollectedBy: "debug_cli",
1343 CompletedAction: []byte{},
Philipp Schrader670a1c82023-05-17 19:42:43 -07001344 Timestamp: 1009,
Sabina Leaver9b4eb312023-02-20 19:58:17 -08001345 },
1346 }
1347
Philipp Schradere11114f2023-04-15 17:04:25 -07001348 expectedStats := []db.Stats2023{
1349 db.Stats2023{
1350 PreScouting: true,
1351 TeamNumber: "1234", MatchNumber: 4, SetNumber: 1,
1352 CompLevel: "qual", StartingQuadrant: 0, LowCubesAuto: 0,
1353 MiddleCubesAuto: 0, HighCubesAuto: 0, CubesDroppedAuto: 0,
1354 LowConesAuto: 0, MiddleConesAuto: 0, HighConesAuto: 0,
1355 ConesDroppedAuto: 0, LowCubes: 1, MiddleCubes: 0,
1356 HighCubes: 0, CubesDropped: 0, LowCones: 0,
1357 MiddleCones: 0, HighCones: 0, ConesDropped: 0, SuperchargedPieces: 0,
1358 AvgCycle: 0, Mobility: false, DockedAuto: false, EngagedAuto: false,
1359 BalanceAttemptAuto: false, Docked: false, Engaged: false,
1360 BalanceAttempt: false, CollectedBy: "debug_cli",
1361 },
1362 }
1363
Sabina Leaver9b4eb312023-02-20 19:58:17 -08001364 if !reflect.DeepEqual(expectedActions, database.actions) {
1365 t.Fatal("Expected ", expectedActions, ", but got:", database.actions)
1366 }
Philipp Schradere11114f2023-04-15 17:04:25 -07001367 if !reflect.DeepEqual(expectedStats, database.stats2023) {
1368 t.Fatal("Expected ", expectedStats, ", but got:", database.stats2023)
1369 }
Sabina Leaver9b4eb312023-02-20 19:58:17 -08001370}
1371
Filip Kujawac1ded372023-05-27 14:33:43 -07001372// Validates that we can delete stats.
1373func TestDeleteFromStats(t *testing.T) {
1374 database := MockDatabase{
1375 stats2023: []db.Stats2023{
1376 {
1377 TeamNumber: "3634", MatchNumber: 1, SetNumber: 2,
1378 CompLevel: "quals", StartingQuadrant: 3, LowCubesAuto: 10,
1379 MiddleCubesAuto: 1, HighCubesAuto: 1, CubesDroppedAuto: 0,
1380 LowConesAuto: 1, MiddleConesAuto: 2, HighConesAuto: 1,
1381 ConesDroppedAuto: 0, LowCubes: 1, MiddleCubes: 1,
1382 HighCubes: 2, CubesDropped: 1, LowCones: 1,
1383 MiddleCones: 2, HighCones: 0, ConesDropped: 1, SuperchargedPieces: 0,
1384 AvgCycle: 34, Mobility: false, DockedAuto: true, EngagedAuto: false,
1385 BalanceAttemptAuto: false, Docked: false, Engaged: false,
1386 BalanceAttempt: true, CollectedBy: "isaac",
1387 },
1388 {
1389 TeamNumber: "2343", MatchNumber: 1, SetNumber: 2,
1390 CompLevel: "quals", StartingQuadrant: 1, LowCubesAuto: 0,
1391 MiddleCubesAuto: 1, HighCubesAuto: 1, CubesDroppedAuto: 2,
1392 LowConesAuto: 0, MiddleConesAuto: 0, HighConesAuto: 0,
1393 ConesDroppedAuto: 1, LowCubes: 0, MiddleCubes: 0,
1394 HighCubes: 1, CubesDropped: 0, LowCones: 0,
1395 MiddleCones: 2, HighCones: 1, ConesDropped: 1, SuperchargedPieces: 0,
1396 AvgCycle: 53, Mobility: false, DockedAuto: false, EngagedAuto: false,
1397 BalanceAttemptAuto: true, Docked: false, Engaged: false,
1398 BalanceAttempt: true, CollectedBy: "unknown",
1399 },
1400 },
1401 actions: []db.Action{
1402 {
1403 PreScouting: true,
1404 TeamNumber: "3634",
1405 MatchNumber: 1,
1406 SetNumber: 2,
1407 CompLevel: "quals",
1408 CollectedBy: "debug_cli",
1409 CompletedAction: []byte{},
1410 Timestamp: 2400,
1411 },
1412 {
1413 PreScouting: true,
1414 TeamNumber: "2343",
1415 MatchNumber: 1,
1416 SetNumber: 2,
1417 CompLevel: "quals",
1418 CollectedBy: "debug_cli",
1419 CompletedAction: []byte{},
1420 Timestamp: 1009,
1421 },
1422 },
1423 }
1424 scoutingServer := server.NewScoutingServer()
1425 HandleRequests(&database, scoutingServer)
1426 scoutingServer.Start(8080)
1427 defer scoutingServer.Stop()
1428
1429 builder := flatbuffers.NewBuilder(1024)
1430 builder.Finish((&delete_2023_data_scouting.Delete2023DataScoutingT{
1431 CompLevel: "quals",
1432 MatchNumber: 1,
1433 SetNumber: 2,
1434 TeamNumber: "2343",
1435 }).Pack(builder))
1436
1437 _, err := debug.Delete2023DataScouting("http://localhost:8080", builder.FinishedBytes())
1438 if err != nil {
1439 t.Fatal("Failed to delete from data scouting ", err)
1440 }
1441
1442 expectedActions := []db.Action{
1443 {
1444 PreScouting: true,
1445 TeamNumber: "3634",
1446 MatchNumber: 1,
1447 SetNumber: 2,
1448 CompLevel: "quals",
1449 CollectedBy: "debug_cli",
1450 CompletedAction: []byte{},
1451 Timestamp: 2400,
1452 },
1453 }
1454
1455 expectedStats := []db.Stats2023{
1456 {
1457 TeamNumber: "3634", MatchNumber: 1, SetNumber: 2,
1458 CompLevel: "quals", StartingQuadrant: 3, LowCubesAuto: 10,
1459 MiddleCubesAuto: 1, HighCubesAuto: 1, CubesDroppedAuto: 0,
1460 LowConesAuto: 1, MiddleConesAuto: 2, HighConesAuto: 1,
1461 ConesDroppedAuto: 0, LowCubes: 1, MiddleCubes: 1,
1462 HighCubes: 2, CubesDropped: 1, LowCones: 1,
1463 MiddleCones: 2, HighCones: 0, ConesDropped: 1, SuperchargedPieces: 0,
1464 AvgCycle: 34, Mobility: false, DockedAuto: true, EngagedAuto: false,
1465 BalanceAttemptAuto: false, Docked: false, Engaged: false,
1466 BalanceAttempt: true, CollectedBy: "isaac",
1467 },
1468 }
1469
1470 if !reflect.DeepEqual(expectedActions, database.actions) {
1471 t.Fatal("Expected ", expectedActions, ", but got:", database.actions)
1472 }
1473 if !reflect.DeepEqual(expectedStats, database.stats2023) {
1474 t.Fatal("Expected ", expectedStats, ", but got:", database.stats2023)
1475 }
1476}
1477
Emily Markova8cb91312024-02-02 12:30:37 -08001478// Validates that we can delete 2024 stats.
1479func TestDeleteFromStats2024(t *testing.T) {
1480 database := MockDatabase{
1481 stats2024: []db.Stats2024{
1482 {
1483 PreScouting: false, TeamNumber: "746",
1484 MatchNumber: 3, SetNumber: 1, CompLevel: "quals", StartingQuadrant: 2,
1485 SpeakerAuto: 0, AmpAuto: 1, NotesDroppedAuto: 1, MobilityAuto: true,
1486 Speaker: 0, Amp: 1, SpeakerAmplified: 1, AmpAmplified: 1,
Emily Markova6079e2f2024-02-17 13:17:24 -08001487 NotesDropped: 0, Penalties: 1, TrapNote: true, Spotlight: false, AvgCycle: 233,
Emily Markova040123c2024-02-27 09:48:37 -08001488 Park: false, OnStage: false, Harmony: true, RobotDied: false, CollectedBy: "alek",
Emily Markova8cb91312024-02-02 12:30:37 -08001489 },
1490 {
1491 PreScouting: false, TeamNumber: "244",
1492 MatchNumber: 5, SetNumber: 3, CompLevel: "quals", StartingQuadrant: 1,
1493 SpeakerAuto: 0, AmpAuto: 0, NotesDroppedAuto: 0, MobilityAuto: false,
1494 Speaker: 0, Amp: 0, SpeakerAmplified: 3, AmpAmplified: 1,
Emily Markova6079e2f2024-02-17 13:17:24 -08001495 NotesDropped: 0, Penalties: 1, TrapNote: false, Spotlight: false, AvgCycle: 120,
Emily Markova040123c2024-02-27 09:48:37 -08001496 Park: false, OnStage: true, Harmony: false, RobotDied: false, CollectedBy: "kacey",
Emily Markova8cb91312024-02-02 12:30:37 -08001497 },
1498 },
1499 actions: []db.Action{
1500 {
1501 PreScouting: true,
1502 TeamNumber: "746",
1503 MatchNumber: 3,
1504 SetNumber: 1,
1505 CompLevel: "quals",
1506 CollectedBy: "debug_cli",
1507 CompletedAction: []byte{},
1508 Timestamp: 2400,
1509 },
1510 {
1511 PreScouting: true,
1512 TeamNumber: "244",
1513 MatchNumber: 5,
1514 SetNumber: 3,
1515 CompLevel: "quals",
1516 CollectedBy: "debug_cli",
1517 CompletedAction: []byte{},
1518 Timestamp: 1009,
1519 },
1520 },
1521 }
1522 scoutingServer := server.NewScoutingServer()
1523 HandleRequests(&database, scoutingServer)
1524 scoutingServer.Start(8080)
1525 defer scoutingServer.Stop()
1526
1527 builder := flatbuffers.NewBuilder(1024)
1528 builder.Finish((&delete_2024_data_scouting.Delete2024DataScoutingT{
1529 CompLevel: "quals",
1530 MatchNumber: 3,
1531 SetNumber: 1,
1532 TeamNumber: "746",
1533 }).Pack(builder))
1534
1535 _, err := debug.Delete2024DataScouting("http://localhost:8080", builder.FinishedBytes())
1536 if err != nil {
1537 t.Fatal("Failed to delete from data scouting 2024", err)
1538 }
1539
1540 expectedActions := []db.Action{
1541 {
1542 PreScouting: true,
1543 TeamNumber: "244",
1544 MatchNumber: 5,
1545 SetNumber: 3,
1546 CompLevel: "quals",
1547 CollectedBy: "debug_cli",
1548 CompletedAction: []byte{},
1549 Timestamp: 1009,
1550 },
1551 }
1552
1553 expectedStats := []db.Stats2024{
1554 {
1555 PreScouting: false, TeamNumber: "244",
1556 MatchNumber: 5, SetNumber: 3, CompLevel: "quals", StartingQuadrant: 1,
1557 SpeakerAuto: 0, AmpAuto: 0, NotesDroppedAuto: 0, MobilityAuto: false,
1558 Speaker: 0, Amp: 0, SpeakerAmplified: 3, AmpAmplified: 1,
Emily Markova6079e2f2024-02-17 13:17:24 -08001559 NotesDropped: 0, Penalties: 1, TrapNote: false, Spotlight: false, AvgCycle: 120,
Emily Markova040123c2024-02-27 09:48:37 -08001560 Park: false, OnStage: true, Harmony: false, RobotDied: false, CollectedBy: "kacey",
Emily Markova8cb91312024-02-02 12:30:37 -08001561 },
1562 }
1563
1564 if !reflect.DeepEqual(expectedActions, database.actions) {
1565 t.Fatal("Expected ", expectedActions, ", but got:", database.actions)
1566 }
1567 if !reflect.DeepEqual(expectedStats, database.stats2024) {
1568 t.Fatal("Expected ", expectedStats, ", but got:", database.stats2024)
1569 }
1570}
1571
Philipp Schrader8747f1b2022-02-23 23:56:22 -08001572// A mocked database we can use for testing. Add functionality to this as
1573// needed for your tests.
1574
Philipp Schradercbf5c6a2022-02-27 23:25:19 -08001575type MockDatabase struct {
Emily Markovabf24c9e2023-02-08 20:31:11 -08001576 matches []db.TeamMatch
Filip Kujawa210a03b2022-11-24 14:41:11 -08001577 notes []db.NotesData
1578 shiftSchedule []db.Shift
1579 driver_ranking []db.DriverRankingData
Emily Markova290147d2023-03-03 22:40:06 -08001580 stats2023 []db.Stats2023
Emily Markova8cb91312024-02-02 12:30:37 -08001581 stats2024 []db.Stats2024
Sabina Leaver9b4eb312023-02-20 19:58:17 -08001582 actions []db.Action
Emily Markovafaecfe12023-07-01 12:40:03 -07001583 images []db.PitImage
Philipp Schradercbf5c6a2022-02-27 23:25:19 -08001584}
Philipp Schrader8747f1b2022-02-23 23:56:22 -08001585
Emily Markovabf24c9e2023-02-08 20:31:11 -08001586func (database *MockDatabase) AddToMatch(match db.TeamMatch) error {
Philipp Schraderd3fac192022-03-02 20:35:46 -08001587 database.matches = append(database.matches, match)
Philipp Schrader8747f1b2022-02-23 23:56:22 -08001588 return nil
1589}
1590
Emily Markova290147d2023-03-03 22:40:06 -08001591func (database *MockDatabase) AddToStats2023(stats2023 db.Stats2023) error {
1592 database.stats2023 = append(database.stats2023, stats2023)
1593 return nil
1594}
Emily Markova8cb91312024-02-02 12:30:37 -08001595
1596func (database *MockDatabase) AddToStats2024(stats2024 db.Stats2024) error {
1597 database.stats2024 = append(database.stats2024, stats2024)
1598 return nil
1599}
Emily Markovabf24c9e2023-02-08 20:31:11 -08001600func (database *MockDatabase) ReturnMatches() ([]db.TeamMatch, error) {
Philipp Schradercbf5c6a2022-02-27 23:25:19 -08001601 return database.matches, nil
Philipp Schrader8747f1b2022-02-23 23:56:22 -08001602}
1603
Emily Markova290147d2023-03-03 22:40:06 -08001604func (database *MockDatabase) ReturnStats2023() ([]db.Stats2023, error) {
1605 return database.stats2023, nil
1606}
1607
Emily Markova8cb91312024-02-02 12:30:37 -08001608func (database *MockDatabase) ReturnStats2024() ([]db.Stats2024, error) {
1609 return database.stats2024, nil
1610}
1611
Filip Kujawaf3f9def2023-04-20 13:46:46 -07001612func (database *MockDatabase) ReturnStats2023ForTeam(teamNumber string, matchNumber int32, setNumber int32, compLevel string, preScouting bool) ([]db.Stats2023, error) {
Philipp Schrader0f7b6362023-03-11 14:02:48 -08001613 var results []db.Stats2023
1614 for _, stats := range database.stats2023 {
Filip Kujawaf3f9def2023-04-20 13:46:46 -07001615 if stats.TeamNumber == teamNumber && stats.MatchNumber == matchNumber && stats.SetNumber == setNumber && stats.CompLevel == compLevel && stats.PreScouting == preScouting {
Philipp Schrader0f7b6362023-03-11 14:02:48 -08001616 results = append(results, stats)
1617 }
1618 }
1619 return results, nil
1620}
1621
Emily Markova8cb91312024-02-02 12:30:37 -08001622func (database *MockDatabase) ReturnStats2024ForTeam(teamNumber string, matchNumber int32, setNumber int32, compLevel string, preScouting bool) ([]db.Stats2024, error) {
1623 var results []db.Stats2024
1624 for _, stats := range database.stats2024 {
1625 if stats.TeamNumber == teamNumber && stats.MatchNumber == matchNumber && stats.SetNumber == setNumber && stats.CompLevel == compLevel && stats.PreScouting == preScouting {
1626 results = append(results, stats)
1627 }
1628 }
1629 return results, nil
1630}
1631
Emily Markovae68b7632023-12-30 14:17:55 -08001632func (database *MockDatabase) QueryNotes(requestedTeam string) ([]string, error) {
Alex Perry81f96ba2022-03-13 18:26:19 -07001633 var results []string
1634 for _, data := range database.notes {
1635 if data.TeamNumber == requestedTeam {
Philipp Schradereecb8962022-06-01 21:02:42 -07001636 results = append(results, data.Notes)
Alex Perry81f96ba2022-03-13 18:26:19 -07001637 }
1638 }
Philipp Schradereecb8962022-06-01 21:02:42 -07001639 return results, nil
Alex Perry81f96ba2022-03-13 18:26:19 -07001640}
1641
Filip Kujawaf947cb42022-11-21 10:00:30 -08001642func (database *MockDatabase) AddNotes(data db.NotesData) error {
1643 database.notes = append(database.notes, data)
Alex Perry81f96ba2022-03-13 18:26:19 -07001644 return nil
1645}
1646
Filip Kujawaf882e022022-12-14 13:14:08 -08001647func (database *MockDatabase) ReturnAllNotes() ([]db.NotesData, error) {
1648 return database.notes, nil
1649}
1650
Milo Lin1d59f0c2022-06-22 20:30:58 -07001651func (database *MockDatabase) AddToShift(data db.Shift) error {
1652 database.shiftSchedule = append(database.shiftSchedule, data)
1653 return nil
1654}
1655
1656func (database *MockDatabase) ReturnAllShifts() ([]db.Shift, error) {
1657 return database.shiftSchedule, nil
1658}
1659
1660func (database *MockDatabase) QueryAllShifts(int) ([]db.Shift, error) {
1661 return []db.Shift{}, nil
1662}
1663
Emily Markovafaecfe12023-07-01 12:40:03 -07001664func (database *MockDatabase) QueryPitImages(requestedTeam string) ([]db.RequestedPitImage, error) {
1665 var results []db.RequestedPitImage
1666 for _, data := range database.images {
1667 if data.TeamNumber == requestedTeam {
1668 results = append(results, db.RequestedPitImage{
1669 TeamNumber: data.TeamNumber,
1670 ImagePath: data.ImagePath,
1671 CheckSum: data.CheckSum,
1672 })
1673 }
1674 }
1675 return results, nil
1676}
1677
Filip Kujawa210a03b2022-11-24 14:41:11 -08001678func (database *MockDatabase) AddDriverRanking(data db.DriverRankingData) error {
1679 database.driver_ranking = append(database.driver_ranking, data)
1680 return nil
1681}
1682
Filip Kujawaf882e022022-12-14 13:14:08 -08001683func (database *MockDatabase) ReturnAllDriverRankings() ([]db.DriverRankingData, error) {
1684 return database.driver_ranking, nil
1685}
Sabina Leaver9b4eb312023-02-20 19:58:17 -08001686
1687func (database *MockDatabase) AddAction(action db.Action) error {
1688 database.actions = append(database.actions, action)
1689 return nil
1690}
1691
Emily Markovafaecfe12023-07-01 12:40:03 -07001692func (database *MockDatabase) AddPitImage(pitImage db.PitImage) error {
1693 database.images = append(database.images, pitImage)
1694 return nil
1695}
1696
Sabina Leaver9b4eb312023-02-20 19:58:17 -08001697func (database *MockDatabase) ReturnActions() ([]db.Action, error) {
1698 return database.actions, nil
1699}
Filip Kujawac1ded372023-05-27 14:33:43 -07001700
Emily Markova8e39f452023-12-23 12:17:30 -08001701func (database *MockDatabase) ReturnPitImages() ([]db.PitImage, error) {
1702 return database.images, nil
1703}
1704
Filip Kujawac1ded372023-05-27 14:33:43 -07001705func (database *MockDatabase) DeleteFromStats(compLevel_ string, matchNumber_ int32, setNumber_ int32, teamNumber_ string) error {
1706 for i, stat := range database.stats2023 {
1707 if stat.CompLevel == compLevel_ &&
1708 stat.MatchNumber == matchNumber_ &&
1709 stat.SetNumber == setNumber_ &&
1710 stat.TeamNumber == teamNumber_ {
1711 // Match found, remove the element from the array.
1712 database.stats2023 = append(database.stats2023[:i], database.stats2023[i+1:]...)
1713 }
1714 }
1715 return nil
1716}
1717
Emily Markova8cb91312024-02-02 12:30:37 -08001718func (database *MockDatabase) DeleteFromStats2024(compLevel_ string, matchNumber_ int32, setNumber_ int32, teamNumber_ string) error {
1719 for i, stat := range database.stats2024 {
1720 if stat.CompLevel == compLevel_ &&
1721 stat.MatchNumber == matchNumber_ &&
1722 stat.SetNumber == setNumber_ &&
1723 stat.TeamNumber == teamNumber_ {
1724 // Match found, remove the element from the array.
1725 database.stats2024 = append(database.stats2024[:i], database.stats2024[i+1:]...)
1726 }
1727 }
1728 return nil
1729}
1730
Filip Kujawac1ded372023-05-27 14:33:43 -07001731func (database *MockDatabase) DeleteFromActions(compLevel_ string, matchNumber_ int32, setNumber_ int32, teamNumber_ string) error {
1732 for i, action := range database.actions {
1733 if action.CompLevel == compLevel_ &&
1734 action.MatchNumber == matchNumber_ &&
1735 action.SetNumber == setNumber_ &&
1736 action.TeamNumber == teamNumber_ {
1737 // Match found, remove the element from the array.
1738 database.actions = append(database.actions[:i], database.actions[i+1:]...)
1739 }
1740 }
1741 return nil
1742}