blob: 20a63ca58582993408b2c2c29f4e783bafd53668 [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 Markova290147d2023-03-03 22:40:06 -080011 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_2023_data_scouting"
12 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_2023_data_scouting_response"
Filip Kujawaf882e022022-12-14 13:14:08 -080013 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_all_driver_rankings"
14 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_all_driver_rankings_response"
Philipp Schradercbf5c6a2022-02-27 23:25:19 -080015 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_all_matches"
16 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_all_matches_response"
Filip Kujawaf882e022022-12-14 13:14:08 -080017 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_all_notes"
18 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_all_notes_response"
Alex Perry81f96ba2022-03-13 18:26:19 -070019 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_notes_for_team"
Milo Lin1d59f0c2022-06-22 20:30:58 -070020 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_shift_schedule"
21 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_shift_schedule_response"
Emily Markova1abe9782023-03-11 19:45:38 -080022 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/submit_actions"
Filip Kujawa210a03b2022-11-24 14:41:11 -080023 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/submit_driver_ranking"
Alex Perry81f96ba2022-03-13 18:26:19 -070024 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/submit_notes"
Milo Lin1d59f0c2022-06-22 20:30:58 -070025 "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/submit_shift_schedule"
Philipp Schradercdb5cfc2022-02-20 14:57:07 -080026 "github.com/frc971/971-Robot-Code/scouting/webserver/server"
27 flatbuffers "github.com/google/flatbuffers/go"
28)
29
30// Validates that an unhandled address results in a 404.
31func Test404(t *testing.T) {
Philipp Schrader8747f1b2022-02-23 23:56:22 -080032 db := MockDatabase{}
Philipp Schradercdb5cfc2022-02-20 14:57:07 -080033 scoutingServer := server.NewScoutingServer()
Philipp Schrader43c730b2023-02-26 20:27:44 -080034 HandleRequests(&db, scoutingServer)
Philipp Schradercdb5cfc2022-02-20 14:57:07 -080035 scoutingServer.Start(8080)
36 defer scoutingServer.Stop()
37
38 resp, err := http.Get("http://localhost:8080/requests/foo")
39 if err != nil {
40 t.Fatalf("Failed to get data: %v", err)
41 }
42 if resp.StatusCode != http.StatusNotFound {
43 t.Fatalf("Expected error code 404, but got %d instead", resp.Status)
44 }
45}
46
Philipp Schradercbf5c6a2022-02-27 23:25:19 -080047// Validates that we can request the full match list.
48func TestRequestAllMatches(t *testing.T) {
49 db := MockDatabase{
Emily Markovabf24c9e2023-02-08 20:31:11 -080050 matches: []db.TeamMatch{
Philipp Schradercbf5c6a2022-02-27 23:25:19 -080051 {
Emily Markovaabcac6e2023-02-18 17:50:03 -080052 MatchNumber: 1, SetNumber: 1, CompLevel: "qm",
Emily Markovab8551572023-03-22 19:49:39 -070053 Alliance: "R", AlliancePosition: 1, TeamNumber: "5",
Emily Markovabf24c9e2023-02-08 20:31:11 -080054 },
55 {
Emily Markovaabcac6e2023-02-18 17:50:03 -080056 MatchNumber: 1, SetNumber: 1, CompLevel: "qm",
Emily Markovab8551572023-03-22 19:49:39 -070057 Alliance: "R", AlliancePosition: 2, TeamNumber: "42",
Emily Markovabf24c9e2023-02-08 20:31:11 -080058 },
59 {
Emily Markovaabcac6e2023-02-18 17:50:03 -080060 MatchNumber: 1, SetNumber: 1, CompLevel: "qm",
Emily Markovab8551572023-03-22 19:49:39 -070061 Alliance: "R", AlliancePosition: 3, TeamNumber: "600",
Emily Markovabf24c9e2023-02-08 20:31:11 -080062 },
63 {
Emily Markovaabcac6e2023-02-18 17:50:03 -080064 MatchNumber: 1, SetNumber: 1, CompLevel: "qm",
Emily Markovab8551572023-03-22 19:49:39 -070065 Alliance: "B", AlliancePosition: 1, TeamNumber: "971",
Emily Markovabf24c9e2023-02-08 20:31:11 -080066 },
67 {
Emily Markovaabcac6e2023-02-18 17:50:03 -080068 MatchNumber: 1, SetNumber: 1, CompLevel: "qm",
Emily Markovab8551572023-03-22 19:49:39 -070069 Alliance: "B", AlliancePosition: 2, TeamNumber: "400",
Emily Markovabf24c9e2023-02-08 20:31:11 -080070 },
71 {
Emily Markovaabcac6e2023-02-18 17:50:03 -080072 MatchNumber: 1, SetNumber: 1, CompLevel: "qm",
Emily Markovab8551572023-03-22 19:49:39 -070073 Alliance: "B", AlliancePosition: 3, TeamNumber: "200",
Philipp Schradercbf5c6a2022-02-27 23:25:19 -080074 },
75 {
Emily Markovaabcac6e2023-02-18 17:50:03 -080076 MatchNumber: 2, SetNumber: 1, CompLevel: "qm",
Emily Markovab8551572023-03-22 19:49:39 -070077 Alliance: "R", AlliancePosition: 1, TeamNumber: "6",
Emily Markovabf24c9e2023-02-08 20:31:11 -080078 },
79 {
Emily Markovaabcac6e2023-02-18 17:50:03 -080080 MatchNumber: 2, SetNumber: 1, CompLevel: "qm",
Emily Markovab8551572023-03-22 19:49:39 -070081 Alliance: "R", AlliancePosition: 2, TeamNumber: "43",
Emily Markovabf24c9e2023-02-08 20:31:11 -080082 },
83 {
Emily Markovaabcac6e2023-02-18 17:50:03 -080084 MatchNumber: 2, SetNumber: 1, CompLevel: "qm",
Emily Markovab8551572023-03-22 19:49:39 -070085 Alliance: "R", AlliancePosition: 3, TeamNumber: "601",
Emily Markovabf24c9e2023-02-08 20:31:11 -080086 },
87 {
Emily Markovaabcac6e2023-02-18 17:50:03 -080088 MatchNumber: 2, SetNumber: 1, CompLevel: "qm",
Emily Markovab8551572023-03-22 19:49:39 -070089 Alliance: "B", AlliancePosition: 1, TeamNumber: "972",
Emily Markovabf24c9e2023-02-08 20:31:11 -080090 },
91 {
Emily Markovaabcac6e2023-02-18 17:50:03 -080092 MatchNumber: 2, SetNumber: 1, CompLevel: "qm",
Emily Markovab8551572023-03-22 19:49:39 -070093 Alliance: "B", AlliancePosition: 2, TeamNumber: "401",
Emily Markovabf24c9e2023-02-08 20:31:11 -080094 },
95 {
Emily Markovaabcac6e2023-02-18 17:50:03 -080096 MatchNumber: 2, SetNumber: 1, CompLevel: "qm",
Emily Markovab8551572023-03-22 19:49:39 -070097 Alliance: "B", AlliancePosition: 3, TeamNumber: "201",
Philipp Schradercbf5c6a2022-02-27 23:25:19 -080098 },
99 {
Emily Markovaabcac6e2023-02-18 17:50:03 -0800100 MatchNumber: 3, SetNumber: 1, CompLevel: "qm",
Emily Markovab8551572023-03-22 19:49:39 -0700101 Alliance: "R", AlliancePosition: 1, TeamNumber: "7",
Emily Markovabf24c9e2023-02-08 20:31:11 -0800102 },
103 {
Emily Markovaabcac6e2023-02-18 17:50:03 -0800104 MatchNumber: 3, SetNumber: 1, CompLevel: "qm",
Emily Markovab8551572023-03-22 19:49:39 -0700105 Alliance: "R", AlliancePosition: 2, TeamNumber: "44",
Emily Markovabf24c9e2023-02-08 20:31:11 -0800106 },
107 {
Emily Markovaabcac6e2023-02-18 17:50:03 -0800108 MatchNumber: 3, SetNumber: 1, CompLevel: "qm",
Emily Markovab8551572023-03-22 19:49:39 -0700109 Alliance: "R", AlliancePosition: 3, TeamNumber: "602",
Emily Markovabf24c9e2023-02-08 20:31:11 -0800110 },
111 {
Emily Markovaabcac6e2023-02-18 17:50:03 -0800112 MatchNumber: 3, SetNumber: 1, CompLevel: "qm",
Emily Markovab8551572023-03-22 19:49:39 -0700113 Alliance: "B", AlliancePosition: 1, TeamNumber: "973",
Emily Markovabf24c9e2023-02-08 20:31:11 -0800114 },
115 {
Emily Markovaabcac6e2023-02-18 17:50:03 -0800116 MatchNumber: 3, SetNumber: 1, CompLevel: "qm",
Emily Markovab8551572023-03-22 19:49:39 -0700117 Alliance: "B", AlliancePosition: 2, TeamNumber: "402",
Emily Markovabf24c9e2023-02-08 20:31:11 -0800118 },
119 {
Emily Markovaabcac6e2023-02-18 17:50:03 -0800120 MatchNumber: 3, SetNumber: 1, CompLevel: "qm",
Emily Markovab8551572023-03-22 19:49:39 -0700121 Alliance: "B", AlliancePosition: 3, TeamNumber: "202",
Philipp Schradercbf5c6a2022-02-27 23:25:19 -0800122 },
123 },
Philipp Schrader0f7b6362023-03-11 14:02:48 -0800124 // Pretend that we have some data scouting data.
125 stats2023: []db.Stats2023{
126 {
127 TeamNumber: "5", MatchNumber: 1, SetNumber: 1,
128 CompLevel: "qm", StartingQuadrant: 3, LowCubesAuto: 10,
129 MiddleCubesAuto: 1, HighCubesAuto: 1, CubesDroppedAuto: 0,
130 LowConesAuto: 1, MiddleConesAuto: 2, HighConesAuto: 1,
131 ConesDroppedAuto: 0, LowCubes: 1, MiddleCubes: 1,
132 HighCubes: 2, CubesDropped: 1, LowCones: 1,
Filip Kujawa7a045e72023-04-13 08:41:09 -0700133 MiddleCones: 2, HighCones: 0, ConesDropped: 1, SuperchargedPieces: 0,
Filip Kujawa0b4b1e52023-04-15 14:05:40 -0700134 AvgCycle: 34, Mobility: false, DockedAuto: true, EngagedAuto: true,
Emily Markova63c63f62023-03-29 20:57:35 -0700135 BalanceAttemptAuto: false, Docked: false, Engaged: false,
136 BalanceAttempt: false, CollectedBy: "alex",
Philipp Schrader0f7b6362023-03-11 14:02:48 -0800137 },
138 {
139 TeamNumber: "973", MatchNumber: 3, SetNumber: 1,
140 CompLevel: "qm", StartingQuadrant: 1, LowCubesAuto: 0,
141 MiddleCubesAuto: 1, HighCubesAuto: 1, CubesDroppedAuto: 2,
142 LowConesAuto: 0, MiddleConesAuto: 0, HighConesAuto: 0,
143 ConesDroppedAuto: 1, LowCubes: 0, MiddleCubes: 0,
144 HighCubes: 1, CubesDropped: 0, LowCones: 0,
Filip Kujawa7a045e72023-04-13 08:41:09 -0700145 MiddleCones: 2, HighCones: 1, ConesDropped: 1, SuperchargedPieces: 0,
Filip Kujawa0b4b1e52023-04-15 14:05:40 -0700146 AvgCycle: 53, Mobility: true, DockedAuto: true, EngagedAuto: false,
Emily Markova63c63f62023-03-29 20:57:35 -0700147 BalanceAttemptAuto: false, Docked: false, Engaged: false,
148 BalanceAttempt: true, CollectedBy: "bob",
Philipp Schrader0f7b6362023-03-11 14:02:48 -0800149 },
150 },
Philipp Schradercbf5c6a2022-02-27 23:25:19 -0800151 }
152 scoutingServer := server.NewScoutingServer()
Philipp Schrader43c730b2023-02-26 20:27:44 -0800153 HandleRequests(&db, scoutingServer)
Philipp Schradercbf5c6a2022-02-27 23:25:19 -0800154 scoutingServer.Start(8080)
155 defer scoutingServer.Stop()
156
157 builder := flatbuffers.NewBuilder(1024)
158 builder.Finish((&request_all_matches.RequestAllMatchesT{}).Pack(builder))
159
160 response, err := debug.RequestAllMatches("http://localhost:8080", builder.FinishedBytes())
161 if err != nil {
162 t.Fatal("Failed to request all matches: ", err)
163 }
164
165 expected := request_all_matches_response.RequestAllMatchesResponseT{
166 MatchList: []*request_all_matches_response.MatchT{
Philipp Schrader30b4a682022-04-16 14:36:17 -0700167 // MatchNumber, SetNumber, CompLevel
Philipp Schradercbf5c6a2022-02-27 23:25:19 -0800168 // R1, R2, R3, B1, B2, B3
169 {
Emily Markovaabcac6e2023-02-18 17:50:03 -0800170 1, 1, "qm",
Emily Markovab8551572023-03-22 19:49:39 -0700171 "5", "42", "600", "971", "400", "200",
Philipp Schrader0f7b6362023-03-11 14:02:48 -0800172 &request_all_matches_response.ScoutedLevelT{
173 // The R1 team has already been data
174 // scouted.
175 true, false, false, false, false, false,
176 },
Philipp Schradercbf5c6a2022-02-27 23:25:19 -0800177 },
178 {
Emily Markovaabcac6e2023-02-18 17:50:03 -0800179 2, 1, "qm",
Emily Markovab8551572023-03-22 19:49:39 -0700180 "6", "43", "601", "972", "401", "201",
Philipp Schrader0f7b6362023-03-11 14:02:48 -0800181 &request_all_matches_response.ScoutedLevelT{
182 false, false, false, false, false, false,
183 },
Philipp Schradercbf5c6a2022-02-27 23:25:19 -0800184 },
185 {
Emily Markovaabcac6e2023-02-18 17:50:03 -0800186 3, 1, "qm",
Emily Markovab8551572023-03-22 19:49:39 -0700187 "7", "44", "602", "973", "402", "202",
Philipp Schrader0f7b6362023-03-11 14:02:48 -0800188 &request_all_matches_response.ScoutedLevelT{
189 // The B1 team has already been data
190 // scouted.
191 false, false, false, true, false, false,
192 },
Philipp Schradercbf5c6a2022-02-27 23:25:19 -0800193 },
194 },
195 }
196 if len(expected.MatchList) != len(response.MatchList) {
197 t.Fatal("Expected ", expected, ", but got ", *response)
198 }
199 for i, match := range expected.MatchList {
200 if !reflect.DeepEqual(*match, *response.MatchList[i]) {
201 t.Fatal("Expected for match", i, ":", *match, ", but got:", *response.MatchList[i])
202 }
203 }
Philipp Schrader30005e42022-03-06 13:53:58 -0800204
Philipp Schradercbf5c6a2022-02-27 23:25:19 -0800205}
206
Emily Markova290147d2023-03-03 22:40:06 -0800207// Validates that we can request the 2023 stats.
208func TestRequest2023DataScouting(t *testing.T) {
209 db := MockDatabase{
210 stats2023: []db.Stats2023{
211 {
212 TeamNumber: "3634", MatchNumber: 1, SetNumber: 2,
213 CompLevel: "quals", StartingQuadrant: 3, LowCubesAuto: 10,
214 MiddleCubesAuto: 1, HighCubesAuto: 1, CubesDroppedAuto: 0,
215 LowConesAuto: 1, MiddleConesAuto: 2, HighConesAuto: 1,
216 ConesDroppedAuto: 0, LowCubes: 1, MiddleCubes: 1,
217 HighCubes: 2, CubesDropped: 1, LowCones: 1,
Filip Kujawa7a045e72023-04-13 08:41:09 -0700218 MiddleCones: 2, HighCones: 0, ConesDropped: 1, SuperchargedPieces: 0,
Filip Kujawa0b4b1e52023-04-15 14:05:40 -0700219 AvgCycle: 34, Mobility: false, DockedAuto: true, EngagedAuto: false,
Emily Markova63c63f62023-03-29 20:57:35 -0700220 BalanceAttemptAuto: false, Docked: false, Engaged: false,
221 BalanceAttempt: true, CollectedBy: "isaac",
Emily Markova290147d2023-03-03 22:40:06 -0800222 },
223 {
224 TeamNumber: "2343", MatchNumber: 1, SetNumber: 2,
225 CompLevel: "quals", StartingQuadrant: 1, LowCubesAuto: 0,
226 MiddleCubesAuto: 1, HighCubesAuto: 1, CubesDroppedAuto: 2,
227 LowConesAuto: 0, MiddleConesAuto: 0, HighConesAuto: 0,
228 ConesDroppedAuto: 1, LowCubes: 0, MiddleCubes: 0,
229 HighCubes: 1, CubesDropped: 0, LowCones: 0,
Filip Kujawa7a045e72023-04-13 08:41:09 -0700230 MiddleCones: 2, HighCones: 1, ConesDropped: 1, SuperchargedPieces: 0,
Filip Kujawa0b4b1e52023-04-15 14:05:40 -0700231 AvgCycle: 53, Mobility: false, DockedAuto: false, EngagedAuto: false,
Emily Markova63c63f62023-03-29 20:57:35 -0700232 BalanceAttemptAuto: true, Docked: false, Engaged: false,
233 BalanceAttempt: true, CollectedBy: "unknown",
Emily Markova290147d2023-03-03 22:40:06 -0800234 },
235 },
236 }
237 scoutingServer := server.NewScoutingServer()
238 HandleRequests(&db, scoutingServer)
239 scoutingServer.Start(8080)
240 defer scoutingServer.Stop()
241
242 builder := flatbuffers.NewBuilder(1024)
243 builder.Finish((&request_2023_data_scouting.Request2023DataScoutingT{}).Pack(builder))
244
245 response, err := debug.Request2023DataScouting("http://localhost:8080", builder.FinishedBytes())
246 if err != nil {
247 t.Fatal("Failed to request all matches: ", err)
248 }
249
250 expected := request_2023_data_scouting_response.Request2023DataScoutingResponseT{
251 StatsList: []*request_2023_data_scouting_response.Stats2023T{
252 {
253 TeamNumber: "3634", MatchNumber: 1, SetNumber: 2,
254 CompLevel: "quals", StartingQuadrant: 3, LowCubesAuto: 10,
255 MiddleCubesAuto: 1, HighCubesAuto: 1, CubesDroppedAuto: 0,
256 LowConesAuto: 1, MiddleConesAuto: 2, HighConesAuto: 1,
257 ConesDroppedAuto: 0, LowCubes: 1, MiddleCubes: 1,
258 HighCubes: 2, CubesDropped: 1, LowCones: 1,
Filip Kujawa7a045e72023-04-13 08:41:09 -0700259 MiddleCones: 2, HighCones: 0, ConesDropped: 1, SuperchargedPieces: 0,
Filip Kujawa0b4b1e52023-04-15 14:05:40 -0700260 AvgCycle: 34, Mobility: false, DockedAuto: true, EngagedAuto: false,
Emily Markova63c63f62023-03-29 20:57:35 -0700261 BalanceAttemptAuto: false, Docked: false, Engaged: false,
262 BalanceAttempt: true, CollectedBy: "isaac",
Emily Markova290147d2023-03-03 22:40:06 -0800263 },
264 {
265 TeamNumber: "2343", MatchNumber: 1, SetNumber: 2,
266 CompLevel: "quals", StartingQuadrant: 1, LowCubesAuto: 0,
267 MiddleCubesAuto: 1, HighCubesAuto: 1, CubesDroppedAuto: 2,
268 LowConesAuto: 0, MiddleConesAuto: 0, HighConesAuto: 0,
269 ConesDroppedAuto: 1, LowCubes: 0, MiddleCubes: 0,
270 HighCubes: 1, CubesDropped: 0, LowCones: 0,
Filip Kujawa7a045e72023-04-13 08:41:09 -0700271 MiddleCones: 2, HighCones: 1, ConesDropped: 1, SuperchargedPieces: 0,
Filip Kujawa0b4b1e52023-04-15 14:05:40 -0700272 AvgCycle: 53, Mobility: false, DockedAuto: false, EngagedAuto: false,
Emily Markova63c63f62023-03-29 20:57:35 -0700273 BalanceAttemptAuto: true, Docked: false, Engaged: false,
274 BalanceAttempt: true, CollectedBy: "unknown",
Emily Markova290147d2023-03-03 22:40:06 -0800275 },
276 },
277 }
278 if len(expected.StatsList) != len(response.StatsList) {
279 t.Fatal("Expected ", expected, ", but got ", *response)
280 }
281 for i, match := range expected.StatsList {
282 if !reflect.DeepEqual(*match, *response.StatsList[i]) {
283 t.Fatal("Expected for stats", i, ":", *match, ", but got:", *response.StatsList[i])
284 }
285 }
286}
287
Emily Markova1abe9782023-03-11 19:45:38 -0800288// Validates that we can request the 2023 stats.
289func TestConvertActionsToStat(t *testing.T) {
290 builder := flatbuffers.NewBuilder(1024)
291 builder.Finish((&submit_actions.SubmitActionsT{
292 TeamNumber: "4244",
293 MatchNumber: 3,
294 SetNumber: 1,
295 CompLevel: "quals",
Emily Markova1abe9782023-03-11 19:45:38 -0800296 ActionsList: []*submit_actions.ActionT{
297 {
298 ActionTaken: &submit_actions.ActionTypeT{
299 Type: submit_actions.ActionTypeStartMatchAction,
300 Value: &submit_actions.StartMatchActionT{
301 Position: 1,
302 },
303 },
304 Timestamp: 0,
305 },
306 {
307 ActionTaken: &submit_actions.ActionTypeT{
308 Type: submit_actions.ActionTypePickupObjectAction,
309 Value: &submit_actions.PickupObjectActionT{
310 ObjectType: submit_actions.ObjectTypekCube,
311 Auto: true,
312 },
313 },
314 Timestamp: 400,
315 },
316 {
317 ActionTaken: &submit_actions.ActionTypeT{
318 Type: submit_actions.ActionTypePickupObjectAction,
319 Value: &submit_actions.PickupObjectActionT{
320 ObjectType: submit_actions.ObjectTypekCube,
321 Auto: true,
322 },
323 },
324 Timestamp: 800,
325 },
326 {
327 ActionTaken: &submit_actions.ActionTypeT{
328 Type: submit_actions.ActionTypePlaceObjectAction,
329 Value: &submit_actions.PlaceObjectActionT{
330 ObjectType: submit_actions.ObjectTypekCube,
331 ScoreLevel: submit_actions.ScoreLevelkLow,
332 Auto: true,
333 },
334 },
335 Timestamp: 2000,
336 },
337 {
338 ActionTaken: &submit_actions.ActionTypeT{
Filip Kujawa0b4b1e52023-04-15 14:05:40 -0700339 Type: submit_actions.ActionTypeMobilityAction,
340 Value: &submit_actions.MobilityActionT{
341 Mobility: true,
342 },
343 },
344 Timestamp: 2200,
345 },
346 {
347 ActionTaken: &submit_actions.ActionTypeT{
Emily Markova46a69bf2023-03-22 20:45:52 -0700348 Type: submit_actions.ActionTypeAutoBalanceAction,
349 Value: &submit_actions.AutoBalanceActionT{
Emily Markova63c63f62023-03-29 20:57:35 -0700350 Docked: true,
351 Engaged: true,
352 BalanceAttempt: false,
Emily Markova46a69bf2023-03-22 20:45:52 -0700353 },
354 },
355 Timestamp: 2400,
356 },
357 {
358 ActionTaken: &submit_actions.ActionTypeT{
Emily Markova1abe9782023-03-11 19:45:38 -0800359 Type: submit_actions.ActionTypePickupObjectAction,
360 Value: &submit_actions.PickupObjectActionT{
361 ObjectType: submit_actions.ObjectTypekCone,
362 Auto: false,
363 },
364 },
365 Timestamp: 2800,
366 },
367 {
368 ActionTaken: &submit_actions.ActionTypeT{
369 Type: submit_actions.ActionTypePlaceObjectAction,
370 Value: &submit_actions.PlaceObjectActionT{
371 ObjectType: submit_actions.ObjectTypekCone,
372 ScoreLevel: submit_actions.ScoreLevelkHigh,
373 Auto: false,
374 },
375 },
376 Timestamp: 3100,
377 },
Emily Markova46a69bf2023-03-22 20:45:52 -0700378 {
379 ActionTaken: &submit_actions.ActionTypeT{
Filip Kujawa7a045e72023-04-13 08:41:09 -0700380 Type: submit_actions.ActionTypePickupObjectAction,
381 Value: &submit_actions.PickupObjectActionT{
382 ObjectType: submit_actions.ObjectTypekCube,
383 Auto: false,
384 },
385 },
386 Timestamp: 3500,
387 },
388 {
389 ActionTaken: &submit_actions.ActionTypeT{
390 Type: submit_actions.ActionTypePlaceObjectAction,
391 Value: &submit_actions.PlaceObjectActionT{
392 ObjectType: submit_actions.ObjectTypekCube,
393 ScoreLevel: submit_actions.ScoreLevelkSupercharged,
394 Auto: false,
395 },
396 },
397 Timestamp: 3900,
398 },
399 {
400 ActionTaken: &submit_actions.ActionTypeT{
Emily Markova46a69bf2023-03-22 20:45:52 -0700401 Type: submit_actions.ActionTypeEndMatchAction,
402 Value: &submit_actions.EndMatchActionT{
Emily Markova63c63f62023-03-29 20:57:35 -0700403 Docked: true,
404 Engaged: false,
405 BalanceAttempt: true,
Emily Markova46a69bf2023-03-22 20:45:52 -0700406 },
407 },
Filip Kujawa7a045e72023-04-13 08:41:09 -0700408 Timestamp: 4200,
Emily Markova46a69bf2023-03-22 20:45:52 -0700409 },
Emily Markova1abe9782023-03-11 19:45:38 -0800410 },
Philipp Schrader4b489222023-04-15 16:40:16 -0700411 PreScouting: false,
Emily Markova1abe9782023-03-11 19:45:38 -0800412 }).Pack(builder))
413
414 submitActions := submit_actions.GetRootAsSubmitActions(builder.FinishedBytes(), 0)
415 response, err := ConvertActionsToStat(submitActions)
416
417 if err != nil {
418 t.Fatal("Failed to convert actions to stats: ", err)
419 }
420
421 expected := db.Stats2023{
Philipp Schrader4b489222023-04-15 16:40:16 -0700422 PreScouting: false,
423 TeamNumber: "4244", MatchNumber: 3, SetNumber: 1,
Emily Markova1abe9782023-03-11 19:45:38 -0800424 CompLevel: "quals", StartingQuadrant: 1, LowCubesAuto: 1,
425 MiddleCubesAuto: 0, HighCubesAuto: 0, CubesDroppedAuto: 1,
426 LowConesAuto: 0, MiddleConesAuto: 0, HighConesAuto: 0,
427 ConesDroppedAuto: 0, LowCubes: 0, MiddleCubes: 0,
428 HighCubes: 0, CubesDropped: 0, LowCones: 0,
Filip Kujawa7a045e72023-04-13 08:41:09 -0700429 MiddleCones: 0, HighCones: 1, ConesDropped: 0, SuperchargedPieces: 1,
Filip Kujawa0b4b1e52023-04-15 14:05:40 -0700430 AvgCycle: 950, Mobility: true, DockedAuto: true, EngagedAuto: true,
Emily Markova63c63f62023-03-29 20:57:35 -0700431 BalanceAttemptAuto: false, Docked: true, Engaged: false,
Philipp Schradere11114f2023-04-15 17:04:25 -0700432 BalanceAttempt: true, CollectedBy: "",
Emily Markova1abe9782023-03-11 19:45:38 -0800433 }
434
435 if expected != response {
436 t.Fatal("Expected ", expected, ", but got ", response)
437 }
438}
439
Alex Perry81f96ba2022-03-13 18:26:19 -0700440func TestSubmitNotes(t *testing.T) {
441 database := MockDatabase{}
442 scoutingServer := server.NewScoutingServer()
Philipp Schrader43c730b2023-02-26 20:27:44 -0800443 HandleRequests(&database, scoutingServer)
Alex Perry81f96ba2022-03-13 18:26:19 -0700444 scoutingServer.Start(8080)
445 defer scoutingServer.Stop()
446
447 builder := flatbuffers.NewBuilder(1024)
448 builder.Finish((&submit_notes.SubmitNotesT{
Filip Kujawa7ddd5652023-03-07 19:56:15 -0800449 Team: 971,
450 Notes: "Notes",
451 GoodDriving: true,
452 BadDriving: false,
Filip Kujawa11dc4c92023-04-13 08:55:43 -0700453 SolidPlacing: true,
Filip Kujawa7ddd5652023-03-07 19:56:15 -0800454 SketchyPlacing: false,
455 GoodDefense: true,
456 BadDefense: false,
457 EasilyDefended: true,
Alex Perry81f96ba2022-03-13 18:26:19 -0700458 }).Pack(builder))
459
460 _, err := debug.SubmitNotes("http://localhost:8080", builder.FinishedBytes())
461 if err != nil {
462 t.Fatal("Failed to submit notes: ", err)
463 }
464
465 expected := []db.NotesData{
Filip Kujawaf947cb42022-11-21 10:00:30 -0800466 {
Filip Kujawa7ddd5652023-03-07 19:56:15 -0800467 TeamNumber: 971,
468 Notes: "Notes",
469 GoodDriving: true,
470 BadDriving: false,
Filip Kujawa11dc4c92023-04-13 08:55:43 -0700471 SolidPlacing: true,
Filip Kujawa7ddd5652023-03-07 19:56:15 -0800472 SketchyPlacing: false,
473 GoodDefense: true,
474 BadDefense: false,
475 EasilyDefended: true,
Filip Kujawaf947cb42022-11-21 10:00:30 -0800476 },
Alex Perry81f96ba2022-03-13 18:26:19 -0700477 }
478
479 if !reflect.DeepEqual(database.notes, expected) {
480 t.Fatal("Submitted notes did not match", expected, database.notes)
481 }
482}
483
484func TestRequestNotes(t *testing.T) {
485 database := MockDatabase{
486 notes: []db.NotesData{{
Filip Kujawa7ddd5652023-03-07 19:56:15 -0800487 TeamNumber: 971,
488 Notes: "Notes",
489 GoodDriving: true,
490 BadDriving: false,
Filip Kujawa11dc4c92023-04-13 08:55:43 -0700491 SolidPlacing: true,
Filip Kujawa7ddd5652023-03-07 19:56:15 -0800492 SketchyPlacing: false,
493 GoodDefense: true,
494 BadDefense: false,
495 EasilyDefended: true,
Alex Perry81f96ba2022-03-13 18:26:19 -0700496 }},
497 }
498 scoutingServer := server.NewScoutingServer()
Philipp Schrader43c730b2023-02-26 20:27:44 -0800499 HandleRequests(&database, scoutingServer)
Alex Perry81f96ba2022-03-13 18:26:19 -0700500 scoutingServer.Start(8080)
501 defer scoutingServer.Stop()
502
503 builder := flatbuffers.NewBuilder(1024)
504 builder.Finish((&request_notes_for_team.RequestNotesForTeamT{
505 Team: 971,
506 }).Pack(builder))
507 response, err := debug.RequestNotes("http://localhost:8080", builder.FinishedBytes())
508 if err != nil {
509 t.Fatal("Failed to submit notes: ", err)
510 }
511
512 if response.Notes[0].Data != "Notes" {
513 t.Fatal("requested notes did not match", response)
514 }
515}
516
Milo Lin1d59f0c2022-06-22 20:30:58 -0700517func TestRequestShiftSchedule(t *testing.T) {
518 db := MockDatabase{
519 shiftSchedule: []db.Shift{
520 {
521 MatchNumber: 1,
522 R1scouter: "Bob",
523 R2scouter: "James",
524 R3scouter: "Robert",
525 B1scouter: "Alice",
526 B2scouter: "Mary",
527 B3scouter: "Patricia",
528 },
529 {
530 MatchNumber: 2,
531 R1scouter: "Liam",
532 R2scouter: "Noah",
533 R3scouter: "Oliver",
534 B1scouter: "Emma",
535 B2scouter: "Charlotte",
536 B3scouter: "Amelia",
537 },
538 },
539 }
540 scoutingServer := server.NewScoutingServer()
Philipp Schrader43c730b2023-02-26 20:27:44 -0800541 HandleRequests(&db, scoutingServer)
Milo Lin1d59f0c2022-06-22 20:30:58 -0700542 scoutingServer.Start(8080)
543 defer scoutingServer.Stop()
544
545 builder := flatbuffers.NewBuilder(1024)
546 builder.Finish((&request_shift_schedule.RequestShiftScheduleT{}).Pack(builder))
547
548 response, err := debug.RequestShiftSchedule("http://localhost:8080", builder.FinishedBytes())
549 if err != nil {
550 t.Fatal("Failed to request shift schedule: ", err)
551 }
552
553 expected := request_shift_schedule_response.RequestShiftScheduleResponseT{
554 ShiftSchedule: []*request_shift_schedule_response.MatchAssignmentT{
555 {
556 MatchNumber: 1,
Philipp Schrader2ff455b2023-05-03 22:11:50 -0700557 R1Scouter: "Bob",
558 R2Scouter: "James",
559 R3Scouter: "Robert",
560 B1Scouter: "Alice",
561 B2Scouter: "Mary",
562 B3Scouter: "Patricia",
Milo Lin1d59f0c2022-06-22 20:30:58 -0700563 },
564 {
565 MatchNumber: 2,
Philipp Schrader2ff455b2023-05-03 22:11:50 -0700566 R1Scouter: "Liam",
567 R2Scouter: "Noah",
568 R3Scouter: "Oliver",
569 B1Scouter: "Emma",
570 B2Scouter: "Charlotte",
571 B3Scouter: "Amelia",
Milo Lin1d59f0c2022-06-22 20:30:58 -0700572 },
573 },
574 }
575 if len(expected.ShiftSchedule) != len(response.ShiftSchedule) {
576 t.Fatal("Expected ", expected, ", but got ", *response)
577 }
578 for i, match := range expected.ShiftSchedule {
579 if !reflect.DeepEqual(*match, *response.ShiftSchedule[i]) {
580 t.Fatal("Expected for shift schedule", i, ":", *match, ", but got:", *response.ShiftSchedule[i])
581 }
582 }
583}
584
585func TestSubmitShiftSchedule(t *testing.T) {
586 database := MockDatabase{}
587 scoutingServer := server.NewScoutingServer()
Philipp Schrader43c730b2023-02-26 20:27:44 -0800588 HandleRequests(&database, scoutingServer)
Milo Lin1d59f0c2022-06-22 20:30:58 -0700589 scoutingServer.Start(8080)
590 defer scoutingServer.Stop()
591
592 builder := flatbuffers.NewBuilder(1024)
593 builder.Finish((&submit_shift_schedule.SubmitShiftScheduleT{
594 ShiftSchedule: []*submit_shift_schedule.MatchAssignmentT{
595 {MatchNumber: 1,
Philipp Schrader2ff455b2023-05-03 22:11:50 -0700596 R1Scouter: "Bob",
597 R2Scouter: "James",
598 R3Scouter: "Robert",
599 B1Scouter: "Alice",
600 B2Scouter: "Mary",
601 B3Scouter: "Patricia"},
Milo Lin1d59f0c2022-06-22 20:30:58 -0700602 },
603 }).Pack(builder))
604
605 _, err := debug.SubmitShiftSchedule("http://localhost:8080", builder.FinishedBytes())
606 if err != nil {
607 t.Fatal("Failed to submit shift schedule: ", err)
608 }
609
610 expected := []db.Shift{
611 {MatchNumber: 1,
612 R1scouter: "Bob",
613 R2scouter: "James",
614 R3scouter: "Robert",
615 B1scouter: "Alice",
616 B2scouter: "Mary",
617 B3scouter: "Patricia"},
618 }
619 if !reflect.DeepEqual(expected, database.shiftSchedule) {
620 t.Fatal("Expected ", expected, ", but got:", database.shiftSchedule)
621 }
622}
623
Filip Kujawa210a03b2022-11-24 14:41:11 -0800624func TestSubmitDriverRanking(t *testing.T) {
625 database := MockDatabase{}
626 scoutingServer := server.NewScoutingServer()
Philipp Schrader43c730b2023-02-26 20:27:44 -0800627 HandleRequests(&database, scoutingServer)
Filip Kujawa210a03b2022-11-24 14:41:11 -0800628 scoutingServer.Start(8080)
629 defer scoutingServer.Stop()
630
631 builder := flatbuffers.NewBuilder(1024)
632 builder.Finish((&submit_driver_ranking.SubmitDriverRankingT{
633 MatchNumber: 36,
634 Rank1: 1234,
635 Rank2: 1235,
636 Rank3: 1236,
637 }).Pack(builder))
638
639 _, err := debug.SubmitDriverRanking("http://localhost:8080", builder.FinishedBytes())
640 if err != nil {
641 t.Fatal("Failed to submit driver ranking: ", err)
642 }
643
644 expected := []db.DriverRankingData{
645 {MatchNumber: 36, Rank1: 1234, Rank2: 1235, Rank3: 1236},
646 }
647
648 if !reflect.DeepEqual(database.driver_ranking, expected) {
649 t.Fatal("Submitted notes did not match", expected, database.notes)
650 }
651}
652
Filip Kujawaf882e022022-12-14 13:14:08 -0800653// Validates that we can request the driver rankings.
654func TestRequestDriverRankings(t *testing.T) {
655 db := MockDatabase{
656 driver_ranking: []db.DriverRankingData{
657 {
658 MatchNumber: 36,
659 Rank1: 1234,
660 Rank2: 1235,
661 Rank3: 1236,
662 },
663 {
664 MatchNumber: 36,
665 Rank1: 101,
666 Rank2: 202,
667 Rank3: 303,
668 },
669 },
670 }
671 scoutingServer := server.NewScoutingServer()
Philipp Schrader43c730b2023-02-26 20:27:44 -0800672 HandleRequests(&db, scoutingServer)
Filip Kujawaf882e022022-12-14 13:14:08 -0800673 scoutingServer.Start(8080)
674 defer scoutingServer.Stop()
675
676 builder := flatbuffers.NewBuilder(1024)
677 builder.Finish((&request_all_driver_rankings.RequestAllDriverRankingsT{}).Pack(builder))
678
679 response, err := debug.RequestAllDriverRankings("http://localhost:8080", builder.FinishedBytes())
680 if err != nil {
681 t.Fatal("Failed to request all driver rankings: ", err)
682 }
683
684 expected := request_all_driver_rankings_response.RequestAllDriverRankingsResponseT{
685 DriverRankingList: []*request_all_driver_rankings_response.RankingT{
686 {
687 MatchNumber: 36,
688 Rank1: 1234,
689 Rank2: 1235,
690 Rank3: 1236,
691 },
692 {
693 MatchNumber: 36,
694 Rank1: 101,
695 Rank2: 202,
696 Rank3: 303,
697 },
698 },
699 }
700 if len(expected.DriverRankingList) != len(response.DriverRankingList) {
701 t.Fatal("Expected ", expected, ", but got ", *response)
702 }
703 for i, match := range expected.DriverRankingList {
704 if !reflect.DeepEqual(*match, *response.DriverRankingList[i]) {
705 t.Fatal("Expected for driver ranking", i, ":", *match, ", but got:", *response.DriverRankingList[i])
706 }
707 }
708}
709
710// Validates that we can request all notes.
711func TestRequestAllNotes(t *testing.T) {
712 db := MockDatabase{
713 notes: []db.NotesData{
714 {
Filip Kujawa7ddd5652023-03-07 19:56:15 -0800715 TeamNumber: 971,
716 Notes: "Notes",
717 GoodDriving: true,
718 BadDriving: false,
Filip Kujawa11dc4c92023-04-13 08:55:43 -0700719 SolidPlacing: true,
Filip Kujawa7ddd5652023-03-07 19:56:15 -0800720 SketchyPlacing: false,
721 GoodDefense: true,
722 BadDefense: false,
723 EasilyDefended: false,
Filip Kujawaf882e022022-12-14 13:14:08 -0800724 },
725 {
Filip Kujawa7ddd5652023-03-07 19:56:15 -0800726 TeamNumber: 972,
727 Notes: "More Notes",
728 GoodDriving: false,
729 BadDriving: false,
Filip Kujawa11dc4c92023-04-13 08:55:43 -0700730 SolidPlacing: false,
Filip Kujawa7ddd5652023-03-07 19:56:15 -0800731 SketchyPlacing: true,
732 GoodDefense: false,
733 BadDefense: true,
734 EasilyDefended: false,
Filip Kujawaf882e022022-12-14 13:14:08 -0800735 },
736 },
737 }
738 scoutingServer := server.NewScoutingServer()
Philipp Schrader43c730b2023-02-26 20:27:44 -0800739 HandleRequests(&db, scoutingServer)
Filip Kujawaf882e022022-12-14 13:14:08 -0800740 scoutingServer.Start(8080)
741 defer scoutingServer.Stop()
742
743 builder := flatbuffers.NewBuilder(1024)
744 builder.Finish((&request_all_notes.RequestAllNotesT{}).Pack(builder))
745
746 response, err := debug.RequestAllNotes("http://localhost:8080", builder.FinishedBytes())
747 if err != nil {
748 t.Fatal("Failed to request all notes: ", err)
749 }
750
751 expected := request_all_notes_response.RequestAllNotesResponseT{
752 NoteList: []*request_all_notes_response.NoteT{
753 {
Filip Kujawa7ddd5652023-03-07 19:56:15 -0800754 Team: 971,
755 Notes: "Notes",
756 GoodDriving: true,
757 BadDriving: false,
Filip Kujawa11dc4c92023-04-13 08:55:43 -0700758 SolidPlacing: true,
Filip Kujawa7ddd5652023-03-07 19:56:15 -0800759 SketchyPlacing: false,
760 GoodDefense: true,
761 BadDefense: false,
762 EasilyDefended: false,
Filip Kujawaf882e022022-12-14 13:14:08 -0800763 },
764 {
Filip Kujawa7ddd5652023-03-07 19:56:15 -0800765 Team: 972,
766 Notes: "More Notes",
767 GoodDriving: false,
768 BadDriving: false,
Filip Kujawa11dc4c92023-04-13 08:55:43 -0700769 SolidPlacing: false,
Filip Kujawa7ddd5652023-03-07 19:56:15 -0800770 SketchyPlacing: true,
771 GoodDefense: false,
772 BadDefense: true,
773 EasilyDefended: false,
Filip Kujawaf882e022022-12-14 13:14:08 -0800774 },
775 },
776 }
777 if len(expected.NoteList) != len(response.NoteList) {
778 t.Fatal("Expected ", expected, ", but got ", *response)
779 }
780 for i, note := range expected.NoteList {
781 if !reflect.DeepEqual(*note, *response.NoteList[i]) {
782 t.Fatal("Expected for note", i, ":", *note, ", but got:", *response.NoteList[i])
783 }
784 }
785}
786
Sabina Leaver9b4eb312023-02-20 19:58:17 -0800787func packAction(action *submit_actions.ActionT) []byte {
788 builder := flatbuffers.NewBuilder(50 * 1024)
789 builder.Finish((action).Pack(builder))
790 return (builder.FinishedBytes())
791}
792
793func TestAddingActions(t *testing.T) {
794 database := MockDatabase{}
795 scoutingServer := server.NewScoutingServer()
796 HandleRequests(&database, scoutingServer)
797 scoutingServer.Start(8080)
798 defer scoutingServer.Stop()
799
800 builder := flatbuffers.NewBuilder(1024)
801 builder.Finish((&submit_actions.SubmitActionsT{
802 TeamNumber: "1234",
803 MatchNumber: 4,
804 SetNumber: 1,
805 CompLevel: "qual",
806 ActionsList: []*submit_actions.ActionT{
807 {
808 ActionTaken: &submit_actions.ActionTypeT{
809 Type: submit_actions.ActionTypePickupObjectAction,
810 Value: &submit_actions.PickupObjectActionT{
811 ObjectType: submit_actions.ObjectTypekCube,
812 Auto: true,
813 },
814 },
815 Timestamp: 2400,
816 },
817 {
818 ActionTaken: &submit_actions.ActionTypeT{
819 Type: submit_actions.ActionTypePlaceObjectAction,
820 Value: &submit_actions.PlaceObjectActionT{
821 ObjectType: submit_actions.ObjectTypekCube,
822 ScoreLevel: submit_actions.ScoreLevelkLow,
823 Auto: false,
824 },
825 },
826 Timestamp: 1009,
827 },
828 },
Philipp Schrader4b489222023-04-15 16:40:16 -0700829 PreScouting: true,
Sabina Leaver9b4eb312023-02-20 19:58:17 -0800830 }).Pack(builder))
831
832 _, err := debug.SubmitActions("http://localhost:8080", builder.FinishedBytes())
833 if err != nil {
834 t.Fatal("Failed to submit actions: ", err)
835 }
836
837 // Make sure that the data made it into the database.
838 // TODO: Add this back when we figure out how to add the serialized action into the database.
839
840 /* expectedActionsT := []*submit_actions.ActionT{
841 {
842 ActionTaken: &submit_actions.ActionTypeT{
843 Type: submit_actions.ActionTypePickupObjectAction,
844 Value: &submit_actions.PickupObjectActionT{
845 ObjectType: submit_actions.ObjectTypekCube,
846 Auto: true,
847 },
848 },
849 Timestamp: 2400,
850 },
851 {
852 ActionTaken: &submit_actions.ActionTypeT{
853 Type: submit_actions.ActionTypePlaceObjectAction,
854 Value: &submit_actions.PlaceObjectActionT{
855 ObjectType: submit_actions.ObjectTypekCube,
856 ScoreLevel: submit_actions.ScoreLevelkLow,
857 Auto: false,
858 },
859 },
860 Timestamp: 1009,
861 },
862 } */
863
864 expectedActions := []db.Action{
865 {
Philipp Schrader4b489222023-04-15 16:40:16 -0700866 PreScouting: true,
Sabina Leaver9b4eb312023-02-20 19:58:17 -0800867 TeamNumber: "1234",
868 MatchNumber: 4,
869 SetNumber: 1,
870 CompLevel: "qual",
871 CollectedBy: "debug_cli",
872 CompletedAction: []byte{},
Philipp Schrader670a1c82023-05-17 19:42:43 -0700873 Timestamp: 2400,
Sabina Leaver9b4eb312023-02-20 19:58:17 -0800874 },
875 {
Philipp Schrader4b489222023-04-15 16:40:16 -0700876 PreScouting: true,
Sabina Leaver9b4eb312023-02-20 19:58:17 -0800877 TeamNumber: "1234",
878 MatchNumber: 4,
879 SetNumber: 1,
880 CompLevel: "qual",
881 CollectedBy: "debug_cli",
882 CompletedAction: []byte{},
Philipp Schrader670a1c82023-05-17 19:42:43 -0700883 Timestamp: 1009,
Sabina Leaver9b4eb312023-02-20 19:58:17 -0800884 },
885 }
886
Philipp Schradere11114f2023-04-15 17:04:25 -0700887 expectedStats := []db.Stats2023{
888 db.Stats2023{
889 PreScouting: true,
890 TeamNumber: "1234", MatchNumber: 4, SetNumber: 1,
891 CompLevel: "qual", StartingQuadrant: 0, LowCubesAuto: 0,
892 MiddleCubesAuto: 0, HighCubesAuto: 0, CubesDroppedAuto: 0,
893 LowConesAuto: 0, MiddleConesAuto: 0, HighConesAuto: 0,
894 ConesDroppedAuto: 0, LowCubes: 1, MiddleCubes: 0,
895 HighCubes: 0, CubesDropped: 0, LowCones: 0,
896 MiddleCones: 0, HighCones: 0, ConesDropped: 0, SuperchargedPieces: 0,
897 AvgCycle: 0, Mobility: false, DockedAuto: false, EngagedAuto: false,
898 BalanceAttemptAuto: false, Docked: false, Engaged: false,
899 BalanceAttempt: false, CollectedBy: "debug_cli",
900 },
901 }
902
Sabina Leaver9b4eb312023-02-20 19:58:17 -0800903 if !reflect.DeepEqual(expectedActions, database.actions) {
904 t.Fatal("Expected ", expectedActions, ", but got:", database.actions)
905 }
Philipp Schradere11114f2023-04-15 17:04:25 -0700906 if !reflect.DeepEqual(expectedStats, database.stats2023) {
907 t.Fatal("Expected ", expectedStats, ", but got:", database.stats2023)
908 }
Sabina Leaver9b4eb312023-02-20 19:58:17 -0800909}
910
Filip Kujawac1ded372023-05-27 14:33:43 -0700911// Validates that we can delete stats.
912func TestDeleteFromStats(t *testing.T) {
913 database := MockDatabase{
914 stats2023: []db.Stats2023{
915 {
916 TeamNumber: "3634", MatchNumber: 1, SetNumber: 2,
917 CompLevel: "quals", StartingQuadrant: 3, LowCubesAuto: 10,
918 MiddleCubesAuto: 1, HighCubesAuto: 1, CubesDroppedAuto: 0,
919 LowConesAuto: 1, MiddleConesAuto: 2, HighConesAuto: 1,
920 ConesDroppedAuto: 0, LowCubes: 1, MiddleCubes: 1,
921 HighCubes: 2, CubesDropped: 1, LowCones: 1,
922 MiddleCones: 2, HighCones: 0, ConesDropped: 1, SuperchargedPieces: 0,
923 AvgCycle: 34, Mobility: false, DockedAuto: true, EngagedAuto: false,
924 BalanceAttemptAuto: false, Docked: false, Engaged: false,
925 BalanceAttempt: true, CollectedBy: "isaac",
926 },
927 {
928 TeamNumber: "2343", MatchNumber: 1, SetNumber: 2,
929 CompLevel: "quals", StartingQuadrant: 1, LowCubesAuto: 0,
930 MiddleCubesAuto: 1, HighCubesAuto: 1, CubesDroppedAuto: 2,
931 LowConesAuto: 0, MiddleConesAuto: 0, HighConesAuto: 0,
932 ConesDroppedAuto: 1, LowCubes: 0, MiddleCubes: 0,
933 HighCubes: 1, CubesDropped: 0, LowCones: 0,
934 MiddleCones: 2, HighCones: 1, ConesDropped: 1, SuperchargedPieces: 0,
935 AvgCycle: 53, Mobility: false, DockedAuto: false, EngagedAuto: false,
936 BalanceAttemptAuto: true, Docked: false, Engaged: false,
937 BalanceAttempt: true, CollectedBy: "unknown",
938 },
939 },
940 actions: []db.Action{
941 {
942 PreScouting: true,
943 TeamNumber: "3634",
944 MatchNumber: 1,
945 SetNumber: 2,
946 CompLevel: "quals",
947 CollectedBy: "debug_cli",
948 CompletedAction: []byte{},
949 Timestamp: 2400,
950 },
951 {
952 PreScouting: true,
953 TeamNumber: "2343",
954 MatchNumber: 1,
955 SetNumber: 2,
956 CompLevel: "quals",
957 CollectedBy: "debug_cli",
958 CompletedAction: []byte{},
959 Timestamp: 1009,
960 },
961 },
962 }
963 scoutingServer := server.NewScoutingServer()
964 HandleRequests(&database, scoutingServer)
965 scoutingServer.Start(8080)
966 defer scoutingServer.Stop()
967
968 builder := flatbuffers.NewBuilder(1024)
969 builder.Finish((&delete_2023_data_scouting.Delete2023DataScoutingT{
970 CompLevel: "quals",
971 MatchNumber: 1,
972 SetNumber: 2,
973 TeamNumber: "2343",
974 }).Pack(builder))
975
976 _, err := debug.Delete2023DataScouting("http://localhost:8080", builder.FinishedBytes())
977 if err != nil {
978 t.Fatal("Failed to delete from data scouting ", err)
979 }
980
981 expectedActions := []db.Action{
982 {
983 PreScouting: true,
984 TeamNumber: "3634",
985 MatchNumber: 1,
986 SetNumber: 2,
987 CompLevel: "quals",
988 CollectedBy: "debug_cli",
989 CompletedAction: []byte{},
990 Timestamp: 2400,
991 },
992 }
993
994 expectedStats := []db.Stats2023{
995 {
996 TeamNumber: "3634", MatchNumber: 1, SetNumber: 2,
997 CompLevel: "quals", StartingQuadrant: 3, LowCubesAuto: 10,
998 MiddleCubesAuto: 1, HighCubesAuto: 1, CubesDroppedAuto: 0,
999 LowConesAuto: 1, MiddleConesAuto: 2, HighConesAuto: 1,
1000 ConesDroppedAuto: 0, LowCubes: 1, MiddleCubes: 1,
1001 HighCubes: 2, CubesDropped: 1, LowCones: 1,
1002 MiddleCones: 2, HighCones: 0, ConesDropped: 1, SuperchargedPieces: 0,
1003 AvgCycle: 34, Mobility: false, DockedAuto: true, EngagedAuto: false,
1004 BalanceAttemptAuto: false, Docked: false, Engaged: false,
1005 BalanceAttempt: true, CollectedBy: "isaac",
1006 },
1007 }
1008
1009 if !reflect.DeepEqual(expectedActions, database.actions) {
1010 t.Fatal("Expected ", expectedActions, ", but got:", database.actions)
1011 }
1012 if !reflect.DeepEqual(expectedStats, database.stats2023) {
1013 t.Fatal("Expected ", expectedStats, ", but got:", database.stats2023)
1014 }
1015}
1016
Philipp Schrader8747f1b2022-02-23 23:56:22 -08001017// A mocked database we can use for testing. Add functionality to this as
1018// needed for your tests.
1019
Philipp Schradercbf5c6a2022-02-27 23:25:19 -08001020type MockDatabase struct {
Emily Markovabf24c9e2023-02-08 20:31:11 -08001021 matches []db.TeamMatch
Filip Kujawa210a03b2022-11-24 14:41:11 -08001022 notes []db.NotesData
1023 shiftSchedule []db.Shift
1024 driver_ranking []db.DriverRankingData
Emily Markova290147d2023-03-03 22:40:06 -08001025 stats2023 []db.Stats2023
Sabina Leaver9b4eb312023-02-20 19:58:17 -08001026 actions []db.Action
Philipp Schradercbf5c6a2022-02-27 23:25:19 -08001027}
Philipp Schrader8747f1b2022-02-23 23:56:22 -08001028
Emily Markovabf24c9e2023-02-08 20:31:11 -08001029func (database *MockDatabase) AddToMatch(match db.TeamMatch) error {
Philipp Schraderd3fac192022-03-02 20:35:46 -08001030 database.matches = append(database.matches, match)
Philipp Schrader8747f1b2022-02-23 23:56:22 -08001031 return nil
1032}
1033
Emily Markova290147d2023-03-03 22:40:06 -08001034func (database *MockDatabase) AddToStats2023(stats2023 db.Stats2023) error {
1035 database.stats2023 = append(database.stats2023, stats2023)
1036 return nil
1037}
Emily Markovabf24c9e2023-02-08 20:31:11 -08001038func (database *MockDatabase) ReturnMatches() ([]db.TeamMatch, error) {
Philipp Schradercbf5c6a2022-02-27 23:25:19 -08001039 return database.matches, nil
Philipp Schrader8747f1b2022-02-23 23:56:22 -08001040}
1041
Emily Markova290147d2023-03-03 22:40:06 -08001042func (database *MockDatabase) ReturnStats2023() ([]db.Stats2023, error) {
1043 return database.stats2023, nil
1044}
1045
Filip Kujawaf3f9def2023-04-20 13:46:46 -07001046func (database *MockDatabase) ReturnStats2023ForTeam(teamNumber string, matchNumber int32, setNumber int32, compLevel string, preScouting bool) ([]db.Stats2023, error) {
Philipp Schrader0f7b6362023-03-11 14:02:48 -08001047 var results []db.Stats2023
1048 for _, stats := range database.stats2023 {
Filip Kujawaf3f9def2023-04-20 13:46:46 -07001049 if stats.TeamNumber == teamNumber && stats.MatchNumber == matchNumber && stats.SetNumber == setNumber && stats.CompLevel == compLevel && stats.PreScouting == preScouting {
Philipp Schrader0f7b6362023-03-11 14:02:48 -08001050 results = append(results, stats)
1051 }
1052 }
1053 return results, nil
1054}
1055
Philipp Schradereecb8962022-06-01 21:02:42 -07001056func (database *MockDatabase) QueryNotes(requestedTeam int32) ([]string, error) {
Alex Perry81f96ba2022-03-13 18:26:19 -07001057 var results []string
1058 for _, data := range database.notes {
1059 if data.TeamNumber == requestedTeam {
Philipp Schradereecb8962022-06-01 21:02:42 -07001060 results = append(results, data.Notes)
Alex Perry81f96ba2022-03-13 18:26:19 -07001061 }
1062 }
Philipp Schradereecb8962022-06-01 21:02:42 -07001063 return results, nil
Alex Perry81f96ba2022-03-13 18:26:19 -07001064}
1065
Filip Kujawaf947cb42022-11-21 10:00:30 -08001066func (database *MockDatabase) AddNotes(data db.NotesData) error {
1067 database.notes = append(database.notes, data)
Alex Perry81f96ba2022-03-13 18:26:19 -07001068 return nil
1069}
1070
Filip Kujawaf882e022022-12-14 13:14:08 -08001071func (database *MockDatabase) ReturnAllNotes() ([]db.NotesData, error) {
1072 return database.notes, nil
1073}
1074
Milo Lin1d59f0c2022-06-22 20:30:58 -07001075func (database *MockDatabase) AddToShift(data db.Shift) error {
1076 database.shiftSchedule = append(database.shiftSchedule, data)
1077 return nil
1078}
1079
1080func (database *MockDatabase) ReturnAllShifts() ([]db.Shift, error) {
1081 return database.shiftSchedule, nil
1082}
1083
1084func (database *MockDatabase) QueryAllShifts(int) ([]db.Shift, error) {
1085 return []db.Shift{}, nil
1086}
1087
Filip Kujawa210a03b2022-11-24 14:41:11 -08001088func (database *MockDatabase) AddDriverRanking(data db.DriverRankingData) error {
1089 database.driver_ranking = append(database.driver_ranking, data)
1090 return nil
1091}
1092
Filip Kujawaf882e022022-12-14 13:14:08 -08001093func (database *MockDatabase) ReturnAllDriverRankings() ([]db.DriverRankingData, error) {
1094 return database.driver_ranking, nil
1095}
Sabina Leaver9b4eb312023-02-20 19:58:17 -08001096
1097func (database *MockDatabase) AddAction(action db.Action) error {
1098 database.actions = append(database.actions, action)
1099 return nil
1100}
1101
1102func (database *MockDatabase) ReturnActions() ([]db.Action, error) {
1103 return database.actions, nil
1104}
Filip Kujawac1ded372023-05-27 14:33:43 -07001105
1106func (database *MockDatabase) DeleteFromStats(compLevel_ string, matchNumber_ int32, setNumber_ int32, teamNumber_ string) error {
1107 for i, stat := range database.stats2023 {
1108 if stat.CompLevel == compLevel_ &&
1109 stat.MatchNumber == matchNumber_ &&
1110 stat.SetNumber == setNumber_ &&
1111 stat.TeamNumber == teamNumber_ {
1112 // Match found, remove the element from the array.
1113 database.stats2023 = append(database.stats2023[:i], database.stats2023[i+1:]...)
1114 }
1115 }
1116 return nil
1117}
1118
1119func (database *MockDatabase) DeleteFromActions(compLevel_ string, matchNumber_ int32, setNumber_ int32, teamNumber_ string) error {
1120 for i, action := range database.actions {
1121 if action.CompLevel == compLevel_ &&
1122 action.MatchNumber == matchNumber_ &&
1123 action.SetNumber == setNumber_ &&
1124 action.TeamNumber == teamNumber_ {
1125 // Match found, remove the element from the array.
1126 database.actions = append(database.actions[:i], database.actions[i+1:]...)
1127 }
1128 }
1129 return nil
1130}