diff --git a/lib/database/generate/segments/generate-matches.ts b/lib/database/generate/segments/generate-matches.ts index 4b72cd5..6888160 100644 --- a/lib/database/generate/segments/generate-matches.ts +++ b/lib/database/generate/segments/generate-matches.ts @@ -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 { +export default async function GenerateMatches(tbaMatch: any, statboticsMatch: any, eventId: number, teamEntryId: number): Promise { // Skip in progress matches if (tbaMatch.actual_time == undefined) return {success: true}; @@ -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 diff --git a/lib/database/generate/segments/generate-team.ts b/lib/database/generate/segments/generate-team.ts index 2b9e811..5e67554 100644 --- a/lib/database/generate/segments/generate-team.ts +++ b/lib/database/generate/segments/generate-team.ts @@ -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; } diff --git a/lib/statbotics/schema.d.ts b/lib/statbotics/schema.d.ts index b260d49..281e96b 100644 --- a/lib/statbotics/schema.d.ts +++ b/lib/statbotics/schema.d.ts @@ -908,7 +908,17 @@ export interface operations { /** @description Successful Response */ 200: { content: { - "application/json": Record[]; + "application/json": { + match?: string; + epa?: { + breakdown?: { + total_points?: number; + auto_points?: number; + teleop_points?: number; + endgame_points?: number; + }; + }; + }[]; }; }; /** @description Validation Error */ diff --git a/lib/statbotics/statbotics.json b/lib/statbotics/statbotics.json index e5fdd3c..f4a719d 100644 --- a/lib/statbotics/statbotics.json +++ b/lib/statbotics/statbotics.json @@ -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" } diff --git a/prisma/schema.prisma b/prisma/schema.prisma index c743ee8..9f0380c 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -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\"}]")