blob: e45b6aaa1ddeffeaa1765e2c269a5c1e80ff0d8a [file] [log] [blame]
Philipp Schrader80587432022-03-05 15:41:22 -08001import { Component, OnInit } from '@angular/core';
Philipp Schradere279e1a2022-03-15 22:20:10 -07002import { FormsModule } from '@angular/forms';
Philipp Schrader80587432022-03-05 15:41:22 -08003
Philipp Schrader8b8ed672022-03-05 18:08:50 -08004import * as flatbuffer_builder from 'org_frc971/external/com_github_google_flatbuffers/ts/builder';
5import {ByteBuffer} from 'org_frc971/external/com_github_google_flatbuffers/ts/byte-buffer';
6import * as error_response from 'org_frc971/scouting/webserver/requests/messages/error_response_generated';
7import * as submit_data_scouting_response from 'org_frc971/scouting/webserver/requests/messages/submit_data_scouting_response_generated';
8import * as submit_data_scouting from 'org_frc971/scouting/webserver/requests/messages/submit_data_scouting_generated';
9import SubmitDataScouting = submit_data_scouting.scouting.webserver.requests.SubmitDataScouting;
10import SubmitDataScoutingResponse = submit_data_scouting_response.scouting.webserver.requests.SubmitDataScoutingResponse;
11import ErrorResponse = error_response.scouting.webserver.requests.ErrorResponse;
12
Philipp Schradere279e1a2022-03-15 22:20:10 -070013type Section = 'Team Selection'|'Auto'|'TeleOp'|'Climb'|'Other'|'Review and Submit'|'Home'
Philipp Schrader5990fd32022-03-15 21:49:58 -070014type Level = 'NoAttempt'|'Failed'|'FailedWithPlentyOfTime'|'Low'|'Medium'|'High'|'Transversal'
Philipp Schrader80587432022-03-05 15:41:22 -080015
16@Component({
17 selector: 'app-entry',
18 templateUrl: './entry.ng.html',
Philipp Schrader72beced2022-03-07 05:29:52 -080019 styleUrls: ['../common.css', './entry.component.css']
Philipp Schrader80587432022-03-05 15:41:22 -080020})
21export class EntryComponent {
Philipp Schrader93ade042022-03-05 17:16:10 -080022 section: Section = 'Team Selection';
23 matchNumber: number = 1
24 teamNumber: number = 1
Philipp Schrader80587432022-03-05 15:41:22 -080025 autoUpperShotsMade: number = 0;
26 autoLowerShotsMade: number = 0;
27 autoShotsMissed: number = 0;
28 teleUpperShotsMade: number = 0;
29 teleLowerShotsMade: number = 0;
30 teleShotsMissed: number = 0;
Yash Chainani43a81022022-03-12 16:46:47 -080031 defensePlayedOnScore: number = 0;
32 defensePlayedScore: number = 0;
Philipp Schrader5990fd32022-03-15 21:49:58 -070033 level: Level = 'NoAttempt';
Philipp Schrader8b8ed672022-03-05 18:08:50 -080034 errorMessage: string = '';
Philipp Schradere279e1a2022-03-15 22:20:10 -070035 noShow: boolean = false;
36 neverMoved: boolean = false;
37 batteryDied: boolean = false;
38 mechanicallyBroke: boolean = false;
39 lostComs: boolean = false;
Philipp Schrader80587432022-03-05 15:41:22 -080040
Philipp Schrader80587432022-03-05 15:41:22 -080041 nextSection() {
Philipp Schrader93ade042022-03-05 17:16:10 -080042 if (this.section === 'Team Selection') {
43 this.section = 'Auto';
44 } else if (this.section === 'Auto') {
Philipp Schrader80587432022-03-05 15:41:22 -080045 this.section = 'TeleOp';
46 } else if (this.section === 'TeleOp') {
47 this.section = 'Climb';
48 } else if (this.section === 'Climb') {
Philipp Schradere279e1a2022-03-15 22:20:10 -070049 this.section = 'Other';
50 } else if (this.section === 'Other') {
Philipp Schrader80587432022-03-05 15:41:22 -080051 this.section = 'Review and Submit';
52 } else if (this.section === 'Review and Submit') {
Philipp Schrader8b8ed672022-03-05 18:08:50 -080053 this.submitDataScouting();
Philipp Schrader80587432022-03-05 15:41:22 -080054 }
55 }
56
Alex Perrybb3d2062022-03-05 18:14:33 -080057 prevSection() {
Philipp Schrader93ade042022-03-05 17:16:10 -080058 if (this.section === 'Auto') {
59 this.section = 'Team Selection';
60 } else if (this.section === 'TeleOp') {
Alex Perrybb3d2062022-03-05 18:14:33 -080061 this.section = 'Auto';
62 } else if (this.section === 'Climb') {
63 this.section = 'TeleOp';
Philipp Schradere279e1a2022-03-15 22:20:10 -070064 } else if (this.section === 'Other') {
Alex Perrybb3d2062022-03-05 18:14:33 -080065 this.section = 'Climb';
66 } else if (this.section === 'Review and Submit') {
Philipp Schradere279e1a2022-03-15 22:20:10 -070067 this.section = 'Other';
Alex Perrybb3d2062022-03-05 18:14:33 -080068 }
69 }
70
Philipp Schrader8b8ed672022-03-05 18:08:50 -080071 async submitDataScouting() {
72 const builder = new flatbuffer_builder.Builder() as unknown as flatbuffers.Builder;
73 SubmitDataScouting.startSubmitDataScouting(builder);
74 SubmitDataScouting.addTeam(builder, this.teamNumber);
75 SubmitDataScouting.addMatch(builder, this.matchNumber);
76 SubmitDataScouting.addMissedShotsAuto(builder, this.autoShotsMissed);
77 SubmitDataScouting.addUpperGoalAuto(builder, this.autoUpperShotsMade);
78 SubmitDataScouting.addLowerGoalAuto(builder, this.autoLowerShotsMade);
79 SubmitDataScouting.addMissedShotsTele(builder, this.teleShotsMissed);
80 SubmitDataScouting.addUpperGoalTele(builder, this.teleUpperShotsMade);
81 SubmitDataScouting.addLowerGoalTele(builder, this.teleLowerShotsMade);
82 SubmitDataScouting.addDefenseRating(builder, this.defensePlayedScore);
83 // TODO(phil): Add support for defensePlayedOnScore.
84 // TODO(phil): Fix the Climbing score.
85 SubmitDataScouting.addClimbing(builder, 1);
86 builder.finish(SubmitDataScouting.endSubmitDataScouting(builder));
87
88 const buffer = builder.asUint8Array();
89 const res = await fetch(
90 '/requests/submit/data_scouting', {method: 'POST', body: buffer});
91
92 if (res.ok) {
93 // We successfully submitted the data. Go back to Home.
94 this.section = 'Home';
95 } else {
96 const resBuffer = await res.arrayBuffer();
97 const fbBuffer = new ByteBuffer(new Uint8Array(resBuffer));
98 const parsedResponse = ErrorResponse.getRootAsErrorResponse(
99 fbBuffer as unknown as flatbuffers.ByteBuffer);
100
101 const errorMessage = parsedResponse.errorMessage();
102 this.errorMessage = `Received ${res.status} ${res.statusText}: "${errorMessage}"`;
103 }
104 }
Philipp Schrader80587432022-03-05 15:41:22 -0800105}