Repository navigation
Broken robot filter #196
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
Merged
Merged
Broken robot filter #196
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3ec5b87
karni- excluded broken games from all averages, and colored the broke…
karnishein e4cc1dd
karni- added a column to general table and added correct calculations.
karnishein 00d07d9
karni- made it so the data is not deleted from the db each time
karnishein 6ddb0b6
karni- added PATCH request
karnishein 711395c
karni- added frontend - great win
karnishein c3a4556
karni- fixed Hillel's CR comments
karnishein b934729
karni- back to string
karnishein 7afd22c
karni- added a box for times robot broke
karnishein dc73e47
karni- removed
karnishein fadc4f7
karni: keyboard burped
karnishein 743ade6
Merge branch 'master' into broken-robot-filter
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 |
|---|---|---|
| @@ -1,107 +1,107 @@ | ||
| //בס"ד | ||
| //בס"ד | ||
|
|
||
| import { Router } from "express"; | ||
|
karnishein marked this conversation as resolved.
Resolved
|
||
| import { flow, pipe } from "fp-ts/lib/function"; | ||
| import { map, bind, right, fromEither, bindTo } from "fp-ts/lib/TaskEither"; | ||
| import { | ||
| createBodyVerificationPipe, | ||
| flatTryCatch, | ||
| foldResponse, | ||
| } from "@repo/flow-utils"; | ||
| import { getTotalGeneralData } from "./general-router"; | ||
| import { getDb } from "../middleware/db"; | ||
| import { StatusCodes } from "http-status-codes"; | ||
| import { DataPicklistBee, GeneralBeeData } from "@repo/scouting_types"; | ||
| import { right as rightEither } from "fp-ts/lib/Either"; | ||
| import { PicklistBee, picklistBeeCodec } from "@repo/scouting_types"; | ||
| import { Router } from "express"; | ||
| import { flow, pipe } from "fp-ts/lib/function"; | ||
| import { map, bind, right, fromEither, bindTo } from "fp-ts/lib/TaskEither"; | ||
| import { | ||
| createBodyVerificationPipe, | ||
| flatTryCatch, | ||
| foldResponse, | ||
| } from "@repo/flow-utils"; | ||
| import { getTotalGeneralData } from "./general-router"; | ||
| import { getDb } from "../middleware/db"; | ||
| import { StatusCodes } from "http-status-codes"; | ||
| import { DataPicklistBee, GeneralBeeData } from "@repo/scouting_types"; | ||
| import { right as rightEither } from "fp-ts/lib/Either"; | ||
| import { PicklistBee, picklistBeeCodec } from "@repo/scouting_types"; | ||
|
|
||
| export const picklistRouter = Router(); | ||
| export const picklistRouter = Router(); | ||
|
|
||
| export const getPicklistCollection = flow( | ||
| getDb, | ||
| map((db) => db.collection<PicklistBee>("picklist")), | ||
| ); | ||
| export const getPicklistCollection = flow( | ||
| getDb, | ||
| map((db) => db.collection<PicklistBee>("picklist")), | ||
| ); | ||
|
|
||
| const createNewPickList = ( | ||
| data: GeneralBeeData, | ||
| name: string, | ||
| ): PicklistBee => ({ | ||
| name, | ||
| list: Object.entries(data) | ||
| .map(([team, data]) => ({ | ||
| team, | ||
| data, | ||
| })) | ||
| .sort( | ||
| (teamA, teamB) => teamB.data.full.fuelScored - teamA.data.full.fuelScored, | ||
| //sorts from highest score to lowest | ||
| ) | ||
| .map(({ team }) => team), | ||
| }); | ||
| const createNewPickList = ( | ||
| data: GeneralBeeData, | ||
| name: string, | ||
| ): PicklistBee => ({ | ||
| name, | ||
| list: Object.entries(data) | ||
| .map(([team, data]) => ({ | ||
| team, | ||
| data, | ||
| })) | ||
| .sort( | ||
| (teamA, teamB) => teamB.data.full.fuelScored - teamA.data.full.fuelScored, | ||
| //sorts from highest score to lowest | ||
| ) | ||
| .map(({ team }) => team), | ||
| }); | ||
|
|
||
| picklistRouter.get("/list/:picklist/:recency", async (req, res) => { | ||
| await pipe( | ||
| getTotalGeneralData(parseInt(req.params.recency)), | ||
| bind("picklistCollection", getPicklistCollection), | ||
| bind("name", () => right(req.params.picklist)), | ||
| flatTryCatch( | ||
| async ({ generalData, picklistCollection, name }) => ({ | ||
| generalData, | ||
| picklist: | ||
| (await picklistCollection.findOne({ name })) ?? | ||
| createNewPickList(generalData, name), | ||
| }), | ||
| (error) => ({ | ||
| status: StatusCodes.INTERNAL_SERVER_ERROR, | ||
| reason: `Error Getting List From DB: ${error}`, | ||
| }), | ||
| ), | ||
| map(({ generalData, picklist }) => ({ | ||
| name: picklist.name, | ||
| list: picklist.list.map((team) => generalData[team]), | ||
| })), | ||
| map((picklist) => picklist satisfies DataPicklistBee), | ||
| foldResponse(res), | ||
| )(); | ||
| }); | ||
| picklistRouter.get("/list/:picklist/:recency", async (req, res) => { | ||
| await pipe( | ||
| getTotalGeneralData(parseInt(req.params.recency)), | ||
| bind("picklistCollection", getPicklistCollection), | ||
| bind("name", () => right(req.params.picklist)), | ||
| flatTryCatch( | ||
| async ({ generalData, picklistCollection, name }) => ({ | ||
| generalData, | ||
| picklist: | ||
| (await picklistCollection.findOne({ name })) ?? | ||
| createNewPickList(generalData, name), | ||
| }), | ||
| (error) => ({ | ||
| status: StatusCodes.INTERNAL_SERVER_ERROR, | ||
| reason: `Error Getting List From DB: ${error}`, | ||
| }), | ||
| ), | ||
| map(({ generalData, picklist }) => ({ | ||
| name: picklist.name, | ||
| list: picklist.list.map((team) => generalData[team]), | ||
| })), | ||
| map((picklist) => picklist satisfies DataPicklistBee), | ||
| foldResponse(res), | ||
| )(); | ||
| }); | ||
|
|
||
| picklistRouter.post("/list", async (req, res) => { | ||
| await pipe( | ||
| getPicklistCollection(), | ||
| bindTo("picklistCollection"), | ||
| bind("picklist", () => | ||
| pipe( | ||
| rightEither(req), | ||
| createBodyVerificationPipe(picklistBeeCodec), | ||
| fromEither, | ||
| picklistRouter.post("/list", async (req, res) => { | ||
| await pipe( | ||
| getPicklistCollection(), | ||
| bindTo("picklistCollection"), | ||
| bind("picklist", () => | ||
| pipe( | ||
| rightEither(req), | ||
| createBodyVerificationPipe(picklistBeeCodec), | ||
| fromEither, | ||
| ), | ||
| ), | ||
| ), | ||
| flatTryCatch( | ||
| ({ picklist, picklistCollection }) => | ||
| picklistCollection.replaceOne({ name: picklist.name }, picklist, { | ||
| upsert: true, //makes it add the picklist if it cant find one with the same name | ||
| flatTryCatch( | ||
| ({ picklist, picklistCollection }) => | ||
| picklistCollection.replaceOne({ name: picklist.name }, picklist, { | ||
| upsert: true, //makes it add the picklist if it cant find one with the same name | ||
| }), | ||
| (error) => ({ | ||
| status: StatusCodes.INTERNAL_SERVER_ERROR, | ||
| reason: `Error inserting into DB ${error}`, | ||
| }), | ||
| (error) => ({ | ||
| status: StatusCodes.INTERNAL_SERVER_ERROR, | ||
| reason: `Error inserting into DB ${error}`, | ||
| }), | ||
| ), | ||
| foldResponse(res), | ||
| )(); | ||
| }); | ||
| ), | ||
| foldResponse(res), | ||
| )(); | ||
| }); | ||
|
|
||
| picklistRouter.get("/lists", async (req, res) => { | ||
| await pipe( | ||
| getPicklistCollection(), | ||
| picklistRouter.get("/lists", async (req, res) => { | ||
| await pipe( | ||
| getPicklistCollection(), | ||
|
|
||
| flatTryCatch( | ||
| (collection) => collection.find().toArray(), | ||
| (error) => ({ | ||
| status: StatusCodes.INTERNAL_SERVER_ERROR, | ||
| reason: `Error inserting into DB ${error}`, | ||
| }), | ||
| ), | ||
| map((lists) => lists.map(({ name }) => name)), | ||
| foldResponse(res), | ||
| )(); | ||
| }); | ||
| flatTryCatch( | ||
| (collection) => collection.find().toArray(), | ||
| (error) => ({ | ||
| status: StatusCodes.INTERNAL_SERVER_ERROR, | ||
| reason: `Error inserting into DB ${error}`, | ||
| }), | ||
| ), | ||
| map((lists) => lists.map(({ name }) => name)), | ||
| 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
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.
its strange it said you deleated it