Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/scouting/backend/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { build, context } from "esbuild";
import { spawn } from "child_process";

const isDev = process.env.NODE_ENV === "DEV";
const isDev = process.env.NODE_ENV !== "DEV";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to fix this on your computer 😭


const bundlePath = "dist/bundle.js";

Expand Down
2 changes: 1 addition & 1 deletion apps/scouting/backend/src/fuel/distance-split.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { convertPixelToCentimeters, distanceFromHub } from "@repo/rebuilt_map";
import type { FuelEvents, FuelObject } from "./fuel-object";
import { calculateAverage } from "@repo/array-functions";

const averageFuel = (fuels: FuelObject[]): FuelObject => {
export const averageFuel = (fuels: FuelObject[]): FuelObject => {
const averageOfKey = (key: FuelEvents) =>
calculateAverage(fuels, (value) => value[key]);
return {
Expand Down
9 changes: 2 additions & 7 deletions apps/scouting/backend/src/fuel/fuel-general.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
// בס"ד
import type { BPS, FuelObject } from "./fuel-object";
import { createFuelObject } from "./fuel-object";
import type { ScoutingForm, ShiftsArray } from "@repo/scouting_types";
import type { BPS, FuelObject, GeneralFuelData, ScoutingForm, ShiftsArray } from "@repo/scouting_types";


interface GeneralFuelData {
fullGame:FuelObject;
auto:FuelObject;
tele:FuelObject;
}

const calculateFuelStatisticsOfShift = (
match: ScoutingForm["match"],
Expand Down
3 changes: 1 addition & 2 deletions apps/scouting/backend/src/fuel/fuel-object.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// בס"ד
import type { GameObject } from "../game-object";
import type { Match, Point, ShootEvent } from "@repo/scouting_types";
import type { GameObject, Match, Point, ShootEvent } from "@repo/scouting_types";
import { calculateFuelByAveraging } from "./calculations/fuel-averaging";
import { calculateFuelByMatch } from "./calculations/fuel-match";

Expand Down
15 changes: 0 additions & 15 deletions apps/scouting/backend/src/game-object.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,2 @@
// בס"ד

export type GameObject<T extends string, AdditionalInfo> = Record<T, number> &
AdditionalInfo;

export const addGameEvent = <T extends string>(
gameObject: GameObject<T, unknown>,
event: T,
): void => {
gameObject[event]++;
};

export interface GameObjectWithPoints<T extends string> {
gameObject: GameObject<T, unknown>;
calculatePoints: (gameObject: GameObject<T, unknown>) => number;
calculateRP: (gameObject: GameObject<T, unknown>) => number;
}
6 changes: 3 additions & 3 deletions apps/scouting/backend/src/routes/forms-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import { mongofyQuery } from "../middleware/query";

export const formsRouter = Router();

const getCollection = flow(
export const getFormsCollection = flow(
getDb,
map((db) => db.collection<ScoutingForm>("forms")),
);

formsRouter.get("/", async (req, res) => {
await pipe(
getCollection(),
getFormsCollection(),
map((collection) => collection.find(mongofyQuery(req.query)).toArray()),
fold(
(error) => () =>
Expand All @@ -32,7 +32,7 @@ formsRouter.get("/", async (req, res) => {

formsRouter.post("/single", async (req, res) => {
await pipe(
getCollection(),
getFormsCollection(),
flatMap((collection) =>
pipe(
right(req),
Expand Down
126 changes: 126 additions & 0 deletions apps/scouting/backend/src/routes/general-router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
//בס"ד
/* eslint-disable @typescript-eslint/no-magic-numbers */ //for the example bps

import { Router } from "express";
import { getFormsCollection } from "./forms-router";
import { pipe } from "fp-ts/lib/function";
import { flatMap, fold, map, tryCatch } from "fp-ts/lib/TaskEither";
import { mongofyQuery } from "../middleware/query";
import { generalCalculateFuel } from "../fuel/fuel-general";
import { StatusCodes } from "http-status-codes";

import type {
BPS,
FuelObject,
GeneralFuelData,
} from "@repo/scouting_types";
import { averageFuel } from "../fuel/distance-split";
import { firstElement, isEmpty } from "@repo/array-functions";

export const generalRouter = Router();

interface AccumulatedFuelData {
fullGame: FuelObject[];
auto: FuelObject[];
tele: FuelObject[];
}

const EXAMPLE_BPS: BPS[] = [
{
match: {
number: 42,
type: "qualification",
},
events: [
{
shoot: [12, 45, 88, 110],
score: [12, 88],
},
{
shoot: [135, 140],
score: [135, 140],
},
],
},
];

const ONE_ITEM_ARRAY = 1;

const calcAverageGeneralFuelData = (fuelData: GeneralFuelData[]) => {
if (fuelData.length === ONE_ITEM_ARRAY || isEmpty(fuelData)) {
return firstElement(fuelData);
}

const accumulatedFuelData: AccumulatedFuelData =
fuelData.reduce<AccumulatedFuelData>(
(accumulated, currentFuelData) => ({
fullGame: [...accumulated.fullGame, currentFuelData.fullGame],
auto: [...accumulated.auto, currentFuelData.auto],
tele: [...accumulated.tele, currentFuelData.tele],
}),
{
fullGame: [],
auto: [],
tele: [],
},
);

const averagedFuelData: GeneralFuelData = {
fullGame: averageFuel(accumulatedFuelData.fullGame),
auto: averageFuel(accumulatedFuelData.auto),
tele: averageFuel(accumulatedFuelData.tele),
};

return averagedFuelData;
};

generalRouter.get("/", async (req, res) => {
await pipe(
getFormsCollection(),
flatMap((collection) =>
tryCatch(
() => collection.find(mongofyQuery(req.query)).toArray(),
(error) => ({
status: StatusCodes.INTERNAL_SERVER_ERROR,
reason: `DB Error: ${error}`,
}),
),
),
map((forms) =>
forms.map((form) => ({
teamNumber: form.teamNumber,
generalFuelData: generalCalculateFuel(form, EXAMPLE_BPS),
})),
),

map((generalFuelsData) =>
generalFuelsData.reduce<Record<number, GeneralFuelData[]>>(
(accumulatorRecord, fuelData) => ({
...accumulatorRecord,
[fuelData.teamNumber]: [
...accumulatorRecord[fuelData.teamNumber],
fuelData.generalFuelData,
],
}),
{},
),
),

map((teamAndAllFuelData) => {
const teamAndAvaragedFuelData: Record<number, GeneralFuelData> = {};
Object.entries(teamAndAllFuelData).forEach(([teamNumber, fuelArray]) => {
teamAndAvaragedFuelData[teamNumber] =
calcAverageGeneralFuelData(fuelArray);
});

return teamAndAvaragedFuelData;
}),

fold(
(error) => () =>
Promise.resolve(res.status(error.status).send(error.reason)),
(calculatedFuel) => () =>
Promise.resolve(res.status(StatusCodes.OK).json({ calculatedFuel })),
),
)();
});
6 changes: 4 additions & 2 deletions apps/scouting/backend/src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import { StatusCodes } from "http-status-codes";
import { tbaRouter } from "./tba";
import { gameRouter } from "./game-router";
import { formsRouter } from "./forms-router";
import { generalRouter } from "./general-router";

export const apiRouter = Router();

apiRouter.use("/forms",formsRouter);
apiRouter.use("/forms", formsRouter);
apiRouter.use("/tba", tbaRouter);
apiRouter.use("/game", gameRouter);
apiRouter.use("/general", generalRouter);

apiRouter.get("/health", (req, res) => {
res.status(StatusCodes.OK).send({ message: "Healthy!" });
});
});
8 changes: 4 additions & 4 deletions apps/scouting/frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import type { FC } from "react";
import { ScoutMatch } from "./scouter/pages/ScoutMatch";
import { Route, Routes } from "react-router-dom";
import { ScoutedMatches } from "./scouter/pages/ScoutedMatches";
import { GeneralDataTable } from "./scouter/components/GeneralDataTable";

const App: FC = () => {
return (
<Routes>
<Route path="*" element={<ScoutedMatches />} />
<Route path="/scout" element={<ScoutMatch />} />
</Routes>
<>
<GeneralDataTable filters={{ "match[type]": "qualification" }} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove before merging

</>
);
};
export default App;
Loading
Loading