per game stats and box score

This commit is contained in:
Ravi Prasad
2025-07-08 01:23:34 -05:00
parent a16af088af
commit c7c04fee7e
7 changed files with 704 additions and 101 deletions
+91 -93
View File
@@ -1,32 +1,30 @@
package models
import (
"time"
"gorm.io/gorm"
"time"
)
// Game represents the top-level information for a single NBA game, including schedule details and results.
type Game struct {
ID uint `gorm:"primaryKey" swaggerignore:"true"`
GameID string `gorm:"not null;uniqueIndex" json:"gameId"` // A unique identifier for the game, e.g., "202504010ATL"
Date time.Time `gorm:"not null;index" json:"date"`
IsPlayoff bool `gorm:"not null;default:false;index" json:"isPlayoff"`
StartTimeET string `json:"startTimeET"`
Arena string `json:"arena"`
VisitorTeam string `gorm:"not null" json:"visitorTeam"`
VisitorPTS int `json:"visitorPts"`
HomeTeam string `gorm:"not null" json:"homeTeam"`
HomePTS int `json:"homePts"`
GameDuration string `json:"gameDuration"` // e.g., "2:23"
BoxScoreURL string `json:"boxScoreUrl"`
ID uint `gorm:"primaryKey" swaggerignore:"true"`
GameID string `gorm:"not null;uniqueIndex" json:"gameId"` // The field you want to use
Date time.Time `gorm:"not null;index" json:"date"`
IsPlayoff bool `gorm:"not null;default:false;index" json:"isPlayoff"`
StartTimeET string `json:"startTimeET"`
Arena string `json:"arena"`
VisitorTeam string `gorm:"not null" json:"visitorTeam"`
VisitorPTS int `json:"visitorPts"`
HomeTeam string `gorm:"not null" json:"homeTeam"`
HomePTS int `json:"homePts"`
GameDuration string `json:"gameDuration"`
BoxScoreURL string `json:"boxScoreUrl"`
// Associations
LineScores []LineScore `json:"lineScores"`
PlayerGameBasicStats []PlayerGameBasicStat `json:"playerGameBasicStats"`
PlayerGameAdvStats []PlayerGameAdvStat `json:"playerGameAdvStats"`
TeamGameBasicStats []TeamGameBasicStat `json:"teamGameBasicStats"`
TeamGameAdvStats []TeamGameAdvStat `json:"teamGameAdvStats"`
// Associations (Updated with explicit foreign key tags)
LineScores []LineScore `gorm:"foreignKey:GameID;references:GameID" json:"lineScores"`
PlayerGameBasicStats []PlayerGameBasicStat `gorm:"foreignKey:GameID;references:GameID" json:"playerGameBasicStats"`
PlayerGameAdvStats []PlayerGameAdvStat `gorm:"foreignKey:GameID;references:GameID" json:"playerGameAdvStats"`
TeamGameBasicStats []TeamGameBasicStat `gorm:"foreignKey:GameID;references:GameID" json:"teamGameBasicStats"`
TeamGameAdvStats []TeamGameAdvStat `gorm:"foreignKey:GameID;references:GameID" json:"teamGameAdvStats"`
CreatedAt time.Time `swaggerignore:"true"`
UpdatedAt time.Time `swaggerignore:"true"`
@@ -43,10 +41,10 @@ type LineScore struct {
Q3 int `json:"q3"`
Q4 int `json:"q4"`
// Overtime scores; will be 0 if the game did not go to the respective OT period.
OT1 int `json:"ot1"`
OT2 int `json:"ot2"`
OT3 int `json:"ot3"`
Total int `json:"total"`
OT1 int `json:"ot1"`
OT2 int `json:"ot2"`
OT3 int `json:"ot3"`
Total int `json:"total"`
CreatedAt time.Time `swaggerignore:"true"`
UpdatedAt time.Time `swaggerignore:"true"`
@@ -55,33 +53,33 @@ type LineScore struct {
// PlayerGameBasicStat contains the basic box score statistics for a single player in a single game.
type PlayerGameBasicStat struct {
ID uint `gorm:"primaryKey" swaggerignore:"true"`
GameID string `gorm:"not null;uniqueIndex:idx_player_game_basic" json:"gameId"`
PlayerID string `gorm:"not null;uniqueIndex:idx_player_game_basic" json:"playerId"`
PlayerName string `json:"playerName"`
Team string `gorm:"not null" json:"team"`
Status string `json:"status"` // e.g., "Starter", "Bench", "Did Not Play"
MP string `json:"mp"` // Minutes Played, e.g., "38:07"
FG int `json:"fg"`
FGA int `json:"fga"`
FGPercent float64 `json:"fgPercent"`
ThreeP int `json:"threeP"`
ThreePA int `json:"threePa"`
ID uint `gorm:"primaryKey" swaggerignore:"true"`
GameID string `gorm:"not null;uniqueIndex:idx_player_game_basic" json:"gameId"`
PlayerID string `gorm:"not null;uniqueIndex:idx_player_game_basic" json:"playerId"`
PlayerName string `json:"playerName"`
Team string `gorm:"not null" json:"team"`
Status string `json:"status"` // e.g., "Starter", "Bench", "Did Not Play"
MP string `json:"mp"` // Minutes Played, e.g., "38:07"
FG int `json:"fg"`
FGA int `json:"fga"`
FGPercent float64 `json:"fgPercent"`
ThreeP int `json:"threeP"`
ThreePA int `json:"threePa"`
ThreePPercent float64 `json:"threePPercent"`
FT int `json:"ft"`
FTA int `json:"fta"`
FTPercent float64 `json:"ftPercent"`
ORB int `json:"orb"`
DRB int `json:"drb"`
TRB int `json:"trb"`
AST int `json:"ast"`
STL int `json:"stl"`
BLK int `json:"blk"`
TOV int `json:"tov"`
PF int `json:"pf"`
PTS int `json:"pts"`
GmSc float64 `json:"gmSc"` // Game Score
PlusMinus int `json:"plusMinus"`
FT int `json:"ft"`
FTA int `json:"fta"`
FTPercent float64 `json:"ftPercent"`
ORB int `json:"orb"`
DRB int `json:"drb"`
TRB int `json:"trb"`
AST int `json:"ast"`
STL int `json:"stl"`
BLK int `json:"blk"`
TOV int `json:"tov"`
PF int `json:"pf"`
PTS int `json:"pts"`
GmSc float64 `json:"gmSc"` // Game Score
PlusMinus int `json:"plusMinus"`
CreatedAt time.Time `swaggerignore:"true"`
UpdatedAt time.Time `swaggerignore:"true"`
@@ -90,16 +88,16 @@ type PlayerGameBasicStat struct {
// PlayerGameAdvStat contains the advanced box score statistics for a single player in a single game.
type PlayerGameAdvStat struct {
ID uint `gorm:"primaryKey" swaggerignore:"true"`
GameID string `gorm:"not null;uniqueIndex:idx_player_game_adv" json:"gameId"`
PlayerID string `gorm:"not null;uniqueIndex:idx_player_game_adv" json:"playerId"`
PlayerName string `json:"playerName"`
Team string `gorm:"not null" json:"team"`
MP string `json:"mp"` // Minutes Played
TSPercent float64 `json:"tsPercent"`
ID uint `gorm:"primaryKey" swaggerignore:"true"`
GameID string `gorm:"not null;uniqueIndex:idx_player_game_adv" json:"gameId"`
PlayerID string `gorm:"not null;uniqueIndex:idx_player_game_adv" json:"playerId"`
PlayerName string `json:"playerName"`
Team string `gorm:"not null" json:"team"`
MP string `json:"mp"` // Minutes Played
TSPercent float64 `json:"tsPercent"`
EFGPercent float64 `json:"efgPercent"`
ThreePAr float64 `json:"threePAr"`
FTr float64 `json:"fTr"`
ThreePAr float64 `json:"threePAr"`
FTr float64 `json:"fTr"`
ORBPercent float64 `json:"orbPercent"`
DRBPercent float64 `json:"drbPercent"`
TRBPercent float64 `json:"trbPercent"`
@@ -108,9 +106,9 @@ type PlayerGameAdvStat struct {
BLKPercent float64 `json:"blkPercent"`
TOVPercent float64 `json:"tovPercent"`
USGPercent float64 `json:"usgPercent"`
ORtg int `json:"oRtg"`
DRtg int `json:"dRtg"`
BPM float64 `json:"bpm"` // Box Plus/Minus
ORtg int `json:"oRtg"`
DRtg int `json:"dRtg"`
BPM float64 `json:"bpm"` // Box Plus/Minus
CreatedAt time.Time `swaggerignore:"true"`
UpdatedAt time.Time `swaggerignore:"true"`
@@ -119,28 +117,28 @@ type PlayerGameAdvStat struct {
// TeamGameBasicStat holds the total basic stats for a team in a single game.
type TeamGameBasicStat struct {
ID uint `gorm:"primaryKey" swaggerignore:"true"`
GameID string `gorm:"not null;uniqueIndex:idx_team_game_basic" json:"gameId"`
Team string `gorm:"not null;uniqueIndex:idx_team_game_basic" json:"team"`
MP int `json:"mp"` // Total minutes, usually 240 for a regulation game
FG int `json:"fg"`
FGA int `json:"fga"`
FGPercent float64 `json:"fgPercent"`
ThreeP int `json:"threeP"`
ThreePA int `json:"threePa"`
ID uint `gorm:"primaryKey" swaggerignore:"true"`
GameID string `gorm:"not null;uniqueIndex:idx_team_game_basic" json:"gameId"`
Team string `gorm:"not null;uniqueIndex:idx_team_game_basic" json:"team"`
MP int `json:"mp"` // Total minutes, usually 240 for a regulation game
FG int `json:"fg"`
FGA int `json:"fga"`
FGPercent float64 `json:"fgPercent"`
ThreeP int `json:"threeP"`
ThreePA int `json:"threePa"`
ThreePPercent float64 `json:"threePPercent"`
FT int `json:"ft"`
FTA int `json:"fta"`
FTPercent float64 `json:"ftPercent"`
ORB int `json:"orb"`
DRB int `json:"drb"`
TRB int `json:"trb"`
AST int `json:"ast"`
STL int `json:"stl"`
BLK int `json:"blk"`
TOV int `json:"tov"`
PF int `json:"pf"`
PTS int `json:"pts"`
FT int `json:"ft"`
FTA int `json:"fta"`
FTPercent float64 `json:"ftPercent"`
ORB int `json:"orb"`
DRB int `json:"drb"`
TRB int `json:"trb"`
AST int `json:"ast"`
STL int `json:"stl"`
BLK int `json:"blk"`
TOV int `json:"tov"`
PF int `json:"pf"`
PTS int `json:"pts"`
CreatedAt time.Time `swaggerignore:"true"`
UpdatedAt time.Time `swaggerignore:"true"`
@@ -149,14 +147,14 @@ type TeamGameBasicStat struct {
// TeamGameAdvStat holds the total advanced stats for a team in a single game.
type TeamGameAdvStat struct {
ID uint `gorm:"primaryKey" swaggerignore:"true"`
GameID string `gorm:"not null;uniqueIndex:idx_team_game_adv" json:"gameId"`
Team string `gorm:"not null;uniqueIndex:idx_team_game_adv" json:"team"`
MP int `json:"mp"`
TSPercent float64 `json:"tsPercent"`
ID uint `gorm:"primaryKey" swaggerignore:"true"`
GameID string `gorm:"not null;uniqueIndex:idx_team_game_adv" json:"gameId"`
Team string `gorm:"not null;uniqueIndex:idx_team_game_adv" json:"team"`
MP int `json:"mp"`
TSPercent float64 `json:"tsPercent"`
EFGPercent float64 `json:"efgPercent"`
ThreePAr float64 `json:"threePAr"`
FTr float64 `json:"fTr"`
ThreePAr float64 `json:"threePAr"`
FTr float64 `json:"fTr"`
ORBPercent float64 `json:"orbPercent"`
DRBPercent float64 `json:"drbPercent"`
TRBPercent float64 `json:"trbPercent"`
@@ -165,8 +163,8 @@ type TeamGameAdvStat struct {
BLKPercent float64 `json:"blkPercent"`
TOVPercent float64 `json:"tovPercent"`
USGPercent float64 `json:"usgPercent"` // Will be ~100.0 for a team
ORtg float64 `json:"oRtg"`
DRtg float64 `json:"dRtg"`
ORtg float64 `json:"oRtg"`
DRtg float64 `json:"dRtg"`
CreatedAt time.Time `swaggerignore:"true"`
UpdatedAt time.Time `swaggerignore:"true"`