Skip to content

Commit

Permalink
Merge branch 'main' into 206-photo-import-in-pit-scouting
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePotatoArchivist committed Mar 13, 2024
2 parents df36751 + 4149683 commit 9fb6bca
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 207 deletions.
1 change: 1 addition & 0 deletions client/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_SCOUT_VERSION=LAR.0
1 change: 1 addition & 0 deletions client/src/RootMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ function RootMenu() {
<h1 className='bg-[#2f3646] col-span-2 text-4xl text-[#48c55c] font-bold p-5'>
Vitruvian Scouting
</h1>
<div className='fixed bottom-2 left-1/2 -translate-x-1/2'> Version {import.meta.env.VITE_SCOUT_VERSION} </div>
<LinkButton link='/match'
className='text-5xl bg-[#2f3646] rounded-3xl'>
Match
Expand Down
91 changes: 69 additions & 22 deletions client/src/apps/match/MatchApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,18 @@ import { usePreventUnload } from '../../lib/usePreventUnload';

const schedule = scheduleFile as MatchSchedule

type countKeys = keyof MatchScores;

interface MatchScores {
autoShootNear: number;
autoShootMid: number;
autoShootFar: number;
autoAmp: number;
autoMiss: number;
autoPreload: number;
autoPickup: number;
hold: number; // Did the robot hold a note between auto and teleop? 0=no, 1=yes
teleShootNear: number;
teleShootMid: number;
teleShootFar: number;
teleAmp: number;
teleMiss: number;
telePickupSpeaker: number;
telePickupMiddle: number;
telePickupSource: number;
trap: number;
}
const defualtScores: MatchScores = {
Expand All @@ -44,17 +37,12 @@ const defualtScores: MatchScores = {
autoShootFar: 0,
autoAmp: 0,
autoMiss: 0,
autoPreload: 0,
autoPickup: 0,
hold: 0,
teleShootNear: 0,
teleShootMid: 0,
teleShootFar: 0,
teleAmp: 0,
teleMiss: 0,
telePickupSpeaker: 0,
telePickupMiddle: 0,
telePickupSource: 0,
trap: 0,
};

Expand All @@ -69,7 +57,6 @@ function MatchApp() {
const [climbPosition, setClimbPosition] = useState<ClimbPosition>('none');
const [showCheck, setShowCheck] = useState(false);
const [scouterName, setScouterName] = useState('');

const [robotPosition, setRobotPosition] = useState<RobotPosition>();

const [scouterPosition, setScouterPosition] = useState<ScouterPosition>();
Expand All @@ -78,6 +65,54 @@ function MatchApp() {
['blue_1', 'blue_2', 'blue_3'] as (string | undefined)[]
).includes(robotPosition);

const handleAbsentRobot = async () => {
if (
robotPosition == undefined ||
matchNumber == undefined
) {
alert('Check if your signed in, and you have the match number')
return; }

const data: MatchData = {
metadata: {
scouterName,
robotPosition,
matchNumber,
robotTeam: undefined
},
leftStartingZone: leave,
autoNotes: {
near: count.autoShootNear,
mid: count.autoShootMid,
far: count.autoShootFar,
amp: count.autoAmp,
miss: count.autoMiss
},
teleNotes: {
near: count.teleShootNear,
mid: count.teleShootMid,
far: count.teleShootFar,
amp: count.teleAmp,
miss: count.autoMiss
},
trapNotes: count.trap,
climb: climbPosition,
};

sendQueue('/data/match', data);
setCount(defualtScores);
setClimbPosition('none');
setLeave(false);
setMatchNumber(matchNumber + 1);
setCountHistory([]);

setShowCheck(true);

setTimeout(() => {
setShowCheck(false);
}, 3000);
}

const handleSubmit = async () => {
if (
robotPosition == undefined ||
Expand Down Expand Up @@ -129,6 +164,15 @@ function MatchApp() {

};

const showConfirmationDialog = () => {
if (window.confirm('Are you sure you want to mark as absent?')) {
// User confirmed, call the action
handleAbsentRobot();
// Optionally, you can also scroll to the top
scrollTo(0, 0);
}
};

const undoCount = () => {
if (countHistory.length > 0) {
setCountHistory(prevHistory => prevHistory.slice(0, -1));
Expand All @@ -139,9 +183,6 @@ function MatchApp() {
setCountHistory([...countHistory, count]);
setCount(newCount);
};
const handleCount = (key: countKeys) => {
handleSetCount({ ...count, [key]: count[key] + 1 });
};

useEffect(() => {
setTeamNumber(
Expand Down Expand Up @@ -217,6 +258,13 @@ function MatchApp() {
<p className='text-2xl mt-2 mb-2'>Team Number</p>
<TeamDropdown onChange={setTeamNumber} value={teamNumber} />

<div>
<button onClick={showConfirmationDialog} style={{ fontSize: '20px' }}
className='px-2 py-1 mt-14 mb-2 text-center bg-green-500 rounded-md'>
Robot Absent
</button>
</div>

<div>
<h2 className='mt-12 mb-5 text-center text-5xl text-green-600 font-semibold'>Autonomous</h2>
<FieldButton
Expand All @@ -238,19 +286,18 @@ function MatchApp() {
/>
<h2 className='my-6 mt-12 text-center text-5xl text-green-600 font-semibold'>Endgame</h2>
<EndgameButton
setCount={handleSetCount}
climbPosition={climbPosition}
setClimb={setClimbPosition}
alliance={blueAlliance}
scouterPosition={scouterPosition}
count={count}
/>
<div className='flex justify-center mt-20 mb-5'>
<button onClick={() => { if (count.trap < 3) handleCount('trap') }} style={{ fontSize: '30px'}}
className='px-2 py-1 text-center bg-blue-300 rounded-md mr-2 block absolute left-24'>
Trap Note: {count.trap}
</button>
<div className='flex flex-col justify-center mt-20 mb-5'>

<button onClick={() => {handleSubmit(); scrollTo(0, 0);}} style={{ fontSize: '30px' }}
className='px-2 py-1 text-center bg-green-500 rounded-md'>
Submit
Submit
</button>

</div>
Expand Down
13 changes: 10 additions & 3 deletions client/src/apps/pit/PitApp.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import MultiButton from '../../components/MultiButton';
//import ToggleButton from '../../components/ToggleButton'
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';
import Checkbox from '../../components/Checkbox';
import { PitFile, teamRoles, drivebase } from 'requests';
import { postJson } from '../../lib/postJson';
import LinkButton from '../../components/LinkButton';
import { MaterialSymbol } from 'react-material-symbols';
import TeamDropdown from '../../components/TeamDropdown';
Expand All @@ -12,6 +11,8 @@ import SignIn from '../../components/SignIn';
import ConeStacker from '../../components/ConeStacker';
import { usePreventUnload } from '../../lib/usePreventUnload';
import ImageUploader from '../../components/ImageUploader';
import { useFetchJson } from '../../lib/useFetch';
import { postJson } from '../../lib/postJson';


function PitApp() {
Expand All @@ -32,6 +33,7 @@ function PitApp() {
setAutoInputValues([...autoInputValues, '']);
};

const [scoutedTeams, refreshScoutedTeams] = useFetchJson<number[]>('/data/pit/scouted-teams');

const [autoInputValues, setAutoInputValues] = useState(['']);
const [role, setRole] = useState<teamRoles|undefined>();
Expand All @@ -52,6 +54,10 @@ function PitApp() {

const [scouterName, setScouterName] = useState('');
const [robotImage, setRobotImage] = useState('');
useEffect(() => {
const timeout = setInterval(refreshScoutedTeams, 60 * 1000);
return () => clearInterval(timeout);
}, [refreshScoutedTeams]);

const handleSubmit = async() => {
if (!drivetrain || !role){
Expand Down Expand Up @@ -86,6 +92,7 @@ function PitApp() {
try {
const result = await postJson('/data/pit', data);
if (!result.ok) throw new Error('Request Did Not Succeed');
refreshScoutedTeams();
setAutoInputValues(['']);
setAmpChecked(false);
setAmpPrefChecked(false);
Expand Down Expand Up @@ -165,7 +172,7 @@ function PitApp() {
<div className="flex justify-center items-center mb-8">
<div className="flex flex-col items-center bg-[#2f3646] border-[#2f3646] border-4 h-24 w-2/4 justify-center rounded-lg">
<h1 className="text-center text-white">Team Number</h1>
<TeamDropdown onChange={setTeamNumber} value={teamNumber} />
<TeamDropdown onChange={setTeamNumber} value={teamNumber} disabledOptions={scoutedTeams} />
</div>
</div>

Expand Down
18 changes: 18 additions & 0 deletions client/src/components/EndGameButton.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
import { Dispatch, SetStateAction } from 'react';
import { MatchScores } from '../apps/match/MatchApp';
import { ClimbPosition, ScouterPosition } from 'requests';
import MultiButton from './MultiButton';

function EndgameButton({
setClimb,
setCount,
climbPosition,
alliance,
scouterPosition,
count,
}: {
setClimb: Dispatch<SetStateAction<ClimbPosition>>;
setCount: Dispatch<SetStateAction<MatchScores>>;
climbPosition: ClimbPosition;
alliance: boolean | undefined;
scouterPosition: ScouterPosition | undefined;
count: MatchScores;
}) {
// const [alliance, setAlliance] = useState(false); //false=red, true=blue, null=hollow purple

const handleClimb = (newClimb: ClimbPosition) => {
setClimb(newClimb);
};

const handleTrap = () => {
setCount(prevCount => ({
...prevCount,
['trap']: prevCount['trap'] + 1,
}));
}

return (
<>
<div
Expand Down Expand Up @@ -62,6 +74,12 @@ function EndgameButton({
]}
/>
</div>
<div className = 'flex justify-center pt-24'>
<button onClick={() => { if (count.trap < 3) handleTrap() }} style={{ fontSize: '30px'}}
className='px-2 py-1 text-center bg-blue-300 rounded-md'>
Trap Notes: {count.trap}
</button>
</div>
</>
);
}
Expand Down
Loading

0 comments on commit 9fb6bca

Please sign in to comment.