Skip to content

Commit

Permalink
backend
Browse files Browse the repository at this point in the history
  • Loading branch information
salvobonsma committed Aug 21, 2024
1 parent fcec149 commit 1970d83
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 4 deletions.
6 changes: 5 additions & 1 deletion lib/database/generate/segments/generate-matches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import {ActionResult} from "@/lib/database/action-result";
import prisma from "@/lib/prisma";

export default async function GenerateMatches(tbaMatch: any, eventId: number, teamEntryId: number): Promise<ActionResult> {
export default async function GenerateMatches(tbaMatch: any, statboticsMatch: any, eventId: number, teamEntryId: number): Promise<ActionResult> {
// Skip in progress matches
if (tbaMatch.actual_time == undefined) return {success: true};

Expand Down Expand Up @@ -51,6 +51,10 @@ export default async function GenerateMatches(tbaMatch: any, eventId: number, te
{
data: {
teamEntryId: teamEntryId,
totalEPA: statboticsMatch?.total_points ?? -1,
autoEPA: statboticsMatch?.auto_points ?? -1,
teleopEPA: statboticsMatch?.teleop_points ?? -1,
endgameEPA: statboticsMatch?.endgame_points ?? -1,
status: "notStarted",
eventId: eventId,
matchKey: tbaMatch.key
Expand Down
20 changes: 19 additions & 1 deletion lib/database/generate/segments/generate-team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,26 @@ export default async function GenerateTeam(tbaTeam: any, eventId: number, year:
return {success: false, message: "TBA API request error (h): " + tbaMatches.response.status}
}

const statboticsMatches = await statbotics.GET("/v3/team_matches", {
params: {
query: {
team: tbaTeam.team_number.toString(),
year: year
}
}
});
if (!statboticsMatches.data) return {
success: false,
message: "Statbotics API request error (i): " + pastSeasons.response.status
};

const generateMatchesError = (await Promise.all(
tbaMatches.data.map((match) => GenerateMatches(match, eventId, teamEntry.id))
tbaMatches.data.map((match) => GenerateMatches(
match,
statboticsMatches.data.find(statboticsMatch => statboticsMatch.match === match.key)?.epa?.breakdown,
eventId,
teamEntry.id
))
)).find(res => !res.success);
if (generateMatchesError) return generateMatchesError;
}
Expand Down
12 changes: 11 additions & 1 deletion lib/statbotics/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,17 @@ export interface operations {
/** @description Successful Response */
200: {
content: {
"application/json": Record<string, never>[];
"application/json": {
match?: string;
epa?: {
breakdown?: {
total_points?: number;
auto_points?: number;
teleop_points?: number;
endgame_points?: number;
};
};
}[];
};
};
/** @description Validation Error */
Expand Down
29 changes: 28 additions & 1 deletion lib/statbotics/statbotics.json
Original file line number Diff line number Diff line change
Expand Up @@ -1839,7 +1839,34 @@
"schema": {
"type": "array",
"items": {
"type": "object"
"type": "object",
"properties": {
"match": {
"type": "string"
},
"epa": {
"type": "object",
"properties": {
"breakdown": {
"type": "object",
"properties": {
"total_points": {
"type": "number"
},
"auto_points": {
"type": "number"
},
"teleop_points": {
"type": "number"
},
"endgame_points": {
"type": "number"
}
}
}
}
}
}
},
"title": "Response Read Team Matches V3 Team Matches Get"
}
Expand Down
5 changes: 5 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ model TeamPastSeason {
model MatchEntry {
id Int @id @default(autoincrement())
totalEPA Float
autoEPA Float
teleopEPA Float
endgameEPA Float
status String
notes String @default("[{\"children\":[{\"text\":\"\"}],\"type\":\"p\"}]")
Expand Down

0 comments on commit 1970d83

Please sign in to comment.