mirror of
https://github.com/nprasad2077/NBA_Go.git
synced 2026-09-22 14:05:13 +00:00
comment out table drops
This commit is contained in:
+12
-12
@@ -33,18 +33,18 @@ func InitDB(shouldMigrate bool) *gorm.DB {
|
|||||||
// --- ADD THIS BLOCK TO DROP STALE TABLES ---
|
// --- ADD THIS BLOCK TO DROP STALE TABLES ---
|
||||||
// Drop tables in reverse order of dependency (children first).
|
// Drop tables in reverse order of dependency (children first).
|
||||||
// This ensures a clean migration every time the import process runs.
|
// This ensures a clean migration every time the import process runs.
|
||||||
log.Println("⚠️ Dropping existing game-related tables for a clean migration...")
|
// log.Println("⚠️ Dropping existing game-related tables for a clean migration...")
|
||||||
if err := db.Migrator().DropTable(
|
// if err := db.Migrator().DropTable(
|
||||||
&models.LineScore{},
|
// &models.LineScore{},
|
||||||
&models.PlayerGameBasicStat{},
|
// &models.PlayerGameBasicStat{},
|
||||||
&models.PlayerGameAdvStat{},
|
// &models.PlayerGameAdvStat{},
|
||||||
&models.TeamGameBasicStat{},
|
// &models.TeamGameBasicStat{},
|
||||||
&models.TeamGameAdvStat{},
|
// &models.TeamGameAdvStat{},
|
||||||
&models.Game{}, // Drop parent table last
|
// &models.Game{}, // Drop parent table last
|
||||||
); err != nil {
|
// ); err != nil {
|
||||||
log.Fatalf("failed to drop tables: %v", err)
|
// log.Fatalf("failed to drop tables: %v", err)
|
||||||
}
|
// }
|
||||||
log.Println("✅ Tables dropped successfully.")
|
// log.Println("✅ Tables dropped successfully.")
|
||||||
// --- END OF ADDED BLOCK ---
|
// --- END OF ADDED BLOCK ---
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
|
||||||
"github.com/nprasad2077/NBA_Go/services"
|
"github.com/nprasad2077/NBA_Go/services"
|
||||||
"github.com/nprasad2077/NBA_Go/utils"
|
"github.com/nprasad2077/NBA_Go/utils"
|
||||||
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
// importPlayerAdvanced fetches and stores advanced stats for seasons 2017–2025
|
// importPlayerAdvanced fetches and stores advanced stats for seasons 2017–2025
|
||||||
@@ -35,37 +35,39 @@ func importPlayerAdvancedPlayoffs(db *gorm.DB) {
|
|||||||
|
|
||||||
// importPlayerTotalsScrape fetches & stores scraped regular-season total stats
|
// importPlayerTotalsScrape fetches & stores scraped regular-season total stats
|
||||||
func importPlayerTotalsScrape(db *gorm.DB) {
|
func importPlayerTotalsScrape(db *gorm.DB) {
|
||||||
for season := 2025; season <= 2025; season++ {
|
for season := 2025; season <= 2025; season++ {
|
||||||
if err := services.FetchAndStorePlayerTotalScrapedStats(db, season, false); err != nil {
|
if err := services.FetchAndStorePlayerTotalScrapedStats(db, season, false); err != nil {
|
||||||
log.Printf("scraped totals import failed for %d: %v", season, err)
|
log.Printf("scraped totals import failed for %d: %v", season, err)
|
||||||
}
|
}
|
||||||
log.Printf("Player Totals import for season: %d", season)
|
log.Printf("Player Totals import for season: %d", season)
|
||||||
time.Sleep(1100 * time.Millisecond)
|
time.Sleep(1100 * time.Millisecond)
|
||||||
utils.SleepWithJitter(1500 * time.Millisecond)
|
utils.SleepWithJitter(1500 * time.Millisecond)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// importPlayerPlayoffsScrape fetches & stores scraped playoff total stats
|
// importPlayerPlayoffsScrape fetches & stores scraped playoff total stats
|
||||||
func importPlayerTotalsPlayoffsScrape(db *gorm.DB) {
|
func importPlayerTotalsPlayoffsScrape(db *gorm.DB) {
|
||||||
for season := 2025; season <= 2025; season++ {
|
for season := 2025; season <= 2025; season++ {
|
||||||
if err := services.FetchAndStorePlayerTotalScrapedStats(db, season, true); err != nil {
|
if err := services.FetchAndStorePlayerTotalScrapedStats(db, season, true); err != nil {
|
||||||
log.Printf("scraped playoffs import failed for %d: %v", season, err)
|
log.Printf("scraped playoffs import failed for %d: %v", season, err)
|
||||||
}
|
}
|
||||||
log.Printf("Player Playoffs Totals import for season: %d", season)
|
log.Printf("Player Playoffs Totals import for season: %d", season)
|
||||||
time.Sleep(1100 * time.Millisecond)
|
time.Sleep(1100 * time.Millisecond)
|
||||||
utils.SleepWithJitter(1750 * time.Millisecond)
|
utils.SleepWithJitter(1750 * time.Millisecond)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// importGameSchedules fetches and stores game schedules
|
// importGameSchedules fetches and stores game schedules
|
||||||
func importGameSchedules(db *gorm.DB) {
|
func importGameSchedules(db *gorm.DB) {
|
||||||
// An NBA season typically runs from October to June
|
// An NBA season typically runs from October to June
|
||||||
months := []string{
|
months := []string{
|
||||||
"october", "november", "december", "january",
|
// "october", "november", "december", "january",
|
||||||
"february", "march", "april", "may", "june",
|
// "february", "march", "april", "may", "june",
|
||||||
|
"december", "january",
|
||||||
|
"february", "march", "april",
|
||||||
}
|
}
|
||||||
|
|
||||||
for season := 2025; season <= 2025; season++ {
|
for season := 2023; season <= 2024; season++ {
|
||||||
log.Printf("--- Starting Game Schedule Import for Season: %d ---", season)
|
log.Printf("--- Starting Game Schedule Import for Season: %d ---", season)
|
||||||
for _, month := range months {
|
for _, month := range months {
|
||||||
// The service will print a warning and skip if a month has no data (e.g. May/June for a season not yet finished)
|
// The service will print a warning and skip if a month has no data (e.g. May/June for a season not yet finished)
|
||||||
@@ -82,14 +84,15 @@ func importGameSchedules(db *gorm.DB) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// importBoxScores fetches and stores all box score data (line scores, player/team stats)
|
// importBoxScores fetches and stores all box score data (line scores, player/team stats)
|
||||||
// for games within a recent date range.
|
// for games within a recent date range.
|
||||||
func importBoxScores(db *gorm.DB) {
|
func importBoxScores(db *gorm.DB) {
|
||||||
// Define the date range for the import.
|
// Define the date range for the import.
|
||||||
// This example fetches data for games in the last 90 days.
|
|
||||||
to := time.Now()
|
// The format is: time.Date(year, month, day, hour, min, sec, nsec, location)
|
||||||
from := to.AddDate(0, -1, 1) // 0 years, -3 months, 0 days
|
to := time.Date(2025, time.April, 10, 0, 0, 0, 0, time.UTC)
|
||||||
|
// to := time.Now()
|
||||||
|
from := to.AddDate(0, -1, 0) // 0 years, -3 months, 0 days
|
||||||
|
|
||||||
log.Printf("--- Starting Box Score Data Import from %s to %s ---", from.Format("2006-01-02"), to.Format("2006-01-02"))
|
log.Printf("--- Starting Box Score Data Import from %s to %s ---", from.Format("2006-01-02"), to.Format("2006-01-02"))
|
||||||
|
|
||||||
@@ -100,9 +103,6 @@ func importBoxScores(db *gorm.DB) {
|
|||||||
log.Printf("--- Finished Box Score Data Import ---")
|
log.Printf("--- Finished Box Score Data Import ---")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// importPlayerShotChart fetches shot-charts for every known player
|
// importPlayerShotChart fetches shot-charts for every known player
|
||||||
// func importPlayerShotChart(db *gorm.DB) {
|
// func importPlayerShotChart(db *gorm.DB) {
|
||||||
// const firstID = "hardeja01"
|
// const firstID = "hardeja01"
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ func FetchAndStoreBoxScoreDataForDateRange(db *gorm.DB, from, to time.Time) erro
|
|||||||
log.Printf("Error processing box score for game %s: %v", game.GameID, err)
|
log.Printf("Error processing box score for game %s: %v", game.GameID, err)
|
||||||
}
|
}
|
||||||
// Be a good internet citizen and pause between requests.
|
// Be a good internet citizen and pause between requests.
|
||||||
utils.SleepWithJitter(1500 * time.Millisecond)
|
utils.SleepWithJitter(3000 * time.Millisecond)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user