From 067b3caa236ec310e3c215da11509424d484a311 Mon Sep 17 00:00:00 2001 From: Bill Radjewski Date: Sat, 1 Feb 2025 18:06:31 -0500 Subject: [PATCH] feat: win probability and excitement --- src/app/games/service.ts | 4 ++++ src/app/games/types.ts | 1 + src/app/plays/service.ts | 4 ++++ src/app/plays/types.ts | 1 + src/config/types/db.d.ts | 3 +++ 5 files changed, 13 insertions(+) diff --git a/src/app/games/service.ts b/src/app/games/service.ts index 8e0a30a..3c15c09 100644 --- a/src/app/games/service.ts +++ b/src/app/games/service.ts @@ -57,6 +57,7 @@ export const getGames = async ( 'venue.name as venue', 'venue.city', 'venue.state', + 'game.excitement', ]) .orderBy('game.startDate', 'asc') .limit(3000); @@ -136,6 +137,9 @@ export const getGames = async ( awayPoints: game.awayPoints, awayPeriodPoints: game.awayPeriodPoints, awayWinner: game.awayWinner, + excitement: game.excitement + ? Math.round(Number(game.excitement) * 10) / 10 + : null, venueId: game.venueId, venue: game.venue, city: game.city, diff --git a/src/app/games/types.ts b/src/app/games/types.ts index 63cdd9f..18cf82b 100644 --- a/src/app/games/types.ts +++ b/src/app/games/types.ts @@ -60,6 +60,7 @@ export interface GameInfo { */ awayPeriodPoints: number[] | null; awayWinner: boolean | null; + excitement: number | null; /** * @isInt */ diff --git a/src/app/plays/service.ts b/src/app/plays/service.ts index a505952..cb09214 100644 --- a/src/app/plays/service.ts +++ b/src/app/plays/service.ts @@ -83,6 +83,7 @@ const getPlays = async ( 'play.scoreValue', 'playType.name as playType', 'play.playText', + 'play.wp', jsonArrayFrom( eb .selectFrom('athlete') @@ -181,6 +182,9 @@ const getPlays = async ( : null, homeScore: play.homeScore, awayScore: play.awayScore, + homeWinProbability: play.wp + ? Math.round(Number(play.wp) * 1000) / 1000 + : null, period: play.period, clock: play.clock, secondsRemaining: play.secondsRemaining, diff --git a/src/app/plays/types.ts b/src/app/plays/types.ts index 7c34a2e..7965a25 100644 --- a/src/app/plays/types.ts +++ b/src/app/plays/types.ts @@ -54,6 +54,7 @@ export interface PlayInfo { * @isInt */ awayScore: number; + homeWinProbability: number | null; scoringPlay: boolean | null; shootingPlay: boolean | null; scoreValue: number | null; diff --git a/src/config/types/db.d.ts b/src/config/types/db.d.ts index 6e32d83..318b687 100644 --- a/src/config/types/db.d.ts +++ b/src/config/types/db.d.ts @@ -97,6 +97,7 @@ export interface ConferenceTeam { export interface Game { attendance: number | null; conferenceGame: Generated; + excitement: Numeric | null; gameType: string | null; id: Generated; neutralSite: Generated; @@ -122,6 +123,7 @@ export interface GameInfo { awayTeamId: number | null; awayWinner: boolean | null; conferenceGame: boolean | null; + excitement: Numeric | null; gameType: string | null; homeConference: string | null; homeConferenceId: number | null; @@ -274,6 +276,7 @@ export interface Play { sourceId: string; teamId: number | null; wallclock: Timestamp | null; + wp: Numeric | null; } export interface PlayType {