-
Notifications
You must be signed in to change notification settings - Fork 0
TBA integration with scouting #9
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
YoniKiriaty
wants to merge
9
commits into
master
Choose a base branch
from
scouting/tba
base: master
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
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ec4f6fd
Yoni - started adding basic tba route with types and verification
YoniKiriaty db0ee1d
Yoni - started typing
YoniKiriaty d82ad25
Yoni - started adding types for matche
YoniKiriaty 92e4ff3
Yoni - changed post output
YoniKiriaty a0afd7d
Yoni - improved backend communication while adding matches types
YoniKiriaty aa2e1d6
Yoni - forgot to update tba router types
YoniKiriaty bab91e0
Yoni - removed test
YoniKiriaty 747a0d4
Yoni - better typing and fixed some according to CR
YoniKiriaty 034353c
Yoni - removed useless imports
YoniKiriaty 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // בס"ד | ||
| import type { RequestHandler } from "express"; | ||
| import { isLeft } from "fp-ts/lib/Either"; | ||
| import { StatusCodes } from "http-status-codes"; | ||
| import { PathReporter } from "io-ts/lib/PathReporter"; | ||
| import type { Props, TypeC } from "io-ts"; | ||
|
|
||
| export const verifyBody = | ||
| <U extends Props>(typeToCheck: TypeC<U>): RequestHandler => | ||
| (req, res, next): void => { | ||
| const result = typeToCheck.decode(req.body); | ||
|
|
||
| if (isLeft(result)) { | ||
| res | ||
| .status(StatusCodes.NOT_ACCEPTABLE) | ||
| .json({ errors: PathReporter.report(result) }); | ||
| } else { | ||
| next(); | ||
| } | ||
| }; |
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 |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| // בס"ד | ||
| import { Router } from "express"; | ||
| import { StatusCodes } from "http-status-codes"; | ||
| import { tbaRouter } from "./tba"; | ||
|
|
||
| export const apiRouter = Router(); | ||
|
|
||
| apiRouter.use("/tba", tbaRouter); | ||
| apiRouter.get("/health", (req, res) => { | ||
| res.status(StatusCodes.OK).send({ message: "Healthy!" }); | ||
| }); | ||
| }); |
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,43 @@ | ||
| // בס"ד | ||
| import axios, { type AxiosRequestConfig } from "axios"; | ||
| import { Router } from "express"; | ||
| import { verifyBody } from "../middleware/verification"; | ||
| import { | ||
| type TBAMatch, | ||
| type TBAMatchesProps, | ||
| matchesProps, | ||
| } from "../../../common/types/TBAMatch"; | ||
| import { StatusCodes } from "http-status-codes"; | ||
| import type { ScoreBreakdown2025 } from "../../../common/types/ScoreBreakdown2025"; | ||
| import type { BodiedRequest } from "../../../common/types/Express"; | ||
|
|
||
| export const tbaRouter = Router(); | ||
|
|
||
| const TBA_KEY = process.env.TBA_API_KEY ?? "yourtbakey"; | ||
|
|
||
| const fetchTba = async <T>( | ||
| route: string, | ||
| config?: AxiosRequestConfig | ||
| ): Promise<T> => { | ||
| return axios | ||
| .get(`https://www.thebluealliance.com/api/v3${route}`, { | ||
| headers: { "X-TBA-Auth-Key": TBA_KEY }, | ||
| ...config, | ||
| }) | ||
| .then((value) => value.data as T); | ||
|
||
| }; | ||
|
|
||
| tbaRouter.post( | ||
| "/matches", | ||
| verifyBody(matchesProps), | ||
| (req: BodiedRequest<TBAMatchesProps>, res) => { | ||
| fetchTba<TBAMatch<ScoreBreakdown2025>>(`/event/${req.body.event}/matches`) | ||
| .then((value) => { | ||
| console.log(value); | ||
| res.status(StatusCodes.OK).json({ value }); | ||
| }) | ||
| .catch((error: unknown) => { | ||
| console.error(error); | ||
| }); | ||
| } | ||
| ); | ||
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,7 @@ | ||
| // בס"ד | ||
|
|
||
| import type { Request } from "express"; | ||
|
|
||
| export interface BodiedRequest<Body> extends Request { | ||
| body: Body; | ||
| } |
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,57 @@ | ||
| // בס"ד | ||
|
|
||
| type YesNo = "Yes" | "No"; | ||
|
|
||
| type Climb = "Park" | "DeepCage" | "ShallowCage" | "None"; | ||
|
|
||
| interface ReefRow { | ||
| nodeA: boolean; | ||
| nodeB: boolean; | ||
| nodeC: boolean; | ||
| nodeD: boolean; | ||
| nodeE: boolean; | ||
| } | ||
| interface Reef { | ||
| botRow: ReefRow; | ||
| midRow: ReefRow; | ||
| tba_botRowCount: number; | ||
| tba_midRowCount: number; | ||
| tba_topRowCount: number; | ||
| topRow: ReefRow; | ||
| trough: number; | ||
| } | ||
| export interface ScoreBreakdown2025 { | ||
| adjustPoints: number; | ||
| algaePoints: number; | ||
| autoBonusAchieved: boolean; | ||
| autoCoralCount: number; | ||
| autoCoralPoints: number; | ||
| autoLineRobot1: YesNo; | ||
| autoLineRobot2: YesNo; | ||
| autoLineRobot3: YesNo; | ||
| autoMobilityPoints: number; | ||
| autoPoints: number; | ||
| autoReef: Reef; | ||
| bargeBonusAchieved: boolean; | ||
| coopertitionCriteriaMet: boolean; | ||
| coralBonusAchieved: boolean; | ||
| endGameBargePoints: number; | ||
| endGameRobot1: Climb; | ||
| endGameRobot2: Climb; | ||
| endGameRobot3: Climb; | ||
| foulCount: number; | ||
| foulPoints: number; | ||
| g206Penalty: boolean; | ||
| g410Penalty: boolean; | ||
| g418Penalty: boolean; | ||
| g428Penalty: boolean; | ||
| netAlgaeCount: number; | ||
| rp: number; | ||
| techFoulCount: number; | ||
| teleopCoralCount: number; | ||
| teleopCoralPoints: number; | ||
| teleopPoints: number; | ||
| teleopReef: Reef; | ||
| totalPoints: number; | ||
| wallAlgaeCount: number; | ||
| } |
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,46 @@ | ||
| // בס"ד | ||
| import * as t from "io-ts"; | ||
| import type { AtMost } from "./Utils"; | ||
|
|
||
| export const matchesProps = t.type({ | ||
| event: t.string, | ||
| }); | ||
|
|
||
| export type TBAMatchesProps = t.TypeOf<typeof matchesProps>; | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cheater!!!! |
||
| const maxTeamsInAlliance = 3; | ||
| type TeamKeys = AtMost<string, typeof maxTeamsInAlliance>; | ||
|
|
||
| export interface TBAAlliance { | ||
| score: number; | ||
| team_keys: TeamKeys; | ||
| surrogate_team_keys: TeamKeys; | ||
| dq_team_keys: TeamKeys; | ||
| } | ||
|
|
||
|
|
||
| export interface TBAMatch<AllianceBreakdown, MiscBreakdown = {}> { | ||
| key: "string"; | ||
| comp_level: "qm"; | ||
| set_number: number; | ||
| match_number: number; | ||
| alliances: { | ||
| red: TBAAlliance; | ||
| blue: TBAAlliance; | ||
| }; | ||
| winning_alliance: "red" | "blue" | ""; // "" is a tie | ||
| event_key: string; | ||
| time: number; | ||
| actual_time: number; | ||
| predicted_time: number; | ||
| post_result_time: number; | ||
| score_breakdown: { | ||
| red: AllianceBreakdown; | ||
| blue: AllianceBreakdown; | ||
| } & MiscBreakdown; | ||
| videos: { | ||
| type: string; | ||
| key: string; | ||
| }[]; | ||
| } | ||
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,13 @@ | ||
| // בס"ד | ||
|
|
||
|
|
||
| type AtMostUnion<T extends unknown[]> = | ||
| T extends [infer _, ...infer Rest] | ||
|
||
| ? T | AtMostUnion<Rest> | ||
| : []; | ||
|
|
||
|
|
||
| export type AtMost<T, N extends number, Result extends unknown[] = []> = | ||
| Result['length'] extends N | ||
| ? Result | AtMostUnion<Result> | ||
| : AtMost<T, N, [T, ...Result]>; | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.