-
Notifications
You must be signed in to change notification settings - Fork 0
General data showing #40
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
18
commits into
master
Choose a base branch
from
general-data-showing
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
18 commits
Select commit
Hold shift + click to select a range
823a6f9
karni- started working on the router
karnishein b555d88
karni- started working on the router
karnishein c47f4a0
karni- wrote the get command
karnishein 22a6a80
karni- added a fuel types folder
karnishein f104363
karni- no magic numbers
karnishein 9c7483b
karni- started working on the table component
karnishein cdea5aa
karni- trying my best
karnishein 8cbeb73
karni- code might work, god is real
karnishein 58920aa
karni- finished the table - ready for pr
karnishein 36a3a59
karni- fixed the way I process some of the data
karnishein 6996dd8
karni- merged with master
karnishein ae3718a
karni- fixed the averaging
karnishein b310c26
karni- changed how I accumulate the records idk
karnishein 15aba54
karni- added an index for fuel
karnishein 5b1c653
karni- no return no no (Hara al return)
karnishein 08be5c8
karni- StatusCodes.INTERNAL_SERVER_ERROR
karnishein e3bfaed
karni- fixed final things
karnishein 2c0e0e8
karni- removed unused
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
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 |
|---|---|---|
| @@ -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; | ||
| } |
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,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; | ||
karnishein marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }), | ||
|
|
||
| fold( | ||
| (error) => () => | ||
| Promise.resolve(res.status(error.status).send(error.reason)), | ||
| (calculatedFuel) => () => | ||
| Promise.resolve(res.status(StatusCodes.OK).json({ calculatedFuel })), | ||
| ), | ||
| )(); | ||
| }); | ||
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 |
|---|---|---|
|
|
@@ -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" }} /> | ||
|
Contributor
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. remove before merging |
||
| </> | ||
| ); | ||
| }; | ||
| export default App; | ||
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.
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.
we need to fix this on your computer 😭