Skip to content

Commit

Permalink
Merge branch 'alliances' of https://github.com/Decatur-Robotics/Gearbox
Browse files Browse the repository at this point in the history
… into alliances
  • Loading branch information
BanEvading committed Feb 14, 2025
2 parents d469613 + 9fd4941 commit 8f2928b
Show file tree
Hide file tree
Showing 17 changed files with 574 additions and 35 deletions.
2 changes: 1 addition & 1 deletion components/forms/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export default function Form(props: FormProps) {

const elements = [];

// console.log(`Block: ${rowCount}x${colCount}: ${block.flat().map(e => e.key).join(", ")}`);
//console.log(`Block: ${rowCount}x${colCount}: ${block.flat().map(e => e.key).join(", ")}`);
for (let r = 0; r < rowCount; r++) {
for (let c = 0; c < colCount; c++) {
let topRounding = "",
Expand Down
16 changes: 4 additions & 12 deletions components/stats/SmallGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,7 @@ export default function SmallGraph(props: {
};

useEffect(() => {
if (
!props.selectedReports ||
(datapoints && currentTeam === props.team && false)
)
return;
if (!props.selectedReports) return;

setDataPoints([]);
setCurrentTeam(props.team);
Expand All @@ -126,7 +122,7 @@ export default function SmallGraph(props: {
);
});
}
}, [key, currentTeam, datapoints, props.selectedReports, props.team]);
}, [key, currentTeam, props.selectedReports, props.team]);

if (!props.selectedReports) {
return <></>;
Expand All @@ -141,13 +137,9 @@ export default function SmallGraph(props: {
console.log(e.target.value);
setKey(e.target.value);
}}
defaultValue={"selected"}
>
<option
disabled
selected
>
Select Variable
</option>
<option disabled>Select Variable</option>
{keys.map((key) => (
<option
key={key}
Expand Down
28 changes: 28 additions & 0 deletions lib/Enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,31 @@ export namespace IntoTheDeepEnums {
HighLevelClimb = "High Level Climb",
}
}

export namespace ReefscapeEnums {
export enum EndgameClimbStatus {
None = "None",
Park = "Park",
High = "High",
Low = "Low",
}

export enum DriveThroughDeepCage {
No = "No",
Slow = "Slow",
Fast = "Fast",
}

export enum AutoCapabilities {
NoAuto = "No Auto",
MovePastStart = "Move Past Start",
ScoreOneCoral = "Score One Coral",
ScoreMoreThanOneCoral = "ScoreMoreThanOneCoral",
}

export enum Climbing {
No = "No",
Deep = "Deep",
Shallow = "Shallow",
}
}
18 changes: 18 additions & 0 deletions lib/Layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
CenterStageEnums,
IntoTheDeepEnums,
FtcDrivetrain,
ReefscapeEnums,
} from "./Enums";
import { PitReportData, QuantData, Pitreport, Report, League } from "./Types";

Expand Down Expand Up @@ -143,6 +144,14 @@ export type StatPair<
label: string;
};

export type StatGroup<
TPitData extends PitReportData,
TQuantData extends QuantData,
> = {
stats: Stat<TPitData, TQuantData>[];
label: string;
};

export type StatsLayout<
TPitData extends PitReportData,
TQuantData extends QuantData,
Expand Down Expand Up @@ -204,6 +213,10 @@ export function keyToType(
CenterStageEnums.AutoSidePreference,
IntoTheDeepEnums.StartedWith,
IntoTheDeepEnums.EndgameLevelClimbed,
ReefscapeEnums.AutoCapabilities,
ReefscapeEnums.Climbing,
ReefscapeEnums.DriveThroughDeepCage,
ReefscapeEnums.EndgameClimbStatus,
];

if (key === "Defense") return Defense;
Expand All @@ -213,6 +226,11 @@ export function keyToType(
if (key === "EndgameLevelClimbed")
return IntoTheDeepEnums.EndgameLevelClimbed;

if (key == "AutoCapabilities") return ReefscapeEnums.AutoCapabilities;
if (key == "Climbing") return ReefscapeEnums.Climbing;
if (key == "DriveThroughDeepCage") return ReefscapeEnums.DriveThroughDeepCage;
if (key == "EndgameClimbStatus") return ReefscapeEnums.EndgameClimbStatus;

for (const e of enums) {
if (Object.values(e).includes(exampleData[key])) return e;
}
Expand Down
3 changes: 3 additions & 0 deletions lib/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export class Game<

fieldImagePrefix: string;
coverImage: string;
coverImageClass: string;

getBadges: (
pitData: Pitreport<TPitData> | undefined,
Expand Down Expand Up @@ -204,6 +205,7 @@ export class Game<
pitStatsLayout: PitStatsLayout<TPitData, TQuantData>,
fieldImagePrefix: string,
coverImage: string,
coverImageClass: string | undefined,
getBadges: (
pitData: Pitreport<TPitData> | undefined,
quantitativeReports: Report<TQuantData>[] | undefined,
Expand Down Expand Up @@ -237,6 +239,7 @@ export class Game<

this.fieldImagePrefix = fieldImagePrefix;
this.coverImage = coverImage;
this.coverImageClass = coverImageClass ?? "";

this.getBadges = getBadges;
this.getAvgPoints = getAvgPoints;
Expand Down
2 changes: 1 addition & 1 deletion lib/api/ClientApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ export default class ClientApi extends NextApiTemplate<ApiDependencies> {
isAuthorized: AccessLevels.AlwaysAuthorized,
handler: async (req, res, { tba }, authData, [tbaId]) => {
const compRankings = await tba.req.getCompetitonRanking(tbaId);
return res.status(200).send(compRankings.rankings);
return res.status(200).send(compRankings?.rankings);
},
});

Expand Down
1 change: 1 addition & 0 deletions lib/client/GameId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export enum GameId {
Crescendo = "Crescendo",
CenterStage = "CenterStage",
IntoTheDeep = "IntoTheDeep",
Reefscape = "Reefscape",
}

export const defaultGameId = GameId.Crescendo;
28 changes: 28 additions & 0 deletions lib/client/StatsMath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,31 @@ export function ComparativePercent<T extends QuantData>(

return Round((a / (b + a)) * 100) + "%";
}

/**
* @tested_by tests/lib/client/StatsMath.test.ts
*/
export function ComparativePercentMulti<T extends QuantData>(
selectors: Selector<T>[],
reports: Report<T>[],
) {
const results: string[] = [];
const totals = selectors.map((selectors) =>
NumericalTotal(selectors, reports),
);

let sum = 0;
for (let i = 0; i < totals.length; i++) {
sum += totals[i];
}

for (let i = 0; i < totals.length; i++) {
results.push(Round((totals[i] / sum) * 100) + "%");
}

if (sum === 0) {
return 0;
}

return results;
}
14 changes: 9 additions & 5 deletions lib/client/useInterval.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import { useEffect, useState } from "react";
import { useCallback, useEffect, useState } from "react";

/**
* Can be janky. You've been warned.
*/

export default function useInterval(
func: () => any,
interval: number,
deps: any[] = [],
) {
const [id, setId] = useState<NodeJS.Timeout | undefined>(undefined);
const [id, setId] = useState<NodeJS.Timeout>();
const callback = useCallback(func, [func, ...deps]);

useEffect(() => {
setId(setInterval(func, interval));
return () => clearInterval(id);
}, [func.name, interval, func, id, deps]);
console.log("Setting interval", interval);
const newInterval = setInterval(callback, interval);
setId(newInterval);
return () => clearInterval(newInterval);
}, [interval, callback]);

return id;
}
Loading

0 comments on commit 8f2928b

Please sign in to comment.