-
Notifications
You must be signed in to change notification settings - Fork 0
Pit scouting #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
karnishein
wants to merge
6
commits into
worlds
Choose a base branch
from
pit-scouting
base: worlds
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Pit scouting #120
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4bfb13d
Yoni - stop crashing the metrics when bps is null
YoniKiriaty e718451
karni- added types and backend
karnishein caafe75
karni- continued
karnishein 755afcf
karni- merged with worlds
karnishein 5a81a60
karni- added the whole pit scouting submition
karnishein 2dba74e
karni- did what Yoni asked
karnishein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| //בס"ד | ||
|
|
||
| import { Router } from "express"; | ||
| import { flow, pipe } from "fp-ts/lib/function"; | ||
| import { getDb } from "../middleware/db"; | ||
| import { bind, bindTo, fromEither, map } from "fp-ts/lib/TaskEither"; | ||
| import { | ||
| createBodyVerificationPipe, | ||
| flatTryCatch, | ||
| foldResponse, | ||
| } from "@repo/flow-utils"; | ||
| import { right as rightEither } from "fp-ts/lib/Either"; | ||
| import { mongofyQuery } from "@repo/flow-utils"; | ||
| import { PitScout, pitScoutCodec } from "@repo/scouting_types"; | ||
| import { StatusCodes } from "http-status-codes"; | ||
|
|
||
| export const pitScoutRouter = Router(); | ||
|
|
||
| export const getPitCollection = flow( | ||
| getDb, | ||
| map((db) => db.collection<PitScout>("pit")), | ||
| ); | ||
|
|
||
| pitScoutRouter.post("/", async (req, res) => { | ||
| await pipe( | ||
| rightEither(req), | ||
| createBodyVerificationPipe(pitScoutCodec), | ||
| fromEither, | ||
| bindTo("pitScout"), | ||
| bind("collection", getPitCollection), | ||
| map(({ pitScout, collection }) => collection.insertOne(pitScout)), | ||
| foldResponse(res), | ||
| )(); | ||
| }); | ||
|
|
||
| pitScoutRouter.get("/", async (req, res) => { | ||
| await flow( | ||
| getPitCollection, | ||
| flatTryCatch( | ||
| (collection) => collection.find(mongofyQuery(req.query)).toArray(), | ||
| () => ({ | ||
| status: StatusCodes.INTERNAL_SERVER_ERROR, | ||
| reason: "Error Inserting Forms To Collection ", | ||
| }), | ||
| ), | ||
| bindTo("forms"), | ||
| foldResponse(res), | ||
| )(); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
apps/scouting/frontend/src/strategy/tabs/pit-scout/BooleanStats.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| //בס"ד | ||
|
|
||
| import type { FC } from "react"; | ||
| import type { | ||
| PitScout, | ||
| PitScoutBoolean, | ||
| PitScoutBooleanKey, | ||
| PitScoutBooleanMetric, | ||
| } from "@repo/scouting_types"; | ||
|
|
||
| interface BooleanStatsProps { | ||
| statKey: PitScoutBooleanKey; | ||
| label: string; | ||
| form: PitScout; | ||
| setBoolForm: (key: PitScoutBooleanKey, value: PitScoutBooleanMetric) => void; | ||
| } | ||
|
|
||
| export const BooleanStats: FC<BooleanStatsProps> = ({ | ||
| statKey, | ||
| label, | ||
| form, | ||
| setBoolForm, | ||
| }) => { | ||
| return ( | ||
| <div key={statKey} className="flex items-center justify-between group"> | ||
| <span className="text-sm font-medium text-slate-300 group-hover:text-white transition-colors"> | ||
| {label} | ||
| </span> | ||
| <div className="flex gap-2 bg-slate-900/80 p-1 rounded-xl border border-white/5"> | ||
| <button | ||
| onClick={() => setBoolForm(statKey, true)} | ||
| className={`px-4 py-1.5 rounded-lg text-[10px] font-black uppercase transition-all ${ | ||
| form.booleanMetrics[statKey] === true | ||
| ? "bg-emerald-500 text-slate-950 shadow-[0_0_10px_rgba(16,185,129,0.2)]" | ||
| : "text-slate-500 hover:text-slate-300" | ||
| }`} | ||
| > | ||
| Yes | ||
| </button> | ||
| <button | ||
| onClick={() => setBoolForm(statKey, false)} | ||
| className={`px-4 py-1.5 rounded-lg text-[10px] font-black uppercase transition-all ${ | ||
| form.booleanMetrics[statKey] === false | ||
| ? "bg-rose-500 text-slate-950 shadow-[0_0_10px_rgba(244,63,94,0.2)]" | ||
| : "text-slate-500 hover:text-slate-300" | ||
| }`} | ||
| > | ||
| No | ||
| </button> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; |
44 changes: 44 additions & 0 deletions
44
apps/scouting/frontend/src/strategy/tabs/pit-scout/NumberStats.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| //בס"ד | ||
|
|
||
| import type { | ||
| PitScout, | ||
| PitScoutNumberKey, | ||
| SuperScout, | ||
| } from "@repo/scouting_types"; | ||
| import type { FC } from "react"; | ||
|
|
||
| interface NumberStatsProps { | ||
| statKey: PitScoutNumberKey; | ||
| label: string; | ||
| placeholder: string; | ||
| form: PitScout; | ||
| setNumberForm: (key: PitScoutNumberKey, value: number) => void; | ||
| } | ||
|
|
||
| export const NumberStats: FC<NumberStatsProps> = ({ | ||
| statKey, | ||
| label, | ||
| placeholder, | ||
| form, | ||
| setNumberForm, | ||
| }) => { | ||
| return ( | ||
| <div | ||
| key={statKey} | ||
| className="bg-slate-800/40 border border-white/5 p-5 rounded-2xl" | ||
| > | ||
| <label className="text-[10px] font-bold uppercase text-slate-500 block mb-2"> | ||
| {label} | ||
| </label> | ||
| <input | ||
| type="number" | ||
| className="w-full bg-slate-900/50 border border-white/10 rounded-xl px-4 py-2.5 outline-none focus:border-amber-500/50 transition-all text-sm font-medium" | ||
| value={form.numberMetrics[statKey] ?? ""} | ||
| onChange={(event) => | ||
| setNumberForm(statKey, parseFloat(event.target.value)) | ||
| } | ||
| placeholder={placeholder} | ||
| /> | ||
| </div> | ||
| ); | ||
| }; |
191 changes: 191 additions & 0 deletions
191
apps/scouting/frontend/src/strategy/tabs/pit-scout/PitScoutTab.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,191 @@ | ||
| //בס"ד | ||
|
|
||
| import { useState, type FC } from "react"; | ||
| import type { | ||
| PitScout, | ||
| PitScoutBoolean, | ||
| PitScoutBooleanKey, | ||
| PitScoutBooleanMetric, | ||
| PitScoutNumber, | ||
| PitScoutNumberKey, | ||
| } from "@repo/scouting_types"; | ||
| import { NumberStats } from "./NumberStats"; | ||
| import { BooleanStats } from "./BooleanStats"; | ||
|
|
||
| const NUMBER_FIELDS: { | ||
| statKey: PitScoutNumberKey; | ||
| label: string; | ||
| placeholder: string; | ||
| }[] = [ | ||
| { | ||
| statKey: "robotWeight", | ||
| label: "Robot Weight (lbs)", | ||
| placeholder: "e.g. 120", | ||
| }, | ||
| { statKey: "ballCapacity", label: "Ball Capacity", placeholder: "e.g. 50" }, | ||
| ]; | ||
|
karnishein marked this conversation as resolved.
|
||
|
|
||
| const PIT_SCOUT_URL = "/api/v1/pit/"; | ||
|
|
||
| const BOOLEAN_FIELDS: { statKey: PitScoutBooleanKey; label: string }[] = [ | ||
| { statKey: "hasTurret", label: "Has turret?" }, | ||
| { statKey: "canPassTrench", label: "Can pass trench?" }, | ||
| { statKey: "canPassBumpEasily", label: "Can pass bump easily?" }, | ||
| ]; | ||
|
|
||
| const initialState: PitScout = { | ||
| teamNumber: 0, | ||
| numberMetrics: { robotWeight: undefined, ballCapacity: undefined }, | ||
| booleanMetrics: { | ||
| hasTurret: undefined, | ||
| canPassTrench: undefined, | ||
| canPassBumpEasily: undefined, | ||
| }, | ||
| extraInfo: undefined, | ||
| }; | ||
|
|
||
| export const PitScoutTab: FC = () => { | ||
| const [form, setForm] = useState<PitScout>(initialState); | ||
| const [status, setStatus] = useState< | ||
| "idle" | "loading" | "success" | "error" | ||
| >("idle"); | ||
| const [errorMsg, setErrorMsg] = useState(""); | ||
|
|
||
| const setNumberForm = (key: PitScoutNumberKey, value: number) => | ||
| setForm((form) => ({ | ||
| ...form, | ||
| numberMetrics: { ...form.numberMetrics, [key]: value || undefined }, | ||
| })); | ||
| const setBoolForm = (key: PitScoutBooleanKey, value: PitScoutBooleanMetric) => | ||
| setForm((form) => ({ | ||
| ...form, | ||
| booleanMetrics: { | ||
| ...form.booleanMetrics, | ||
| [key]: form.booleanMetrics[key] === value ? undefined : value, | ||
| }, | ||
| })); | ||
|
|
||
| const setExtraForm = (value: string) => | ||
| setForm((form) => ({ ...form, extraInfo: value || undefined })); | ||
|
|
||
| const handleSubmit = async () => { | ||
| if (!form.teamNumber) { | ||
| setStatus("error"); | ||
| setErrorMsg("Team number is required."); | ||
| return; | ||
| } | ||
|
|
||
| setStatus("loading"); | ||
| try { | ||
| const res = await fetch(PIT_SCOUT_URL, { | ||
| method: "POST", | ||
| headers: { "Content-Type": "application/json" }, | ||
| body: JSON.stringify(form), | ||
| }); | ||
|
|
||
| if (res.ok) { | ||
| setStatus("success"); | ||
| setForm(initialState); | ||
| } else { | ||
| const text = await res.text(); | ||
| setStatus("error"); | ||
| setErrorMsg(text || "Submission failed."); | ||
| } | ||
| } catch (error) { | ||
| setStatus("error"); | ||
| setErrorMsg(error instanceof Error ? error.message : "Network error."); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="flex flex-col items-center gap-6 max-w-2xl mx-auto pb-12 text-slate-200"> | ||
| <div className="w-full bg-slate-800/40 border border-white/5 p-6 rounded-2xl backdrop-blur-sm shadow-xl"> | ||
| <h2 className="text-xs font-black uppercase tracking-[0.2em] text-amber-500 mb-4"> | ||
| Team Identification | ||
| </h2> | ||
| <div className="flex flex-col gap-2"> | ||
| <label className="text-[10px] font-bold uppercase text-slate-500 ml-1"> | ||
| Team Number | ||
| </label> | ||
| <input | ||
| type="number" | ||
| className="bg-slate-900/50 border border-white/10 rounded-xl px-4 py-3 text-xl font-mono focus:border-amber-500/50 outline-none transition-all placeholder:text-slate-700" | ||
| value={form.teamNumber || ""} | ||
| onChange={(event) => | ||
| setForm((form) => ({ | ||
| ...form, | ||
| teamNumber: parseInt(event.target.value) || 0, | ||
| })) | ||
| } | ||
| placeholder="0000" | ||
| /> | ||
|
karnishein marked this conversation as resolved.
|
||
| </div> | ||
| </div> | ||
|
|
||
| <div className="w-full grid grid-cols-1 md:grid-cols-2 gap-4"> | ||
| {NUMBER_FIELDS.map(({ statKey: key, label, placeholder }) => ( | ||
| <NumberStats | ||
| statKey={key} | ||
| label={label} | ||
| placeholder={placeholder} | ||
| form={form} | ||
| setNumberForm={setNumberForm} | ||
| /> | ||
| ))} | ||
| </div> | ||
|
|
||
| <div className="w-full bg-slate-800/40 border border-white/5 p-6 rounded-2xl"> | ||
| <h2 className="text-xs font-black uppercase tracking-[0.2em] text-amber-500 mb-6"> | ||
| Mechanical Capabilities | ||
| </h2> | ||
| <div className="grid gap-4"> | ||
| {BOOLEAN_FIELDS.map(({ statKey: key, label }) => ( | ||
| <BooleanStats | ||
| statKey={key} | ||
| label={label} | ||
| form={form} | ||
| setBoolForm={setBoolForm} | ||
| /> | ||
| ))} | ||
| </div> | ||
| </div> | ||
|
|
||
| <div className="w-full bg-slate-800/40 border border-white/5 p-6 rounded-2xl"> | ||
| <h2 className="text-xs font-black uppercase tracking-[0.2em] text-amber-500 mb-4"> | ||
| extra information | ||
| </h2> | ||
| <textarea | ||
| className="w-full bg-slate-900/50 border border-white/10 rounded-xl p-4 min-h-[120px] outline-none focus:border-amber-500/50 transition-all text-sm resize-none placeholder:text-slate-700" | ||
| value={form.extraInfo ?? ""} | ||
| onChange={(event) => setExtraForm(event.target.value)} | ||
| placeholder="Enter extra observations..." | ||
| /> | ||
| </div> | ||
|
|
||
| <div className="w-full flex flex-col items-center gap-4 mt-4"> | ||
| <button | ||
| onClick={handleSubmit} | ||
| disabled={status === "loading"} | ||
| className="w-full max-w-xs py-4 bg-emerald-500 text-slate-950 text-xs font-black uppercase tracking-widest rounded-xl | ||
| disabled:opacity-40 hover:bg-emerald-400 transition-all active:scale-95 | ||
| shadow-lg shadow-emerald-900/20" | ||
| > | ||
| {status === "loading" ? "Transmitting..." : "Submit"} | ||
| </button> | ||
|
|
||
| {status === "success" && ( | ||
| <div className="flex items-center gap-2 text-emerald-400 animate-pulse"> | ||
| <span className="text-[10px] font-black tracking-widest uppercase"> | ||
| ✓ Data Synced Successfully | ||
| </span> | ||
| </div> | ||
| )} | ||
| {status === "error" && ( | ||
| <div className="text-rose-400 text-[10px] font-black tracking-widest uppercase bg-rose-500/10 border border-rose-500/20 px-4 py-2 rounded-lg"> | ||
| ⚠ ERROR: {errorMsg} | ||
| </div> | ||
| )} | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove before merging