blob: 609b09db060744ac2b85232b5161391c96b6399d [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,
Emily Markovacd156942024-04-07 19:32:28 -0700139 Speaker: 0, Amp: 1, SpeakerAmplified: 2, Shuttled: 1, OutOfField: 2,
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,
Emily Markovacd156942024-04-07 19:32:28 -0700147 Speaker: 0, Amp: 4, SpeakerAmplified: 3, Shuttled: 0, OutOfField: 0,
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,
Emily Markovacd156942024-04-07 19:32:28 -0700216 Speaker: 4, Amp: 2, SpeakerAmplified: 1, Shuttled: 0, OutOfField: 2,
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,
Emily Markovacd156942024-04-07 19:32:28 -0700224 Speaker: 0, Amp: 2, SpeakerAmplified: 3, Shuttled: 1, OutOfField: 0,
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,
Emily Markovacd156942024-04-07 19:32:28 -0700249 Speaker: 4, Amp: 2, SpeakerAmplified: 1, Shuttled: 0, OutOfField: 2,
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,
Emily Markovacd156942024-04-07 19:32:28 -0700257 Speaker: 0, Amp: 2, SpeakerAmplified: 3, Shuttled: 1, OutOfField: 0,
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 },
Emily Markova8cb91312024-02-02 12:30:37 -0800379 Timestamp: 800,
380 },
381 {
382 ActionTaken: &submit_2024_actions.ActionTypeT{
383 Type: submit_2024_actions.ActionTypePlaceNoteAction,
384 Value: &submit_2024_actions.PlaceNoteActionT{
385 ScoreType: submit_2024_actions.ScoreTypekAMP,
386 Auto: true,
387 },
388 },
389 Timestamp: 2000,
390 },
391 {
392 ActionTaken: &submit_2024_actions.ActionTypeT{
393 Type: submit_2024_actions.ActionTypeMobilityAction,
394 Value: &submit_2024_actions.MobilityActionT{
395 Mobility: true,
396 },
397 },
398 Timestamp: 2200,
399 },
400 {
401 ActionTaken: &submit_2024_actions.ActionTypeT{
Emily Markovadcadcb62024-02-03 13:07:17 -0800402 Type: submit_2024_actions.ActionTypePenaltyAction,
403 Value: &submit_2024_actions.PenaltyActionT{
404 Penalties: 5,
405 },
Emily Markova8cb91312024-02-02 12:30:37 -0800406 },
407 Timestamp: 2400,
408 },
409 {
410 ActionTaken: &submit_2024_actions.ActionTypeT{
411 Type: submit_2024_actions.ActionTypePickupNoteAction,
412 Value: &submit_2024_actions.PickupNoteActionT{
413 Auto: false,
414 },
415 },
416 Timestamp: 2800,
417 },
418 {
419 ActionTaken: &submit_2024_actions.ActionTypeT{
420 Type: submit_2024_actions.ActionTypePlaceNoteAction,
421 Value: &submit_2024_actions.PlaceNoteActionT{
Emily Markovacd156942024-04-07 19:32:28 -0700422 ScoreType: submit_2024_actions.ScoreTypekSHUTTLED,
Emily Markova8cb91312024-02-02 12:30:37 -0800423 Auto: false,
424 },
425 },
426 Timestamp: 3100,
427 },
428 {
429 ActionTaken: &submit_2024_actions.ActionTypeT{
430 Type: submit_2024_actions.ActionTypePickupNoteAction,
431 Value: &submit_2024_actions.PickupNoteActionT{
432 Auto: false,
433 },
434 },
Emily Markova040123c2024-02-27 09:48:37 -0800435 Timestamp: 3200,
436 },
437 {
438 ActionTaken: &submit_2024_actions.ActionTypeT{
439 Type: submit_2024_actions.ActionTypePlaceNoteAction,
440 Value: &submit_2024_actions.PlaceNoteActionT{
441 ScoreType: submit_2024_actions.ScoreTypekDROPPED,
442 Auto: false,
443 },
444 },
445 Timestamp: 3300,
446 },
447 {
448 ActionTaken: &submit_2024_actions.ActionTypeT{
449 Type: submit_2024_actions.ActionTypeRobotDeathAction,
450 Value: &submit_2024_actions.RobotDeathActionT{
451 RobotDead: true,
452 },
453 },
454 Timestamp: 3400,
455 },
456 {
457 ActionTaken: &submit_2024_actions.ActionTypeT{
458 Type: submit_2024_actions.ActionTypeRobotDeathAction,
459 Value: &submit_2024_actions.RobotDeathActionT{
460 RobotDead: false,
461 },
462 },
463 Timestamp: 3450,
464 },
465 {
466 ActionTaken: &submit_2024_actions.ActionTypeT{
467 Type: submit_2024_actions.ActionTypePickupNoteAction,
468 Value: &submit_2024_actions.PickupNoteActionT{
469 Auto: false,
470 },
471 },
Emily Markova8cb91312024-02-02 12:30:37 -0800472 Timestamp: 3500,
473 },
474 {
475 ActionTaken: &submit_2024_actions.ActionTypeT{
476 Type: submit_2024_actions.ActionTypePlaceNoteAction,
477 Value: &submit_2024_actions.PlaceNoteActionT{
478 ScoreType: submit_2024_actions.ScoreTypekSPEAKER_AMPLIFIED,
479 Auto: false,
480 },
481 },
482 Timestamp: 3900,
483 },
484 {
485 ActionTaken: &submit_2024_actions.ActionTypeT{
486 Type: submit_2024_actions.ActionTypeEndMatchAction,
487 Value: &submit_2024_actions.EndMatchActionT{
488 StageType: submit_2024_actions.StageTypekHARMONY,
489 TrapNote: false,
Emily Markova6079e2f2024-02-17 13:17:24 -0800490 Spotlight: false,
Emily Markova8cb91312024-02-02 12:30:37 -0800491 },
492 },
493 Timestamp: 4200,
494 },
495 },
496 PreScouting: false,
497 }).Pack(builder))
498
499 submit2024Actions := submit_2024_actions.GetRootAsSubmit2024Actions(builder.FinishedBytes(), 0)
500 response, err := ConvertActionsToStat2024(submit2024Actions)
501
502 if err != nil {
503 t.Fatal("Failed to convert actions to stats: ", err)
504 }
505
506 expected := db.Stats2024{
507 PreScouting: false, TeamNumber: "4244",
508 MatchNumber: 3, SetNumber: 1, CompLevel: "quals", StartingQuadrant: 2,
Emily Markova040123c2024-02-27 09:48:37 -0800509 SpeakerAuto: 0, AmpAuto: 1, NotesDroppedAuto: 0, MobilityAuto: true,
Emily Markovacd156942024-04-07 19:32:28 -0700510 Speaker: 0, Amp: 0, SpeakerAmplified: 1, Shuttled: 1, OutOfField: 0,
511 NotesDropped: 1, Penalties: 5, TrapNote: false, Spotlight: false, AvgCycle: 950,
Emily Markova040123c2024-02-27 09:48:37 -0800512 Park: false, OnStage: false, Harmony: true, RobotDied: true, CollectedBy: "",
Emily Markova8cb91312024-02-02 12:30:37 -0800513 }
514
515 if expected != response {
516 t.Fatal("Expected ", expected, ", but got ", response)
517 }
518}
519
Emily Markova1abe9782023-03-11 19:45:38 -0800520// Validates that we can request the 2023 stats.
521func TestConvertActionsToStat(t *testing.T) {
522 builder := flatbuffers.NewBuilder(1024)
523 builder.Finish((&submit_actions.SubmitActionsT{
524 TeamNumber: "4244",
525 MatchNumber: 3,
526 SetNumber: 1,
527 CompLevel: "quals",
Emily Markova1abe9782023-03-11 19:45:38 -0800528 ActionsList: []*submit_actions.ActionT{
529 {
530 ActionTaken: &submit_actions.ActionTypeT{
531 Type: submit_actions.ActionTypeStartMatchAction,
532 Value: &submit_actions.StartMatchActionT{
533 Position: 1,
534 },
535 },
536 Timestamp: 0,
537 },
538 {
539 ActionTaken: &submit_actions.ActionTypeT{
540 Type: submit_actions.ActionTypePickupObjectAction,
541 Value: &submit_actions.PickupObjectActionT{
542 ObjectType: submit_actions.ObjectTypekCube,
543 Auto: true,
544 },
545 },
546 Timestamp: 400,
547 },
548 {
549 ActionTaken: &submit_actions.ActionTypeT{
550 Type: submit_actions.ActionTypePickupObjectAction,
551 Value: &submit_actions.PickupObjectActionT{
552 ObjectType: submit_actions.ObjectTypekCube,
553 Auto: true,
554 },
555 },
556 Timestamp: 800,
557 },
558 {
559 ActionTaken: &submit_actions.ActionTypeT{
560 Type: submit_actions.ActionTypePlaceObjectAction,
561 Value: &submit_actions.PlaceObjectActionT{
562 ObjectType: submit_actions.ObjectTypekCube,
563 ScoreLevel: submit_actions.ScoreLevelkLow,
564 Auto: true,
565 },
566 },
567 Timestamp: 2000,
568 },
569 {
570 ActionTaken: &submit_actions.ActionTypeT{
Filip Kujawa0b4b1e52023-04-15 14:05:40 -0700571 Type: submit_actions.ActionTypeMobilityAction,
572 Value: &submit_actions.MobilityActionT{
573 Mobility: true,
574 },
575 },
576 Timestamp: 2200,
577 },
578 {
579 ActionTaken: &submit_actions.ActionTypeT{
Emily Markova46a69bf2023-03-22 20:45:52 -0700580 Type: submit_actions.ActionTypeAutoBalanceAction,
581 Value: &submit_actions.AutoBalanceActionT{
Emily Markova63c63f62023-03-29 20:57:35 -0700582 Docked: true,
583 Engaged: true,
584 BalanceAttempt: false,
Emily Markova46a69bf2023-03-22 20:45:52 -0700585 },
586 },
587 Timestamp: 2400,
588 },
589 {
590 ActionTaken: &submit_actions.ActionTypeT{
Emily Markova1abe9782023-03-11 19:45:38 -0800591 Type: submit_actions.ActionTypePickupObjectAction,
592 Value: &submit_actions.PickupObjectActionT{
593 ObjectType: submit_actions.ObjectTypekCone,
594 Auto: false,
595 },
596 },
597 Timestamp: 2800,
598 },
599 {
600 ActionTaken: &submit_actions.ActionTypeT{
601 Type: submit_actions.ActionTypePlaceObjectAction,
602 Value: &submit_actions.PlaceObjectActionT{
603 ObjectType: submit_actions.ObjectTypekCone,
604 ScoreLevel: submit_actions.ScoreLevelkHigh,
605 Auto: false,
606 },
607 },
608 Timestamp: 3100,
609 },
Emily Markova46a69bf2023-03-22 20:45:52 -0700610 {
611 ActionTaken: &submit_actions.ActionTypeT{
Filip Kujawa7a045e72023-04-13 08:41:09 -0700612 Type: submit_actions.ActionTypePickupObjectAction,
613 Value: &submit_actions.PickupObjectActionT{
614 ObjectType: submit_actions.ObjectTypekCube,
615 Auto: false,
616 },
617 },
618 Timestamp: 3500,
619 },
620 {
621 ActionTaken: &submit_actions.ActionTypeT{
622 Type: submit_actions.ActionTypePlaceObjectAction,
623 Value: &submit_actions.PlaceObjectActionT{
624 ObjectType: submit_actions.ObjectTypekCube,
625 ScoreLevel: submit_actions.ScoreLevelkSupercharged,
626 Auto: false,
627 },
628 },
629 Timestamp: 3900,
630 },
631 {
632 ActionTaken: &submit_actions.ActionTypeT{
Emily Markova46a69bf2023-03-22 20:45:52 -0700633 Type: submit_actions.ActionTypeEndMatchAction,
634 Value: &submit_actions.EndMatchActionT{
Emily Markova63c63f62023-03-29 20:57:35 -0700635 Docked: true,
636 Engaged: false,
637 BalanceAttempt: true,
Emily Markova46a69bf2023-03-22 20:45:52 -0700638 },
639 },
Filip Kujawa7a045e72023-04-13 08:41:09 -0700640 Timestamp: 4200,
Emily Markova46a69bf2023-03-22 20:45:52 -0700641 },
Emily Markova1abe9782023-03-11 19:45:38 -0800642 },
Philipp Schrader4b489222023-04-15 16:40:16 -0700643 PreScouting: false,
Emily Markova1abe9782023-03-11 19:45:38 -0800644 }).Pack(builder))
645
646 submitActions := submit_actions.GetRootAsSubmitActions(builder.FinishedBytes(), 0)
647 response, err := ConvertActionsToStat(submitActions)
648
649 if err != nil {
650 t.Fatal("Failed to convert actions to stats: ", err)
651 }
652
653 expected := db.Stats2023{
Philipp Schrader4b489222023-04-15 16:40:16 -0700654 PreScouting: false,
655 TeamNumber: "4244", MatchNumber: 3, SetNumber: 1,
Emily Markova1abe9782023-03-11 19:45:38 -0800656 CompLevel: "quals", StartingQuadrant: 1, LowCubesAuto: 1,
657 MiddleCubesAuto: 0, HighCubesAuto: 0, CubesDroppedAuto: 1,
658 LowConesAuto: 0, MiddleConesAuto: 0, HighConesAuto: 0,
659 ConesDroppedAuto: 0, LowCubes: 0, MiddleCubes: 0,
660 HighCubes: 0, CubesDropped: 0, LowCones: 0,
Filip Kujawa7a045e72023-04-13 08:41:09 -0700661 MiddleCones: 0, HighCones: 1, ConesDropped: 0, SuperchargedPieces: 1,
Filip Kujawa0b4b1e52023-04-15 14:05:40 -0700662 AvgCycle: 950, Mobility: true, DockedAuto: true, EngagedAuto: true,
Emily Markova63c63f62023-03-29 20:57:35 -0700663 BalanceAttemptAuto: false, Docked: true, Engaged: false,
Philipp Schradere11114f2023-04-15 17:04:25 -0700664 BalanceAttempt: true, CollectedBy: "",
Emily Markova1abe9782023-03-11 19:45:38 -0800665 }
666
667 if expected != response {
668 t.Fatal("Expected ", expected, ", but got ", response)
669 }
670}
671
Alex Perry81f96ba2022-03-13 18:26:19 -0700672func TestSubmitNotes(t *testing.T) {
673 database := MockDatabase{}
674 scoutingServer := server.NewScoutingServer()
Philipp Schrader43c730b2023-02-26 20:27:44 -0800675 HandleRequests(&database, scoutingServer)
Alex Perry81f96ba2022-03-13 18:26:19 -0700676 scoutingServer.Start(8080)
677 defer scoutingServer.Stop()
678
679 builder := flatbuffers.NewBuilder(1024)
680 builder.Finish((&submit_notes.SubmitNotesT{
Emily Markovae68b7632023-12-30 14:17:55 -0800681 Team: "971",
Filip Kujawa7ddd5652023-03-07 19:56:15 -0800682 Notes: "Notes",
683 GoodDriving: true,
684 BadDriving: false,
Filip Kujawa11dc4c92023-04-13 08:55:43 -0700685 SolidPlacing: true,
Filip Kujawa7ddd5652023-03-07 19:56:15 -0800686 SketchyPlacing: false,
687 GoodDefense: true,
688 BadDefense: false,
689 EasilyDefended: true,
Alex Perry81f96ba2022-03-13 18:26:19 -0700690 }).Pack(builder))
691
692 _, err := debug.SubmitNotes("http://localhost:8080", builder.FinishedBytes())
693 if err != nil {
694 t.Fatal("Failed to submit notes: ", err)
695 }
696
697 expected := []db.NotesData{
Filip Kujawaf947cb42022-11-21 10:00:30 -0800698 {
Emily Markovae68b7632023-12-30 14:17:55 -0800699 TeamNumber: "971",
Filip Kujawa7ddd5652023-03-07 19:56:15 -0800700 Notes: "Notes",
701 GoodDriving: true,
702 BadDriving: false,
Filip Kujawa11dc4c92023-04-13 08:55:43 -0700703 SolidPlacing: true,
Filip Kujawa7ddd5652023-03-07 19:56:15 -0800704 SketchyPlacing: false,
705 GoodDefense: true,
706 BadDefense: false,
707 EasilyDefended: true,
Filip Kujawaf947cb42022-11-21 10:00:30 -0800708 },
Alex Perry81f96ba2022-03-13 18:26:19 -0700709 }
710
711 if !reflect.DeepEqual(database.notes, expected) {
712 t.Fatal("Submitted notes did not match", expected, database.notes)
713 }
714}
715
716func TestRequestNotes(t *testing.T) {
717 database := MockDatabase{
718 notes: []db.NotesData{{
Emily Markovae68b7632023-12-30 14:17:55 -0800719 TeamNumber: "971A",
Filip Kujawa7ddd5652023-03-07 19:56:15 -0800720 Notes: "Notes",
721 GoodDriving: true,
722 BadDriving: false,
Filip Kujawa11dc4c92023-04-13 08:55:43 -0700723 SolidPlacing: true,
Filip Kujawa7ddd5652023-03-07 19:56:15 -0800724 SketchyPlacing: false,
725 GoodDefense: true,
726 BadDefense: false,
727 EasilyDefended: true,
Alex Perry81f96ba2022-03-13 18:26:19 -0700728 }},
729 }
730 scoutingServer := server.NewScoutingServer()
Philipp Schrader43c730b2023-02-26 20:27:44 -0800731 HandleRequests(&database, scoutingServer)
Alex Perry81f96ba2022-03-13 18:26:19 -0700732 scoutingServer.Start(8080)
733 defer scoutingServer.Stop()
734
735 builder := flatbuffers.NewBuilder(1024)
736 builder.Finish((&request_notes_for_team.RequestNotesForTeamT{
Emily Markovae68b7632023-12-30 14:17:55 -0800737 Team: "971A",
Alex Perry81f96ba2022-03-13 18:26:19 -0700738 }).Pack(builder))
739 response, err := debug.RequestNotes("http://localhost:8080", builder.FinishedBytes())
740 if err != nil {
741 t.Fatal("Failed to submit notes: ", err)
742 }
743
744 if response.Notes[0].Data != "Notes" {
745 t.Fatal("requested notes did not match", response)
746 }
747}
748
Emily Markovafaecfe12023-07-01 12:40:03 -0700749func TestSubmitPitImage(t *testing.T) {
750 database := MockDatabase{}
751 scoutingServer := server.NewScoutingServer()
752 HandleRequests(&database, scoutingServer)
753 scoutingServer.Start(8080)
754 defer scoutingServer.Stop()
755
756 builder := flatbuffers.NewBuilder(1024)
757 builder.Finish((&submit_pit_image.SubmitPitImageT{
758 TeamNumber: "483A", ImagePath: "483Arobot.jpg",
759 ImageData: []byte{12, 43, 54, 34, 98},
760 }).Pack(builder))
761
762 _, err := debug.SubmitPitImage("http://localhost:8080", builder.FinishedBytes())
763 if err != nil {
764 t.Fatal("Failed to submit pit image: ", err)
765 }
766
767 expected := []db.PitImage{
768 {
769 TeamNumber: "483A", CheckSum: "177d9dc52bc25f391232e82521259c378964c068832a9178d73448ba4ac5e0b1",
770 ImagePath: "483Arobot.jpg", ImageData: []byte{12, 43, 54, 34, 98},
771 },
772 }
773
774 if !reflect.DeepEqual(database.images, expected) {
775 t.Fatal("Submitted image did not match", expected, database.images)
776 }
777}
778
779func TestRequestPitImages(t *testing.T) {
780 db := MockDatabase{
781 images: []db.PitImage{
782 {
783 TeamNumber: "932", ImagePath: "pitimage.jpg",
784 ImageData: []byte{3, 34, 44, 65}, CheckSum: "abcdf",
785 },
786 {
787 TeamNumber: "234", ImagePath: "234robot.png",
788 ImageData: []byte{64, 54, 21, 21, 76, 32}, CheckSum: "egrfd",
789 },
790 {
791 TeamNumber: "93A", ImagePath: "abcd.jpg",
792 ImageData: []byte{92, 94, 10, 30, 57, 32, 32}, CheckSum: "rgegfd",
793 },
794 },
795 }
796
797 scoutingServer := server.NewScoutingServer()
798 HandleRequests(&db, scoutingServer)
799 scoutingServer.Start(8080)
800 defer scoutingServer.Stop()
801
802 builder := flatbuffers.NewBuilder(1024)
803 builder.Finish((&request_pit_images.RequestPitImagesT{"932"}).Pack(builder))
804
805 response, err := debug.RequestPitImages("http://localhost:8080", builder.FinishedBytes())
806 if err != nil {
807 t.Fatal("Failed to request pit images: ", err)
808 }
809
810 expected := request_pit_images_response.RequestPitImagesResponseT{
811 PitImageList: []*request_pit_images_response.PitImageT{
812 {
813 TeamNumber: "932", ImagePath: "pitimage.jpg", CheckSum: "abcdf",
814 },
815 },
816 }
817
818 if len(expected.PitImageList) != len(response.PitImageList) {
819 t.Fatal("Expected ", expected, ", but got ", *response)
820 }
821
822 for i, pit_image := range expected.PitImageList {
823 if !reflect.DeepEqual(*pit_image, *response.PitImageList[i]) {
824 t.Fatal("Expected for pit image", i, ":", *pit_image, ", but got:", *response.PitImageList[i])
825 }
826 }
827}
828
Emily Markova8e39f452023-12-23 12:17:30 -0800829func TestRequestAllPitImages(t *testing.T) {
830 db := MockDatabase{
831 images: []db.PitImage{
832 {
833 TeamNumber: "32", ImagePath: "pitimage.jpg",
834 ImageData: []byte{3, 43, 44, 32}, CheckSum: "cdhrj",
835 },
836 {
837 TeamNumber: "231", ImagePath: "232robot.png",
838 ImageData: []byte{64, 54, 54, 21, 76, 32}, CheckSum: "rgre",
839 },
840 {
841 TeamNumber: "90", ImagePath: "abcd.jpg",
842 ImageData: []byte{92, 94, 10, 30, 57, 32, 32}, CheckSum: "erfer",
843 },
844 },
845 }
846
847 scoutingServer := server.NewScoutingServer()
848 HandleRequests(&db, scoutingServer)
849 scoutingServer.Start(8080)
850 defer scoutingServer.Stop()
851
852 builder := flatbuffers.NewBuilder(1024)
853 builder.Finish((&request_all_pit_images.RequestAllPitImagesT{}).Pack(builder))
854
855 response, err := debug.RequestAllPitImages("http://localhost:8080", builder.FinishedBytes())
856 if err != nil {
857 t.Fatal("Failed to request pit images: ", err)
858 }
859
860 expected := request_all_pit_images_response.RequestAllPitImagesResponseT{
861 PitImageList: []*request_all_pit_images_response.PitImageT{
862 {
863 TeamNumber: "32", ImagePath: "pitimage.jpg", CheckSum: "cdhrj",
864 },
865 {
866 TeamNumber: "231", ImagePath: "232robot.png", CheckSum: "rgre",
867 },
868 {
869 TeamNumber: "90", ImagePath: "abcd.jpg", CheckSum: "erfer",
870 },
871 },
872 }
873
874 if len(expected.PitImageList) != len(response.PitImageList) {
875 t.Fatal("Expected ", expected, ", but got ", *response)
876 }
877
878 for i, pit_image := range expected.PitImageList {
879 if !reflect.DeepEqual(*pit_image, *response.PitImageList[i]) {
880 t.Fatal("Expected for pit image", i, ":", *pit_image, ", but got:", *response.PitImageList[i])
881 }
882 }
883}
884
Milo Lin1d59f0c2022-06-22 20:30:58 -0700885func TestRequestShiftSchedule(t *testing.T) {
886 db := MockDatabase{
887 shiftSchedule: []db.Shift{
888 {
889 MatchNumber: 1,
890 R1scouter: "Bob",
891 R2scouter: "James",
892 R3scouter: "Robert",
893 B1scouter: "Alice",
894 B2scouter: "Mary",
895 B3scouter: "Patricia",
896 },
897 {
898 MatchNumber: 2,
899 R1scouter: "Liam",
900 R2scouter: "Noah",
901 R3scouter: "Oliver",
902 B1scouter: "Emma",
903 B2scouter: "Charlotte",
904 B3scouter: "Amelia",
905 },
906 },
907 }
908 scoutingServer := server.NewScoutingServer()
Philipp Schrader43c730b2023-02-26 20:27:44 -0800909 HandleRequests(&db, scoutingServer)
Milo Lin1d59f0c2022-06-22 20:30:58 -0700910 scoutingServer.Start(8080)
911 defer scoutingServer.Stop()
912
913 builder := flatbuffers.NewBuilder(1024)
914 builder.Finish((&request_shift_schedule.RequestShiftScheduleT{}).Pack(builder))
915
916 response, err := debug.RequestShiftSchedule("http://localhost:8080", builder.FinishedBytes())
917 if err != nil {
918 t.Fatal("Failed to request shift schedule: ", err)
919 }
920
921 expected := request_shift_schedule_response.RequestShiftScheduleResponseT{
922 ShiftSchedule: []*request_shift_schedule_response.MatchAssignmentT{
923 {
924 MatchNumber: 1,
Philipp Schrader2ff455b2023-05-03 22:11:50 -0700925 R1Scouter: "Bob",
926 R2Scouter: "James",
927 R3Scouter: "Robert",
928 B1Scouter: "Alice",
929 B2Scouter: "Mary",
930 B3Scouter: "Patricia",
Milo Lin1d59f0c2022-06-22 20:30:58 -0700931 },
932 {
933 MatchNumber: 2,
Philipp Schrader2ff455b2023-05-03 22:11:50 -0700934 R1Scouter: "Liam",
935 R2Scouter: "Noah",
936 R3Scouter: "Oliver",
937 B1Scouter: "Emma",
938 B2Scouter: "Charlotte",
939 B3Scouter: "Amelia",
Milo Lin1d59f0c2022-06-22 20:30:58 -0700940 },
941 },
942 }
943 if len(expected.ShiftSchedule) != len(response.ShiftSchedule) {
944 t.Fatal("Expected ", expected, ", but got ", *response)
945 }
946 for i, match := range expected.ShiftSchedule {
947 if !reflect.DeepEqual(*match, *response.ShiftSchedule[i]) {
948 t.Fatal("Expected for shift schedule", i, ":", *match, ", but got:", *response.ShiftSchedule[i])
949 }
950 }
951}
952
953func TestSubmitShiftSchedule(t *testing.T) {
954 database := MockDatabase{}
955 scoutingServer := server.NewScoutingServer()
Philipp Schrader43c730b2023-02-26 20:27:44 -0800956 HandleRequests(&database, scoutingServer)
Milo Lin1d59f0c2022-06-22 20:30:58 -0700957 scoutingServer.Start(8080)
958 defer scoutingServer.Stop()
959
960 builder := flatbuffers.NewBuilder(1024)
961 builder.Finish((&submit_shift_schedule.SubmitShiftScheduleT{
962 ShiftSchedule: []*submit_shift_schedule.MatchAssignmentT{
963 {MatchNumber: 1,
Philipp Schrader2ff455b2023-05-03 22:11:50 -0700964 R1Scouter: "Bob",
965 R2Scouter: "James",
966 R3Scouter: "Robert",
967 B1Scouter: "Alice",
968 B2Scouter: "Mary",
969 B3Scouter: "Patricia"},
Milo Lin1d59f0c2022-06-22 20:30:58 -0700970 },
971 }).Pack(builder))
972
973 _, err := debug.SubmitShiftSchedule("http://localhost:8080", builder.FinishedBytes())
974 if err != nil {
975 t.Fatal("Failed to submit shift schedule: ", err)
976 }
977
978 expected := []db.Shift{
979 {MatchNumber: 1,
980 R1scouter: "Bob",
981 R2scouter: "James",
982 R3scouter: "Robert",
983 B1scouter: "Alice",
984 B2scouter: "Mary",
985 B3scouter: "Patricia"},
986 }
987 if !reflect.DeepEqual(expected, database.shiftSchedule) {
988 t.Fatal("Expected ", expected, ", but got:", database.shiftSchedule)
989 }
990}
991
Filip Kujawa210a03b2022-11-24 14:41:11 -0800992func TestSubmitDriverRanking(t *testing.T) {
993 database := MockDatabase{}
994 scoutingServer := server.NewScoutingServer()
Philipp Schrader43c730b2023-02-26 20:27:44 -0800995 HandleRequests(&database, scoutingServer)
Filip Kujawa210a03b2022-11-24 14:41:11 -0800996 scoutingServer.Start(8080)
997 defer scoutingServer.Stop()
998
999 builder := flatbuffers.NewBuilder(1024)
1000 builder.Finish((&submit_driver_ranking.SubmitDriverRankingT{
1001 MatchNumber: 36,
Emily Markovae68b7632023-12-30 14:17:55 -08001002 Rank1: "1234",
1003 Rank2: "1235",
1004 Rank3: "1236",
Filip Kujawa210a03b2022-11-24 14:41:11 -08001005 }).Pack(builder))
1006
1007 _, err := debug.SubmitDriverRanking("http://localhost:8080", builder.FinishedBytes())
1008 if err != nil {
1009 t.Fatal("Failed to submit driver ranking: ", err)
1010 }
1011
1012 expected := []db.DriverRankingData{
Emily Markovae68b7632023-12-30 14:17:55 -08001013 {MatchNumber: 36, Rank1: "1234", Rank2: "1235", Rank3: "1236"},
Filip Kujawa210a03b2022-11-24 14:41:11 -08001014 }
1015
1016 if !reflect.DeepEqual(database.driver_ranking, expected) {
1017 t.Fatal("Submitted notes did not match", expected, database.notes)
1018 }
1019}
1020
Filip Kujawaf882e022022-12-14 13:14:08 -08001021// Validates that we can request the driver rankings.
1022func TestRequestDriverRankings(t *testing.T) {
1023 db := MockDatabase{
1024 driver_ranking: []db.DriverRankingData{
1025 {
1026 MatchNumber: 36,
Emily Markovae68b7632023-12-30 14:17:55 -08001027 Rank1: "1234",
1028 Rank2: "1235",
1029 Rank3: "1236",
Filip Kujawaf882e022022-12-14 13:14:08 -08001030 },
1031 {
1032 MatchNumber: 36,
Emily Markovae68b7632023-12-30 14:17:55 -08001033 Rank1: "101",
1034 Rank2: "202",
1035 Rank3: "303",
Filip Kujawaf882e022022-12-14 13:14:08 -08001036 },
1037 },
1038 }
1039 scoutingServer := server.NewScoutingServer()
Philipp Schrader43c730b2023-02-26 20:27:44 -08001040 HandleRequests(&db, scoutingServer)
Filip Kujawaf882e022022-12-14 13:14:08 -08001041 scoutingServer.Start(8080)
1042 defer scoutingServer.Stop()
1043
1044 builder := flatbuffers.NewBuilder(1024)
1045 builder.Finish((&request_all_driver_rankings.RequestAllDriverRankingsT{}).Pack(builder))
1046
1047 response, err := debug.RequestAllDriverRankings("http://localhost:8080", builder.FinishedBytes())
1048 if err != nil {
1049 t.Fatal("Failed to request all driver rankings: ", err)
1050 }
1051
1052 expected := request_all_driver_rankings_response.RequestAllDriverRankingsResponseT{
1053 DriverRankingList: []*request_all_driver_rankings_response.RankingT{
1054 {
1055 MatchNumber: 36,
Emily Markovae68b7632023-12-30 14:17:55 -08001056 Rank1: "1234",
1057 Rank2: "1235",
1058 Rank3: "1236",
Filip Kujawaf882e022022-12-14 13:14:08 -08001059 },
1060 {
1061 MatchNumber: 36,
Emily Markovae68b7632023-12-30 14:17:55 -08001062 Rank1: "101",
1063 Rank2: "202",
1064 Rank3: "303",
Filip Kujawaf882e022022-12-14 13:14:08 -08001065 },
1066 },
1067 }
1068 if len(expected.DriverRankingList) != len(response.DriverRankingList) {
1069 t.Fatal("Expected ", expected, ", but got ", *response)
1070 }
1071 for i, match := range expected.DriverRankingList {
1072 if !reflect.DeepEqual(*match, *response.DriverRankingList[i]) {
1073 t.Fatal("Expected for driver ranking", i, ":", *match, ", but got:", *response.DriverRankingList[i])
1074 }
1075 }
1076}
1077
1078// Validates that we can request all notes.
1079func TestRequestAllNotes(t *testing.T) {
1080 db := MockDatabase{
1081 notes: []db.NotesData{
1082 {
Emily Markovae68b7632023-12-30 14:17:55 -08001083 TeamNumber: "971",
Filip Kujawa7ddd5652023-03-07 19:56:15 -08001084 Notes: "Notes",
1085 GoodDriving: true,
1086 BadDriving: false,
Filip Kujawa11dc4c92023-04-13 08:55:43 -07001087 SolidPlacing: true,
Filip Kujawa7ddd5652023-03-07 19:56:15 -08001088 SketchyPlacing: false,
1089 GoodDefense: true,
1090 BadDefense: false,
1091 EasilyDefended: false,
Filip Kujawaf882e022022-12-14 13:14:08 -08001092 },
1093 {
Emily Markovae68b7632023-12-30 14:17:55 -08001094 TeamNumber: "972",
Filip Kujawa7ddd5652023-03-07 19:56:15 -08001095 Notes: "More Notes",
1096 GoodDriving: false,
1097 BadDriving: false,
Filip Kujawa11dc4c92023-04-13 08:55:43 -07001098 SolidPlacing: false,
Filip Kujawa7ddd5652023-03-07 19:56:15 -08001099 SketchyPlacing: true,
1100 GoodDefense: false,
1101 BadDefense: true,
1102 EasilyDefended: false,
Filip Kujawaf882e022022-12-14 13:14:08 -08001103 },
1104 },
1105 }
1106 scoutingServer := server.NewScoutingServer()
Philipp Schrader43c730b2023-02-26 20:27:44 -08001107 HandleRequests(&db, scoutingServer)
Filip Kujawaf882e022022-12-14 13:14:08 -08001108 scoutingServer.Start(8080)
1109 defer scoutingServer.Stop()
1110
1111 builder := flatbuffers.NewBuilder(1024)
1112 builder.Finish((&request_all_notes.RequestAllNotesT{}).Pack(builder))
1113
1114 response, err := debug.RequestAllNotes("http://localhost:8080", builder.FinishedBytes())
1115 if err != nil {
1116 t.Fatal("Failed to request all notes: ", err)
1117 }
1118
1119 expected := request_all_notes_response.RequestAllNotesResponseT{
1120 NoteList: []*request_all_notes_response.NoteT{
1121 {
Emily Markovae68b7632023-12-30 14:17:55 -08001122 Team: "971",
Filip Kujawa7ddd5652023-03-07 19:56:15 -08001123 Notes: "Notes",
1124 GoodDriving: true,
1125 BadDriving: false,
Filip Kujawa11dc4c92023-04-13 08:55:43 -07001126 SolidPlacing: true,
Filip Kujawa7ddd5652023-03-07 19:56:15 -08001127 SketchyPlacing: false,
1128 GoodDefense: true,
1129 BadDefense: false,
1130 EasilyDefended: false,
Filip Kujawaf882e022022-12-14 13:14:08 -08001131 },
1132 {
Emily Markovae68b7632023-12-30 14:17:55 -08001133 Team: "972",
Filip Kujawa7ddd5652023-03-07 19:56:15 -08001134 Notes: "More Notes",
1135 GoodDriving: false,
1136 BadDriving: false,
Filip Kujawa11dc4c92023-04-13 08:55:43 -07001137 SolidPlacing: false,
Filip Kujawa7ddd5652023-03-07 19:56:15 -08001138 SketchyPlacing: true,
1139 GoodDefense: false,
1140 BadDefense: true,
1141 EasilyDefended: false,
Filip Kujawaf882e022022-12-14 13:14:08 -08001142 },
1143 },
1144 }
1145 if len(expected.NoteList) != len(response.NoteList) {
1146 t.Fatal("Expected ", expected, ", but got ", *response)
1147 }
1148 for i, note := range expected.NoteList {
1149 if !reflect.DeepEqual(*note, *response.NoteList[i]) {
1150 t.Fatal("Expected for note", i, ":", *note, ", but got:", *response.NoteList[i])
1151 }
1152 }
1153}
1154
Sabina Leaver9b4eb312023-02-20 19:58:17 -08001155func packAction(action *submit_actions.ActionT) []byte {
1156 builder := flatbuffers.NewBuilder(50 * 1024)
1157 builder.Finish((action).Pack(builder))
1158 return (builder.FinishedBytes())
1159}
1160
Emily Markova8cb91312024-02-02 12:30:37 -08001161func TestAddingActions2024(t *testing.T) {
1162 database := MockDatabase{}
1163 scoutingServer := server.NewScoutingServer()
1164 HandleRequests(&database, scoutingServer)
1165 scoutingServer.Start(8080)
1166 defer scoutingServer.Stop()
1167
1168 builder := flatbuffers.NewBuilder(1024)
1169 builder.Finish((&submit_2024_actions.Submit2024ActionsT{
1170 TeamNumber: "3421",
1171 MatchNumber: 2,
1172 SetNumber: 1,
1173 CompLevel: "quals",
1174 ActionsList: []*submit_2024_actions.ActionT{
1175 {
1176 ActionTaken: &submit_2024_actions.ActionTypeT{
1177 Type: submit_2024_actions.ActionTypePickupNoteAction,
1178 Value: &submit_2024_actions.PickupNoteActionT{
1179 Auto: true,
1180 },
1181 },
1182 Timestamp: 1800,
1183 },
1184 {
1185 ActionTaken: &submit_2024_actions.ActionTypeT{
1186 Type: submit_2024_actions.ActionTypePlaceNoteAction,
1187 Value: &submit_2024_actions.PlaceNoteActionT{
1188 ScoreType: submit_2024_actions.ScoreTypekSPEAKER,
1189 Auto: false,
1190 },
1191 },
1192 Timestamp: 2500,
1193 },
1194 },
1195 PreScouting: true,
1196 }).Pack(builder))
1197
1198 _, err := debug.Submit2024Actions("http://localhost:8080", builder.FinishedBytes())
1199 if err != nil {
1200 t.Fatal("Failed to submit actions: ", err)
1201 }
1202
1203 expectedActions := []db.Action{
1204 {
1205 PreScouting: true,
1206 TeamNumber: "3421",
1207 MatchNumber: 2,
1208 SetNumber: 1,
1209 CompLevel: "quals",
1210 CollectedBy: "debug_cli",
1211 CompletedAction: []byte{},
1212 Timestamp: 1800,
1213 },
1214 {
1215 PreScouting: true,
1216 TeamNumber: "3421",
1217 MatchNumber: 2,
1218 SetNumber: 1,
1219 CompLevel: "quals",
1220 CollectedBy: "debug_cli",
1221 CompletedAction: []byte{},
1222 Timestamp: 2500,
1223 },
1224 }
1225
1226 expectedStats := []db.Stats2024{
1227 db.Stats2024{
1228 PreScouting: true, TeamNumber: "3421",
1229 MatchNumber: 2, SetNumber: 1, CompLevel: "quals", StartingQuadrant: 0,
1230 SpeakerAuto: 0, AmpAuto: 0, NotesDroppedAuto: 0, MobilityAuto: false,
Emily Markovacd156942024-04-07 19:32:28 -07001231 Speaker: 1, Amp: 0, SpeakerAmplified: 0, Shuttled: 0, OutOfField: 0,
Emily Markova6079e2f2024-02-17 13:17:24 -08001232 NotesDropped: 0, Penalties: 0, TrapNote: false, Spotlight: false, AvgCycle: 0,
Emily Markova040123c2024-02-27 09:48:37 -08001233 Park: false, OnStage: false, Harmony: false, RobotDied: false, CollectedBy: "debug_cli",
Emily Markova8cb91312024-02-02 12:30:37 -08001234 },
1235 }
1236
1237 if !reflect.DeepEqual(expectedActions, database.actions) {
1238 t.Fatal("Expected ", expectedActions, ", but got:", database.actions)
1239 }
1240 if !reflect.DeepEqual(expectedStats, database.stats2024) {
1241 t.Fatal("Expected ", expectedStats, ", but got:", database.stats2024)
1242 }
1243}
1244
Sabina Leaver9b4eb312023-02-20 19:58:17 -08001245func TestAddingActions(t *testing.T) {
1246 database := MockDatabase{}
1247 scoutingServer := server.NewScoutingServer()
1248 HandleRequests(&database, scoutingServer)
1249 scoutingServer.Start(8080)
1250 defer scoutingServer.Stop()
1251
1252 builder := flatbuffers.NewBuilder(1024)
1253 builder.Finish((&submit_actions.SubmitActionsT{
1254 TeamNumber: "1234",
1255 MatchNumber: 4,
1256 SetNumber: 1,
1257 CompLevel: "qual",
1258 ActionsList: []*submit_actions.ActionT{
1259 {
1260 ActionTaken: &submit_actions.ActionTypeT{
1261 Type: submit_actions.ActionTypePickupObjectAction,
1262 Value: &submit_actions.PickupObjectActionT{
1263 ObjectType: submit_actions.ObjectTypekCube,
1264 Auto: true,
1265 },
1266 },
1267 Timestamp: 2400,
1268 },
1269 {
1270 ActionTaken: &submit_actions.ActionTypeT{
1271 Type: submit_actions.ActionTypePlaceObjectAction,
1272 Value: &submit_actions.PlaceObjectActionT{
1273 ObjectType: submit_actions.ObjectTypekCube,
1274 ScoreLevel: submit_actions.ScoreLevelkLow,
1275 Auto: false,
1276 },
1277 },
1278 Timestamp: 1009,
1279 },
1280 },
Philipp Schrader4b489222023-04-15 16:40:16 -07001281 PreScouting: true,
Sabina Leaver9b4eb312023-02-20 19:58:17 -08001282 }).Pack(builder))
1283
1284 _, err := debug.SubmitActions("http://localhost:8080", builder.FinishedBytes())
1285 if err != nil {
1286 t.Fatal("Failed to submit actions: ", err)
1287 }
1288
1289 // Make sure that the data made it into the database.
1290 // TODO: Add this back when we figure out how to add the serialized action into the database.
1291
1292 /* expectedActionsT := []*submit_actions.ActionT{
1293 {
1294 ActionTaken: &submit_actions.ActionTypeT{
1295 Type: submit_actions.ActionTypePickupObjectAction,
1296 Value: &submit_actions.PickupObjectActionT{
1297 ObjectType: submit_actions.ObjectTypekCube,
1298 Auto: true,
1299 },
1300 },
1301 Timestamp: 2400,
1302 },
1303 {
1304 ActionTaken: &submit_actions.ActionTypeT{
1305 Type: submit_actions.ActionTypePlaceObjectAction,
1306 Value: &submit_actions.PlaceObjectActionT{
1307 ObjectType: submit_actions.ObjectTypekCube,
1308 ScoreLevel: submit_actions.ScoreLevelkLow,
1309 Auto: false,
1310 },
1311 },
1312 Timestamp: 1009,
1313 },
1314 } */
1315
1316 expectedActions := []db.Action{
1317 {
Philipp Schrader4b489222023-04-15 16:40:16 -07001318 PreScouting: true,
Sabina Leaver9b4eb312023-02-20 19:58:17 -08001319 TeamNumber: "1234",
1320 MatchNumber: 4,
1321 SetNumber: 1,
1322 CompLevel: "qual",
1323 CollectedBy: "debug_cli",
1324 CompletedAction: []byte{},
Philipp Schrader670a1c82023-05-17 19:42:43 -07001325 Timestamp: 2400,
Sabina Leaver9b4eb312023-02-20 19:58:17 -08001326 },
1327 {
Philipp Schrader4b489222023-04-15 16:40:16 -07001328 PreScouting: true,
Sabina Leaver9b4eb312023-02-20 19:58:17 -08001329 TeamNumber: "1234",
1330 MatchNumber: 4,
1331 SetNumber: 1,
1332 CompLevel: "qual",
1333 CollectedBy: "debug_cli",
1334 CompletedAction: []byte{},
Philipp Schrader670a1c82023-05-17 19:42:43 -07001335 Timestamp: 1009,
Sabina Leaver9b4eb312023-02-20 19:58:17 -08001336 },
1337 }
1338
Philipp Schradere11114f2023-04-15 17:04:25 -07001339 expectedStats := []db.Stats2023{
1340 db.Stats2023{
1341 PreScouting: true,
1342 TeamNumber: "1234", MatchNumber: 4, SetNumber: 1,
1343 CompLevel: "qual", StartingQuadrant: 0, LowCubesAuto: 0,
1344 MiddleCubesAuto: 0, HighCubesAuto: 0, CubesDroppedAuto: 0,
1345 LowConesAuto: 0, MiddleConesAuto: 0, HighConesAuto: 0,
1346 ConesDroppedAuto: 0, LowCubes: 1, MiddleCubes: 0,
1347 HighCubes: 0, CubesDropped: 0, LowCones: 0,
1348 MiddleCones: 0, HighCones: 0, ConesDropped: 0, SuperchargedPieces: 0,
1349 AvgCycle: 0, Mobility: false, DockedAuto: false, EngagedAuto: false,
1350 BalanceAttemptAuto: false, Docked: false, Engaged: false,
1351 BalanceAttempt: false, CollectedBy: "debug_cli",
1352 },
1353 }
1354
Sabina Leaver9b4eb312023-02-20 19:58:17 -08001355 if !reflect.DeepEqual(expectedActions, database.actions) {
1356 t.Fatal("Expected ", expectedActions, ", but got:", database.actions)
1357 }
Philipp Schradere11114f2023-04-15 17:04:25 -07001358 if !reflect.DeepEqual(expectedStats, database.stats2023) {
1359 t.Fatal("Expected ", expectedStats, ", but got:", database.stats2023)
1360 }
Sabina Leaver9b4eb312023-02-20 19:58:17 -08001361}
1362
Filip Kujawac1ded372023-05-27 14:33:43 -07001363// Validates that we can delete stats.
1364func TestDeleteFromStats(t *testing.T) {
1365 database := MockDatabase{
1366 stats2023: []db.Stats2023{
1367 {
1368 TeamNumber: "3634", MatchNumber: 1, SetNumber: 2,
1369 CompLevel: "quals", StartingQuadrant: 3, LowCubesAuto: 10,
1370 MiddleCubesAuto: 1, HighCubesAuto: 1, CubesDroppedAuto: 0,
1371 LowConesAuto: 1, MiddleConesAuto: 2, HighConesAuto: 1,
1372 ConesDroppedAuto: 0, LowCubes: 1, MiddleCubes: 1,
1373 HighCubes: 2, CubesDropped: 1, LowCones: 1,
1374 MiddleCones: 2, HighCones: 0, ConesDropped: 1, SuperchargedPieces: 0,
1375 AvgCycle: 34, Mobility: false, DockedAuto: true, EngagedAuto: false,
1376 BalanceAttemptAuto: false, Docked: false, Engaged: false,
1377 BalanceAttempt: true, CollectedBy: "isaac",
1378 },
1379 {
1380 TeamNumber: "2343", MatchNumber: 1, SetNumber: 2,
1381 CompLevel: "quals", StartingQuadrant: 1, LowCubesAuto: 0,
1382 MiddleCubesAuto: 1, HighCubesAuto: 1, CubesDroppedAuto: 2,
1383 LowConesAuto: 0, MiddleConesAuto: 0, HighConesAuto: 0,
1384 ConesDroppedAuto: 1, LowCubes: 0, MiddleCubes: 0,
1385 HighCubes: 1, CubesDropped: 0, LowCones: 0,
1386 MiddleCones: 2, HighCones: 1, ConesDropped: 1, SuperchargedPieces: 0,
1387 AvgCycle: 53, Mobility: false, DockedAuto: false, EngagedAuto: false,
1388 BalanceAttemptAuto: true, Docked: false, Engaged: false,
1389 BalanceAttempt: true, CollectedBy: "unknown",
1390 },
1391 },
1392 actions: []db.Action{
1393 {
1394 PreScouting: true,
1395 TeamNumber: "3634",
1396 MatchNumber: 1,
1397 SetNumber: 2,
1398 CompLevel: "quals",
1399 CollectedBy: "debug_cli",
1400 CompletedAction: []byte{},
1401 Timestamp: 2400,
1402 },
1403 {
1404 PreScouting: true,
1405 TeamNumber: "2343",
1406 MatchNumber: 1,
1407 SetNumber: 2,
1408 CompLevel: "quals",
1409 CollectedBy: "debug_cli",
1410 CompletedAction: []byte{},
1411 Timestamp: 1009,
1412 },
1413 },
1414 }
1415 scoutingServer := server.NewScoutingServer()
1416 HandleRequests(&database, scoutingServer)
1417 scoutingServer.Start(8080)
1418 defer scoutingServer.Stop()
1419
1420 builder := flatbuffers.NewBuilder(1024)
1421 builder.Finish((&delete_2023_data_scouting.Delete2023DataScoutingT{
1422 CompLevel: "quals",
1423 MatchNumber: 1,
1424 SetNumber: 2,
1425 TeamNumber: "2343",
1426 }).Pack(builder))
1427
1428 _, err := debug.Delete2023DataScouting("http://localhost:8080", builder.FinishedBytes())
1429 if err != nil {
1430 t.Fatal("Failed to delete from data scouting ", err)
1431 }
1432
1433 expectedActions := []db.Action{
1434 {
1435 PreScouting: true,
1436 TeamNumber: "3634",
1437 MatchNumber: 1,
1438 SetNumber: 2,
1439 CompLevel: "quals",
1440 CollectedBy: "debug_cli",
1441 CompletedAction: []byte{},
1442 Timestamp: 2400,
1443 },
1444 }
1445
1446 expectedStats := []db.Stats2023{
1447 {
1448 TeamNumber: "3634", MatchNumber: 1, SetNumber: 2,
1449 CompLevel: "quals", StartingQuadrant: 3, LowCubesAuto: 10,
1450 MiddleCubesAuto: 1, HighCubesAuto: 1, CubesDroppedAuto: 0,
1451 LowConesAuto: 1, MiddleConesAuto: 2, HighConesAuto: 1,
1452 ConesDroppedAuto: 0, LowCubes: 1, MiddleCubes: 1,
1453 HighCubes: 2, CubesDropped: 1, LowCones: 1,
1454 MiddleCones: 2, HighCones: 0, ConesDropped: 1, SuperchargedPieces: 0,
1455 AvgCycle: 34, Mobility: false, DockedAuto: true, EngagedAuto: false,
1456 BalanceAttemptAuto: false, Docked: false, Engaged: false,
1457 BalanceAttempt: true, CollectedBy: "isaac",
1458 },
1459 }
1460
1461 if !reflect.DeepEqual(expectedActions, database.actions) {
1462 t.Fatal("Expected ", expectedActions, ", but got:", database.actions)
1463 }
1464 if !reflect.DeepEqual(expectedStats, database.stats2023) {
1465 t.Fatal("Expected ", expectedStats, ", but got:", database.stats2023)
1466 }
1467}
1468
Emily Markova8cb91312024-02-02 12:30:37 -08001469// Validates that we can delete 2024 stats.
1470func TestDeleteFromStats2024(t *testing.T) {
1471 database := MockDatabase{
1472 stats2024: []db.Stats2024{
1473 {
1474 PreScouting: false, TeamNumber: "746",
1475 MatchNumber: 3, SetNumber: 1, CompLevel: "quals", StartingQuadrant: 2,
1476 SpeakerAuto: 0, AmpAuto: 1, NotesDroppedAuto: 1, MobilityAuto: true,
Emily Markovacd156942024-04-07 19:32:28 -07001477 Speaker: 0, Amp: 1, SpeakerAmplified: 1, Shuttled: 0, OutOfField: 2,
Emily Markova6079e2f2024-02-17 13:17:24 -08001478 NotesDropped: 0, Penalties: 1, TrapNote: true, Spotlight: false, AvgCycle: 233,
Emily Markova040123c2024-02-27 09:48:37 -08001479 Park: false, OnStage: false, Harmony: true, RobotDied: false, CollectedBy: "alek",
Emily Markova8cb91312024-02-02 12:30:37 -08001480 },
1481 {
1482 PreScouting: false, TeamNumber: "244",
1483 MatchNumber: 5, SetNumber: 3, CompLevel: "quals", StartingQuadrant: 1,
1484 SpeakerAuto: 0, AmpAuto: 0, NotesDroppedAuto: 0, MobilityAuto: false,
Emily Markovacd156942024-04-07 19:32:28 -07001485 Speaker: 0, Amp: 0, SpeakerAmplified: 3, Shuttled: 0, OutOfField: 0,
Emily Markova6079e2f2024-02-17 13:17:24 -08001486 NotesDropped: 0, Penalties: 1, TrapNote: false, Spotlight: false, AvgCycle: 120,
Emily Markova040123c2024-02-27 09:48:37 -08001487 Park: false, OnStage: true, Harmony: false, RobotDied: false, CollectedBy: "kacey",
Emily Markova8cb91312024-02-02 12:30:37 -08001488 },
1489 },
1490 actions: []db.Action{
1491 {
1492 PreScouting: true,
1493 TeamNumber: "746",
1494 MatchNumber: 3,
1495 SetNumber: 1,
1496 CompLevel: "quals",
1497 CollectedBy: "debug_cli",
1498 CompletedAction: []byte{},
1499 Timestamp: 2400,
1500 },
1501 {
1502 PreScouting: true,
1503 TeamNumber: "244",
1504 MatchNumber: 5,
1505 SetNumber: 3,
1506 CompLevel: "quals",
1507 CollectedBy: "debug_cli",
1508 CompletedAction: []byte{},
1509 Timestamp: 1009,
1510 },
1511 },
1512 }
1513 scoutingServer := server.NewScoutingServer()
1514 HandleRequests(&database, scoutingServer)
1515 scoutingServer.Start(8080)
1516 defer scoutingServer.Stop()
1517
1518 builder := flatbuffers.NewBuilder(1024)
1519 builder.Finish((&delete_2024_data_scouting.Delete2024DataScoutingT{
1520 CompLevel: "quals",
1521 MatchNumber: 3,
1522 SetNumber: 1,
1523 TeamNumber: "746",
1524 }).Pack(builder))
1525
1526 _, err := debug.Delete2024DataScouting("http://localhost:8080", builder.FinishedBytes())
1527 if err != nil {
1528 t.Fatal("Failed to delete from data scouting 2024", err)
1529 }
1530
1531 expectedActions := []db.Action{
1532 {
1533 PreScouting: true,
1534 TeamNumber: "244",
1535 MatchNumber: 5,
1536 SetNumber: 3,
1537 CompLevel: "quals",
1538 CollectedBy: "debug_cli",
1539 CompletedAction: []byte{},
1540 Timestamp: 1009,
1541 },
1542 }
1543
1544 expectedStats := []db.Stats2024{
1545 {
1546 PreScouting: false, TeamNumber: "244",
1547 MatchNumber: 5, SetNumber: 3, CompLevel: "quals", StartingQuadrant: 1,
1548 SpeakerAuto: 0, AmpAuto: 0, NotesDroppedAuto: 0, MobilityAuto: false,
Emily Markovacd156942024-04-07 19:32:28 -07001549 Speaker: 0, Amp: 0, SpeakerAmplified: 3, Shuttled: 0, OutOfField: 0,
Emily Markova6079e2f2024-02-17 13:17:24 -08001550 NotesDropped: 0, Penalties: 1, TrapNote: false, Spotlight: false, AvgCycle: 120,
Emily Markova040123c2024-02-27 09:48:37 -08001551 Park: false, OnStage: true, Harmony: false, RobotDied: false, CollectedBy: "kacey",
Emily Markova8cb91312024-02-02 12:30:37 -08001552 },
1553 }
1554
1555 if !reflect.DeepEqual(expectedActions, database.actions) {
1556 t.Fatal("Expected ", expectedActions, ", but got:", database.actions)
1557 }
1558 if !reflect.DeepEqual(expectedStats, database.stats2024) {
1559 t.Fatal("Expected ", expectedStats, ", but got:", database.stats2024)
1560 }
1561}
1562
Philipp Schrader8747f1b2022-02-23 23:56:22 -08001563// A mocked database we can use for testing. Add functionality to this as
1564// needed for your tests.
1565
Philipp Schradercbf5c6a2022-02-27 23:25:19 -08001566type MockDatabase struct {
Emily Markovabf24c9e2023-02-08 20:31:11 -08001567 matches []db.TeamMatch
Filip Kujawa210a03b2022-11-24 14:41:11 -08001568 notes []db.NotesData
1569 shiftSchedule []db.Shift
1570 driver_ranking []db.DriverRankingData
Emily Markova290147d2023-03-03 22:40:06 -08001571 stats2023 []db.Stats2023
Emily Markova8cb91312024-02-02 12:30:37 -08001572 stats2024 []db.Stats2024
Sabina Leaver9b4eb312023-02-20 19:58:17 -08001573 actions []db.Action
Emily Markovafaecfe12023-07-01 12:40:03 -07001574 images []db.PitImage
Philipp Schradercbf5c6a2022-02-27 23:25:19 -08001575}
Philipp Schrader8747f1b2022-02-23 23:56:22 -08001576
Emily Markovabf24c9e2023-02-08 20:31:11 -08001577func (database *MockDatabase) AddToMatch(match db.TeamMatch) error {
Philipp Schraderd3fac192022-03-02 20:35:46 -08001578 database.matches = append(database.matches, match)
Philipp Schrader8747f1b2022-02-23 23:56:22 -08001579 return nil
1580}
1581
Emily Markova290147d2023-03-03 22:40:06 -08001582func (database *MockDatabase) AddToStats2023(stats2023 db.Stats2023) error {
1583 database.stats2023 = append(database.stats2023, stats2023)
1584 return nil
1585}
Emily Markova8cb91312024-02-02 12:30:37 -08001586
1587func (database *MockDatabase) AddToStats2024(stats2024 db.Stats2024) error {
1588 database.stats2024 = append(database.stats2024, stats2024)
1589 return nil
1590}
Emily Markovabf24c9e2023-02-08 20:31:11 -08001591func (database *MockDatabase) ReturnMatches() ([]db.TeamMatch, error) {
Philipp Schradercbf5c6a2022-02-27 23:25:19 -08001592 return database.matches, nil
Philipp Schrader8747f1b2022-02-23 23:56:22 -08001593}
1594
Emily Markova290147d2023-03-03 22:40:06 -08001595func (database *MockDatabase) ReturnStats2023() ([]db.Stats2023, error) {
1596 return database.stats2023, nil
1597}
1598
Emily Markova8cb91312024-02-02 12:30:37 -08001599func (database *MockDatabase) ReturnStats2024() ([]db.Stats2024, error) {
1600 return database.stats2024, nil
1601}
1602
Filip Kujawaf3f9def2023-04-20 13:46:46 -07001603func (database *MockDatabase) ReturnStats2023ForTeam(teamNumber string, matchNumber int32, setNumber int32, compLevel string, preScouting bool) ([]db.Stats2023, error) {
Philipp Schrader0f7b6362023-03-11 14:02:48 -08001604 var results []db.Stats2023
1605 for _, stats := range database.stats2023 {
Filip Kujawaf3f9def2023-04-20 13:46:46 -07001606 if stats.TeamNumber == teamNumber && stats.MatchNumber == matchNumber && stats.SetNumber == setNumber && stats.CompLevel == compLevel && stats.PreScouting == preScouting {
Philipp Schrader0f7b6362023-03-11 14:02:48 -08001607 results = append(results, stats)
1608 }
1609 }
1610 return results, nil
1611}
1612
Emily Markova8cb91312024-02-02 12:30:37 -08001613func (database *MockDatabase) ReturnStats2024ForTeam(teamNumber string, matchNumber int32, setNumber int32, compLevel string, preScouting bool) ([]db.Stats2024, error) {
1614 var results []db.Stats2024
1615 for _, stats := range database.stats2024 {
1616 if stats.TeamNumber == teamNumber && stats.MatchNumber == matchNumber && stats.SetNumber == setNumber && stats.CompLevel == compLevel && stats.PreScouting == preScouting {
1617 results = append(results, stats)
1618 }
1619 }
1620 return results, nil
1621}
1622
Emily Markovae68b7632023-12-30 14:17:55 -08001623func (database *MockDatabase) QueryNotes(requestedTeam string) ([]string, error) {
Alex Perry81f96ba2022-03-13 18:26:19 -07001624 var results []string
1625 for _, data := range database.notes {
1626 if data.TeamNumber == requestedTeam {
Philipp Schradereecb8962022-06-01 21:02:42 -07001627 results = append(results, data.Notes)
Alex Perry81f96ba2022-03-13 18:26:19 -07001628 }
1629 }
Philipp Schradereecb8962022-06-01 21:02:42 -07001630 return results, nil
Alex Perry81f96ba2022-03-13 18:26:19 -07001631}
1632
Filip Kujawaf947cb42022-11-21 10:00:30 -08001633func (database *MockDatabase) AddNotes(data db.NotesData) error {
1634 database.notes = append(database.notes, data)
Alex Perry81f96ba2022-03-13 18:26:19 -07001635 return nil
1636}
1637
Filip Kujawaf882e022022-12-14 13:14:08 -08001638func (database *MockDatabase) ReturnAllNotes() ([]db.NotesData, error) {
1639 return database.notes, nil
1640}
1641
Milo Lin1d59f0c2022-06-22 20:30:58 -07001642func (database *MockDatabase) AddToShift(data db.Shift) error {
1643 database.shiftSchedule = append(database.shiftSchedule, data)
1644 return nil
1645}
1646
1647func (database *MockDatabase) ReturnAllShifts() ([]db.Shift, error) {
1648 return database.shiftSchedule, nil
1649}
1650
1651func (database *MockDatabase) QueryAllShifts(int) ([]db.Shift, error) {
1652 return []db.Shift{}, nil
1653}
1654
Emily Markovafaecfe12023-07-01 12:40:03 -07001655func (database *MockDatabase) QueryPitImages(requestedTeam string) ([]db.RequestedPitImage, error) {
1656 var results []db.RequestedPitImage
1657 for _, data := range database.images {
1658 if data.TeamNumber == requestedTeam {
1659 results = append(results, db.RequestedPitImage{
1660 TeamNumber: data.TeamNumber,
1661 ImagePath: data.ImagePath,
1662 CheckSum: data.CheckSum,
1663 })
1664 }
1665 }
1666 return results, nil
1667}
1668
Filip Kujawa210a03b2022-11-24 14:41:11 -08001669func (database *MockDatabase) AddDriverRanking(data db.DriverRankingData) error {
1670 database.driver_ranking = append(database.driver_ranking, data)
1671 return nil
1672}
1673
Filip Kujawaf882e022022-12-14 13:14:08 -08001674func (database *MockDatabase) ReturnAllDriverRankings() ([]db.DriverRankingData, error) {
1675 return database.driver_ranking, nil
1676}
Sabina Leaver9b4eb312023-02-20 19:58:17 -08001677
1678func (database *MockDatabase) AddAction(action db.Action) error {
1679 database.actions = append(database.actions, action)
1680 return nil
1681}
1682
Emily Markovafaecfe12023-07-01 12:40:03 -07001683func (database *MockDatabase) AddPitImage(pitImage db.PitImage) error {
1684 database.images = append(database.images, pitImage)
1685 return nil
1686}
1687
Sabina Leaver9b4eb312023-02-20 19:58:17 -08001688func (database *MockDatabase) ReturnActions() ([]db.Action, error) {
1689 return database.actions, nil
1690}
Filip Kujawac1ded372023-05-27 14:33:43 -07001691
Emily Markova8e39f452023-12-23 12:17:30 -08001692func (database *MockDatabase) ReturnPitImages() ([]db.PitImage, error) {
1693 return database.images, nil
1694}
1695
Filip Kujawac1ded372023-05-27 14:33:43 -07001696func (database *MockDatabase) DeleteFromStats(compLevel_ string, matchNumber_ int32, setNumber_ int32, teamNumber_ string) error {
1697 for i, stat := range database.stats2023 {
1698 if stat.CompLevel == compLevel_ &&
1699 stat.MatchNumber == matchNumber_ &&
1700 stat.SetNumber == setNumber_ &&
1701 stat.TeamNumber == teamNumber_ {
1702 // Match found, remove the element from the array.
1703 database.stats2023 = append(database.stats2023[:i], database.stats2023[i+1:]...)
1704 }
1705 }
1706 return nil
1707}
1708
Emily Markova8cb91312024-02-02 12:30:37 -08001709func (database *MockDatabase) DeleteFromStats2024(compLevel_ string, matchNumber_ int32, setNumber_ int32, teamNumber_ string) error {
1710 for i, stat := range database.stats2024 {
1711 if stat.CompLevel == compLevel_ &&
1712 stat.MatchNumber == matchNumber_ &&
1713 stat.SetNumber == setNumber_ &&
1714 stat.TeamNumber == teamNumber_ {
1715 // Match found, remove the element from the array.
1716 database.stats2024 = append(database.stats2024[:i], database.stats2024[i+1:]...)
1717 }
1718 }
1719 return nil
1720}
1721
Filip Kujawac1ded372023-05-27 14:33:43 -07001722func (database *MockDatabase) DeleteFromActions(compLevel_ string, matchNumber_ int32, setNumber_ int32, teamNumber_ string) error {
1723 for i, action := range database.actions {
1724 if action.CompLevel == compLevel_ &&
1725 action.MatchNumber == matchNumber_ &&
1726 action.SetNumber == setNumber_ &&
1727 action.TeamNumber == teamNumber_ {
1728 // Match found, remove the element from the array.
1729 database.actions = append(database.actions[:i], database.actions[i+1:]...)
1730 }
1731 }
1732 return nil
1733}