Philipp Schrader | 817cce3 | 2022-03-26 15:00:00 -0700 | [diff] [blame] | 1 | import { |
| 2 | Component, |
| 3 | ElementRef, |
| 4 | EventEmitter, |
| 5 | Input, |
| 6 | OnInit, |
| 7 | Output, |
| 8 | ViewChild, |
| 9 | } from '@angular/core'; |
Ravago Jones | 2813c03 | 2022-03-16 23:44:11 -0700 | [diff] [blame] | 10 | import {FormsModule} from '@angular/forms'; |
James Kuszmaul | dac091f | 2022-03-22 09:35:06 -0700 | [diff] [blame] | 11 | import {Builder, ByteBuffer} from 'flatbuffers'; |
Philipp Schrader | d7efa2b | 2023-02-17 21:15:13 -0800 | [diff] [blame] | 12 | import {ErrorResponse} from '../../webserver/requests/messages/error_response_generated'; |
Philipp Schrader | 817cce3 | 2022-03-26 15:00:00 -0700 | [diff] [blame] | 13 | import { |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 14 | StartMatchAction, |
Emily Markova | dcadcb6 | 2024-02-03 13:07:17 -0800 | [diff] [blame] | 15 | ScoreType, |
| 16 | StageType, |
| 17 | Submit2024Actions, |
Filip Kujawa | 0b4b1e5 | 2023-04-15 14:05:40 -0700 | [diff] [blame] | 18 | MobilityAction, |
Emily Markova | dcadcb6 | 2024-02-03 13:07:17 -0800 | [diff] [blame] | 19 | PenaltyAction, |
| 20 | PickupNoteAction, |
| 21 | PlaceNoteAction, |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 22 | RobotDeathAction, |
| 23 | EndMatchAction, |
| 24 | ActionType, |
| 25 | Action, |
Emily Markova | dcadcb6 | 2024-02-03 13:07:17 -0800 | [diff] [blame] | 26 | } from '../../webserver/requests/messages/submit_2024_actions_generated'; |
Philipp Schrader | 8702b78 | 2023-04-15 17:33:37 -0700 | [diff] [blame] | 27 | import {Match} from '../../webserver/requests/messages/request_all_matches_response_generated'; |
| 28 | import {MatchListRequestor} from '@org_frc971/scouting/www/rpc'; |
Philipp Schrader | 8b8ed67 | 2022-03-05 18:08:50 -0800 | [diff] [blame] | 29 | |
Philipp Schrader | 817cce3 | 2022-03-26 15:00:00 -0700 | [diff] [blame] | 30 | type Section = |
| 31 | | 'Team Selection' |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 32 | | 'Init' |
| 33 | | 'Pickup' |
| 34 | | 'Place' |
| 35 | | 'Endgame' |
| 36 | | 'Dead' |
Philipp Schrader | 817cce3 | 2022-03-26 15:00:00 -0700 | [diff] [blame] | 37 | | 'Review and Submit' |
| 38 | | 'Success'; |
Philipp Schrader | 8058743 | 2022-03-05 15:41:22 -0800 | [diff] [blame] | 39 | |
Philipp Schrader | 8aeb14f | 2022-04-08 21:23:18 -0700 | [diff] [blame] | 40 | // TODO(phil): Deduplicate with match_list.component.ts. |
| 41 | const COMP_LEVELS = ['qm', 'ef', 'qf', 'sf', 'f'] as const; |
| 42 | type CompLevel = typeof COMP_LEVELS[number]; |
| 43 | |
| 44 | // TODO(phil): Deduplicate with match_list.component.ts. |
| 45 | const COMP_LEVEL_LABELS: Record<CompLevel, string> = { |
| 46 | qm: 'Qualifications', |
| 47 | ef: 'Eighth Finals', |
| 48 | qf: 'Quarter Finals', |
| 49 | sf: 'Semi Finals', |
| 50 | f: 'Finals', |
| 51 | }; |
| 52 | |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 53 | type ActionT = |
| 54 | | { |
| 55 | type: 'startMatchAction'; |
| 56 | timestamp?: number; |
| 57 | position: number; |
| 58 | } |
| 59 | | { |
Filip Kujawa | 0b4b1e5 | 2023-04-15 14:05:40 -0700 | [diff] [blame] | 60 | type: 'mobilityAction'; |
| 61 | timestamp?: number; |
| 62 | mobility: boolean; |
| 63 | } |
| 64 | | { |
Emily Markova | dcadcb6 | 2024-02-03 13:07:17 -0800 | [diff] [blame] | 65 | type: 'pickupNoteAction'; |
Filip Kujawa | 4413a59 | 2023-03-01 10:54:34 -0800 | [diff] [blame] | 66 | timestamp?: number; |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 67 | auto?: boolean; |
| 68 | } |
| 69 | | { |
Emily Markova | dcadcb6 | 2024-02-03 13:07:17 -0800 | [diff] [blame] | 70 | type: 'placeNoteAction'; |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 71 | timestamp?: number; |
Emily Markova | dcadcb6 | 2024-02-03 13:07:17 -0800 | [diff] [blame] | 72 | scoreType: ScoreType; |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 73 | auto?: boolean; |
| 74 | } |
| 75 | | { |
| 76 | type: 'robotDeathAction'; |
| 77 | timestamp?: number; |
| 78 | robotOn: boolean; |
| 79 | } |
| 80 | | { |
Emily Markova | dcadcb6 | 2024-02-03 13:07:17 -0800 | [diff] [blame] | 81 | type: 'penaltyAction'; |
| 82 | timestamp?: number; |
| 83 | penalties: number; |
| 84 | } |
| 85 | | { |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 86 | type: 'endMatchAction'; |
Emily Markova | dcadcb6 | 2024-02-03 13:07:17 -0800 | [diff] [blame] | 87 | stageType: StageType; |
| 88 | trapNote: boolean; |
Emily Markova | 6079e2f | 2024-02-17 13:17:24 -0800 | [diff] [blame^] | 89 | spotlight: boolean; |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 90 | timestamp?: number; |
| 91 | } |
| 92 | | { |
| 93 | // This is not a action that is submitted, |
| 94 | // It is used for undoing purposes. |
| 95 | type: 'endAutoPhase'; |
| 96 | timestamp?: number; |
Emily Markova | dcadcb6 | 2024-02-03 13:07:17 -0800 | [diff] [blame] | 97 | } |
| 98 | | { |
| 99 | // This is not a action that is submitted, |
| 100 | // It is used for undoing purposes. |
| 101 | type: 'endTeleopPhase'; |
| 102 | timestamp?: number; |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 103 | }; |
emilym | 38d08ba | 2022-10-22 15:25:01 -0700 | [diff] [blame] | 104 | |
Philipp Schrader | 23993e8 | 2022-03-18 18:54:00 -0700 | [diff] [blame] | 105 | @Component({ |
| 106 | selector: 'app-entry', |
| 107 | templateUrl: './entry.ng.html', |
Philipp Schrader | 175a93c | 2023-02-19 13:13:40 -0800 | [diff] [blame] | 108 | styleUrls: ['../app/common.css', './entry.component.css'], |
Philipp Schrader | 23993e8 | 2022-03-18 18:54:00 -0700 | [diff] [blame] | 109 | }) |
Philipp Schrader | 75021f5 | 2023-04-09 21:14:13 -0700 | [diff] [blame] | 110 | export class EntryComponent implements OnInit { |
Philipp Schrader | 36df73a | 2022-03-17 23:27:24 -0700 | [diff] [blame] | 111 | // Re-export the type here so that we can use it in the `[value]` attribute |
| 112 | // of radio buttons. |
Philipp Schrader | 8aeb14f | 2022-04-08 21:23:18 -0700 | [diff] [blame] | 113 | readonly COMP_LEVELS = COMP_LEVELS; |
| 114 | readonly COMP_LEVEL_LABELS = COMP_LEVEL_LABELS; |
Emily Markova | dcadcb6 | 2024-02-03 13:07:17 -0800 | [diff] [blame] | 115 | readonly ScoreType = ScoreType; |
Emily Markova | 6079e2f | 2024-02-17 13:17:24 -0800 | [diff] [blame^] | 116 | readonly StageType = StageType; |
Philipp Schrader | 36df73a | 2022-03-17 23:27:24 -0700 | [diff] [blame] | 117 | |
Ravago Jones | 2813c03 | 2022-03-16 23:44:11 -0700 | [diff] [blame] | 118 | section: Section = 'Team Selection'; |
Ravago Jones | 2813c03 | 2022-03-16 23:44:11 -0700 | [diff] [blame] | 119 | @Input() matchNumber: number = 1; |
Emily Markova | e68b763 | 2023-12-30 14:17:55 -0800 | [diff] [blame] | 120 | @Input() teamNumber: string = '1'; |
Philipp Schrader | 30b4a68 | 2022-04-16 14:36:17 -0700 | [diff] [blame] | 121 | @Input() setNumber: number = 1; |
Philipp Schrader | 8aeb14f | 2022-04-08 21:23:18 -0700 | [diff] [blame] | 122 | @Input() compLevel: CompLevel = 'qm'; |
Philipp Schrader | 75021f5 | 2023-04-09 21:14:13 -0700 | [diff] [blame] | 123 | @Input() skipTeamSelection = false; |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 124 | |
Philipp Schrader | 8702b78 | 2023-04-15 17:33:37 -0700 | [diff] [blame] | 125 | matchList: Match[] = []; |
| 126 | |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 127 | actionList: ActionT[] = []; |
Philipp Schrader | 8702b78 | 2023-04-15 17:33:37 -0700 | [diff] [blame] | 128 | progressMessage: string = ''; |
Ravago Jones | 2813c03 | 2022-03-16 23:44:11 -0700 | [diff] [blame] | 129 | errorMessage: string = ''; |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 130 | autoPhase: boolean = true; |
Filip Kujawa | b73e94c | 2023-04-19 09:33:14 -0700 | [diff] [blame] | 131 | mobilityCompleted: boolean = false; |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 132 | |
Philipp Schrader | e149885 | 2023-04-15 18:06:45 -0700 | [diff] [blame] | 133 | preScouting: boolean = false; |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 134 | matchStartTimestamp: number = 0; |
Emily Markova | dcadcb6 | 2024-02-03 13:07:17 -0800 | [diff] [blame] | 135 | penalties: number = 0; |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 136 | |
Philipp Schrader | 8702b78 | 2023-04-15 17:33:37 -0700 | [diff] [blame] | 137 | teamSelectionIsValid = false; |
| 138 | |
| 139 | constructor(private readonly matchListRequestor: MatchListRequestor) {} |
| 140 | |
Philipp Schrader | 75021f5 | 2023-04-09 21:14:13 -0700 | [diff] [blame] | 141 | ngOnInit() { |
| 142 | // When the user navigated from the match list, we can skip the team |
| 143 | // selection. I.e. we trust that the user clicked the correct button. |
| 144 | this.section = this.skipTeamSelection ? 'Init' : 'Team Selection'; |
Philipp Schrader | 8702b78 | 2023-04-15 17:33:37 -0700 | [diff] [blame] | 145 | |
| 146 | if (this.section == 'Team Selection') { |
| 147 | this.fetchMatchList(); |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | async fetchMatchList() { |
| 152 | this.progressMessage = 'Fetching match list. Please be patient.'; |
| 153 | this.errorMessage = ''; |
| 154 | |
| 155 | try { |
| 156 | this.matchList = await this.matchListRequestor.fetchMatchList(); |
| 157 | this.progressMessage = 'Successfully fetched match list.'; |
| 158 | } catch (e) { |
| 159 | this.errorMessage = e; |
| 160 | this.progressMessage = ''; |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | // This gets called when the user changes something on the Init screen. |
| 165 | // It makes sure that the user can't click "Next" until the information is |
Philipp Schrader | e149885 | 2023-04-15 18:06:45 -0700 | [diff] [blame] | 166 | // valid, or this is for pre-scouting. |
Philipp Schrader | 8702b78 | 2023-04-15 17:33:37 -0700 | [diff] [blame] | 167 | updateTeamSelectionValidity(): void { |
Philipp Schrader | e149885 | 2023-04-15 18:06:45 -0700 | [diff] [blame] | 168 | this.teamSelectionIsValid = this.preScouting || this.matchIsInMatchList(); |
Philipp Schrader | 8702b78 | 2023-04-15 17:33:37 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | matchIsInMatchList(): boolean { |
| 172 | // If the user deletes the content of the teamNumber field, the value here |
| 173 | // is undefined. Guard against that. |
| 174 | if (this.teamNumber == null) { |
| 175 | return false; |
| 176 | } |
Emily Markova | e68b763 | 2023-12-30 14:17:55 -0800 | [diff] [blame] | 177 | const teamNumber = this.teamNumber; |
Philipp Schrader | 8702b78 | 2023-04-15 17:33:37 -0700 | [diff] [blame] | 178 | |
| 179 | for (const match of this.matchList) { |
| 180 | if ( |
| 181 | this.matchNumber == match.matchNumber() && |
| 182 | this.setNumber == match.setNumber() && |
| 183 | this.compLevel == match.compLevel() && |
| 184 | (teamNumber === match.r1() || |
| 185 | teamNumber === match.r2() || |
| 186 | teamNumber === match.r3() || |
| 187 | teamNumber === match.b1() || |
| 188 | teamNumber === match.b2() || |
| 189 | teamNumber === match.b3()) |
| 190 | ) { |
| 191 | return true; |
| 192 | } |
| 193 | } |
| 194 | return false; |
Philipp Schrader | 75021f5 | 2023-04-09 21:14:13 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Emily Markova | dcadcb6 | 2024-02-03 13:07:17 -0800 | [diff] [blame] | 197 | addPenalty(): void { |
| 198 | this.penalties += 1; |
| 199 | } |
| 200 | |
| 201 | removePenalty(): void { |
| 202 | if (this.penalties > 0) { |
| 203 | this.penalties -= 1; |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | addPenalties(): void { |
| 208 | this.addAction({type: 'penaltyAction', penalties: this.penalties}); |
| 209 | } |
| 210 | |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 211 | addAction(action: ActionT): void { |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 212 | if (action.type == 'startMatchAction') { |
| 213 | // Unix nanosecond timestamp. |
| 214 | this.matchStartTimestamp = Date.now() * 1e6; |
| 215 | action.timestamp = 0; |
| 216 | } else { |
| 217 | // Unix nanosecond timestamp relative to match start. |
| 218 | action.timestamp = Date.now() * 1e6 - this.matchStartTimestamp; |
| 219 | } |
| 220 | |
Emily Markova | dcadcb6 | 2024-02-03 13:07:17 -0800 | [diff] [blame] | 221 | if (action.type == 'endMatchAction') { |
| 222 | // endMatchAction occurs at the same time as penaltyAction so add to its timestamp to make it unique. |
| 223 | action.timestamp += 1; |
| 224 | } |
| 225 | |
Filip Kujawa | b73e94c | 2023-04-19 09:33:14 -0700 | [diff] [blame] | 226 | if (action.type == 'mobilityAction') { |
| 227 | this.mobilityCompleted = true; |
| 228 | } |
| 229 | |
Emily Markova | dcadcb6 | 2024-02-03 13:07:17 -0800 | [diff] [blame] | 230 | if (action.type == 'pickupNoteAction' || action.type == 'placeNoteAction') { |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 231 | action.auto = this.autoPhase; |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 232 | } |
| 233 | this.actionList.push(action); |
| 234 | } |
| 235 | |
| 236 | undoLastAction() { |
| 237 | if (this.actionList.length > 0) { |
| 238 | let lastAction = this.actionList.pop(); |
| 239 | switch (lastAction?.type) { |
| 240 | case 'endAutoPhase': |
| 241 | this.autoPhase = true; |
Emily Markova | dcadcb6 | 2024-02-03 13:07:17 -0800 | [diff] [blame] | 242 | this.section = 'Pickup'; |
| 243 | case 'pickupNoteAction': |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 244 | this.section = 'Pickup'; |
| 245 | break; |
Emily Markova | dcadcb6 | 2024-02-03 13:07:17 -0800 | [diff] [blame] | 246 | case 'endTeleopPhase': |
| 247 | this.section = 'Pickup'; |
| 248 | break; |
| 249 | case 'placeNoteAction': |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 250 | this.section = 'Place'; |
| 251 | break; |
| 252 | case 'endMatchAction': |
Emily Markova | dcadcb6 | 2024-02-03 13:07:17 -0800 | [diff] [blame] | 253 | this.section = 'Endgame'; |
| 254 | case 'mobilityAction': |
| 255 | this.mobilityCompleted = false; |
| 256 | break; |
| 257 | case 'startMatchAction': |
| 258 | this.section = 'Init'; |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 259 | break; |
Filip Kujawa | 9f56d0e | 2023-03-03 19:44:43 -0800 | [diff] [blame] | 260 | case 'robotDeathAction': |
| 261 | // TODO(FILIP): Return user to the screen they |
| 262 | // clicked dead robot on. Pickup is fine for now but |
| 263 | // might cause confusion. |
| 264 | this.section = 'Pickup'; |
| 265 | break; |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 266 | default: |
| 267 | break; |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | |
Emily Markova | dcadcb6 | 2024-02-03 13:07:17 -0800 | [diff] [blame] | 272 | stringifyScoreType(scoreType: ScoreType): String { |
| 273 | return ScoreType[scoreType]; |
Emily Markova | f4b06a2 | 2023-05-10 17:44:09 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Emily Markova | dcadcb6 | 2024-02-03 13:07:17 -0800 | [diff] [blame] | 276 | stringifyStageType(stageType: StageType): String { |
| 277 | return StageType[stageType]; |
Emily Markova | f4b06a2 | 2023-05-10 17:44:09 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 280 | changeSectionTo(target: Section) { |
Philipp Schrader | 8702b78 | 2023-04-15 17:33:37 -0700 | [diff] [blame] | 281 | // Clear the messages since they won't be relevant in the next section. |
| 282 | this.errorMessage = ''; |
| 283 | this.progressMessage = ''; |
| 284 | |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 285 | this.section = target; |
| 286 | } |
Philipp Schrader | 8058743 | 2022-03-05 15:41:22 -0800 | [diff] [blame] | 287 | |
Ravago Jones | 2813c03 | 2022-03-16 23:44:11 -0700 | [diff] [blame] | 288 | @ViewChild('header') header: ElementRef; |
Philipp Schrader | 6b2e950 | 2022-03-15 23:42:56 -0700 | [diff] [blame] | 289 | |
Ravago Jones | 2813c03 | 2022-03-16 23:44:11 -0700 | [diff] [blame] | 290 | private scrollToTop() { |
| 291 | this.header.nativeElement.scrollIntoView(); |
| 292 | } |
| 293 | |
Emily Markova | dcadcb6 | 2024-02-03 13:07:17 -0800 | [diff] [blame] | 294 | async submit2024Actions() { |
James Kuszmaul | dac091f | 2022-03-22 09:35:06 -0700 | [diff] [blame] | 295 | const builder = new Builder(); |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 296 | const actionOffsets: number[] = []; |
| 297 | |
| 298 | for (const action of this.actionList) { |
| 299 | let actionOffset: number | undefined; |
| 300 | console.log(action.type); |
| 301 | |
| 302 | switch (action.type) { |
| 303 | case 'startMatchAction': |
| 304 | const startMatchActionOffset = |
| 305 | StartMatchAction.createStartMatchAction(builder, action.position); |
| 306 | actionOffset = Action.createAction( |
| 307 | builder, |
Philipp Schrader | 8c878a2 | 2023-03-20 22:36:38 -0700 | [diff] [blame] | 308 | BigInt(action.timestamp || 0), |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 309 | ActionType.StartMatchAction, |
| 310 | startMatchActionOffset |
| 311 | ); |
| 312 | break; |
Filip Kujawa | 0b4b1e5 | 2023-04-15 14:05:40 -0700 | [diff] [blame] | 313 | case 'mobilityAction': |
| 314 | const mobilityActionOffset = MobilityAction.createMobilityAction( |
| 315 | builder, |
| 316 | action.mobility |
| 317 | ); |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 318 | actionOffset = Action.createAction( |
| 319 | builder, |
Philipp Schrader | 8c878a2 | 2023-03-20 22:36:38 -0700 | [diff] [blame] | 320 | BigInt(action.timestamp || 0), |
Filip Kujawa | 0b4b1e5 | 2023-04-15 14:05:40 -0700 | [diff] [blame] | 321 | ActionType.MobilityAction, |
| 322 | mobilityActionOffset |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 323 | ); |
| 324 | break; |
Emily Markova | dcadcb6 | 2024-02-03 13:07:17 -0800 | [diff] [blame] | 325 | case 'penaltyAction': |
| 326 | const penaltyActionOffset = PenaltyAction.createPenaltyAction( |
| 327 | builder, |
| 328 | action.penalties |
| 329 | ); |
Filip Kujawa | 4c28644 | 2023-03-03 10:41:22 -0800 | [diff] [blame] | 330 | actionOffset = Action.createAction( |
| 331 | builder, |
Philipp Schrader | 8c878a2 | 2023-03-20 22:36:38 -0700 | [diff] [blame] | 332 | BigInt(action.timestamp || 0), |
Emily Markova | dcadcb6 | 2024-02-03 13:07:17 -0800 | [diff] [blame] | 333 | ActionType.PenaltyAction, |
| 334 | penaltyActionOffset |
Filip Kujawa | 4c28644 | 2023-03-03 10:41:22 -0800 | [diff] [blame] | 335 | ); |
| 336 | break; |
Emily Markova | dcadcb6 | 2024-02-03 13:07:17 -0800 | [diff] [blame] | 337 | case 'pickupNoteAction': |
| 338 | const pickupNoteActionOffset = |
| 339 | PickupNoteAction.createPickupNoteAction( |
Filip Kujawa | 0b4b1e5 | 2023-04-15 14:05:40 -0700 | [diff] [blame] | 340 | builder, |
Filip Kujawa | 0b4b1e5 | 2023-04-15 14:05:40 -0700 | [diff] [blame] | 341 | action.auto || false |
| 342 | ); |
| 343 | actionOffset = Action.createAction( |
| 344 | builder, |
| 345 | BigInt(action.timestamp || 0), |
Emily Markova | dcadcb6 | 2024-02-03 13:07:17 -0800 | [diff] [blame] | 346 | ActionType.PickupNoteAction, |
| 347 | pickupNoteActionOffset |
Filip Kujawa | 0b4b1e5 | 2023-04-15 14:05:40 -0700 | [diff] [blame] | 348 | ); |
| 349 | break; |
Emily Markova | dcadcb6 | 2024-02-03 13:07:17 -0800 | [diff] [blame] | 350 | case 'placeNoteAction': |
| 351 | const placeNoteActionOffset = PlaceNoteAction.createPlaceNoteAction( |
| 352 | builder, |
| 353 | action.scoreType, |
| 354 | action.auto || false |
| 355 | ); |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 356 | actionOffset = Action.createAction( |
| 357 | builder, |
Philipp Schrader | 8c878a2 | 2023-03-20 22:36:38 -0700 | [diff] [blame] | 358 | BigInt(action.timestamp || 0), |
Emily Markova | dcadcb6 | 2024-02-03 13:07:17 -0800 | [diff] [blame] | 359 | ActionType.PlaceNoteAction, |
| 360 | placeNoteActionOffset |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 361 | ); |
| 362 | break; |
| 363 | |
| 364 | case 'robotDeathAction': |
| 365 | const robotDeathActionOffset = |
| 366 | RobotDeathAction.createRobotDeathAction(builder, action.robotOn); |
| 367 | actionOffset = Action.createAction( |
| 368 | builder, |
Philipp Schrader | 8c878a2 | 2023-03-20 22:36:38 -0700 | [diff] [blame] | 369 | BigInt(action.timestamp || 0), |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 370 | ActionType.RobotDeathAction, |
| 371 | robotDeathActionOffset |
| 372 | ); |
| 373 | break; |
| 374 | |
| 375 | case 'endMatchAction': |
| 376 | const endMatchActionOffset = EndMatchAction.createEndMatchAction( |
| 377 | builder, |
Emily Markova | dcadcb6 | 2024-02-03 13:07:17 -0800 | [diff] [blame] | 378 | action.stageType, |
Emily Markova | 6079e2f | 2024-02-17 13:17:24 -0800 | [diff] [blame^] | 379 | action.trapNote, |
| 380 | action.spotlight |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 381 | ); |
| 382 | actionOffset = Action.createAction( |
| 383 | builder, |
Philipp Schrader | 8c878a2 | 2023-03-20 22:36:38 -0700 | [diff] [blame] | 384 | BigInt(action.timestamp || 0), |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 385 | ActionType.EndMatchAction, |
| 386 | endMatchActionOffset |
| 387 | ); |
| 388 | break; |
| 389 | |
| 390 | case 'endAutoPhase': |
| 391 | // Not important action. |
| 392 | break; |
| 393 | |
Emily Markova | dcadcb6 | 2024-02-03 13:07:17 -0800 | [diff] [blame] | 394 | case 'endTeleopPhase': |
| 395 | // Not important action. |
| 396 | break; |
| 397 | |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 398 | default: |
| 399 | throw new Error(`Unknown action type`); |
| 400 | } |
| 401 | |
| 402 | if (actionOffset !== undefined) { |
| 403 | actionOffsets.push(actionOffset); |
| 404 | } |
| 405 | } |
Emily Markova | e68b763 | 2023-12-30 14:17:55 -0800 | [diff] [blame] | 406 | const teamNumberFb = builder.createString(this.teamNumber); |
Philipp Schrader | e859e6e | 2023-03-22 19:59:51 -0700 | [diff] [blame] | 407 | const compLevelFb = builder.createString(this.compLevel); |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 408 | |
Emily Markova | dcadcb6 | 2024-02-03 13:07:17 -0800 | [diff] [blame] | 409 | const actionsVector = Submit2024Actions.createActionsListVector( |
Philipp Schrader | 817cce3 | 2022-03-26 15:00:00 -0700 | [diff] [blame] | 410 | builder, |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 411 | actionOffsets |
Philipp Schrader | 817cce3 | 2022-03-26 15:00:00 -0700 | [diff] [blame] | 412 | ); |
Emily Markova | dcadcb6 | 2024-02-03 13:07:17 -0800 | [diff] [blame] | 413 | Submit2024Actions.startSubmit2024Actions(builder); |
| 414 | Submit2024Actions.addTeamNumber(builder, teamNumberFb); |
| 415 | Submit2024Actions.addMatchNumber(builder, this.matchNumber); |
| 416 | Submit2024Actions.addSetNumber(builder, this.setNumber); |
| 417 | Submit2024Actions.addCompLevel(builder, compLevelFb); |
| 418 | Submit2024Actions.addActionsList(builder, actionsVector); |
| 419 | Submit2024Actions.addPreScouting(builder, this.preScouting); |
| 420 | builder.finish(Submit2024Actions.endSubmit2024Actions(builder)); |
Ravago Jones | 2813c03 | 2022-03-16 23:44:11 -0700 | [diff] [blame] | 421 | |
| 422 | const buffer = builder.asUint8Array(); |
Emily Markova | dcadcb6 | 2024-02-03 13:07:17 -0800 | [diff] [blame] | 423 | const res = await fetch('/requests/submit/submit_2024_actions', { |
Philipp Schrader | 817cce3 | 2022-03-26 15:00:00 -0700 | [diff] [blame] | 424 | method: 'POST', |
| 425 | body: buffer, |
| 426 | }); |
Ravago Jones | 2813c03 | 2022-03-16 23:44:11 -0700 | [diff] [blame] | 427 | |
| 428 | if (res.ok) { |
| 429 | // We successfully submitted the data. Report success. |
| 430 | this.section = 'Success'; |
Filip Kujawa | 0ef334c | 2023-02-20 19:42:45 -0800 | [diff] [blame] | 431 | this.actionList = []; |
Ravago Jones | 2813c03 | 2022-03-16 23:44:11 -0700 | [diff] [blame] | 432 | } else { |
| 433 | const resBuffer = await res.arrayBuffer(); |
| 434 | const fbBuffer = new ByteBuffer(new Uint8Array(resBuffer)); |
James Kuszmaul | dac091f | 2022-03-22 09:35:06 -0700 | [diff] [blame] | 435 | const parsedResponse = ErrorResponse.getRootAsErrorResponse(fbBuffer); |
Ravago Jones | 2813c03 | 2022-03-16 23:44:11 -0700 | [diff] [blame] | 436 | |
| 437 | const errorMessage = parsedResponse.errorMessage(); |
Philipp Schrader | 817cce3 | 2022-03-26 15:00:00 -0700 | [diff] [blame] | 438 | this.errorMessage = `Received ${res.status} ${res.statusText}: "${errorMessage}"`; |
Alex Perry | bb3d206 | 2022-03-05 18:14:33 -0800 | [diff] [blame] | 439 | } |
Ravago Jones | 2813c03 | 2022-03-16 23:44:11 -0700 | [diff] [blame] | 440 | } |
Philipp Schrader | 8058743 | 2022-03-05 15:41:22 -0800 | [diff] [blame] | 441 | } |