mirror of
https://github.com/nprasad2077/NBA_Go.git
synced 2026-09-22 14:05:13 +00:00
per game stats and box score
This commit is contained in:
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
// importPlayerAdvanced fetches and stores advanced stats for seasons 2017–2025
|
||||
func importPlayerAdvanced(db *gorm.DB) {
|
||||
for season := 2022; season <= 2025; season++ {
|
||||
for season := 2025; season <= 2025; season++ {
|
||||
if err := services.FetchAndStorePlayerAdvancedScrapedStats(db, season, false); err != nil {
|
||||
log.Printf("advanced import failed for %d: %v", season, err)
|
||||
}
|
||||
@@ -23,7 +23,7 @@ func importPlayerAdvanced(db *gorm.DB) {
|
||||
|
||||
// importPlayerAdvancedPlayoffs fetches and stores advanced stats for playoffs seasons 2023–2025
|
||||
func importPlayerAdvancedPlayoffs(db *gorm.DB) {
|
||||
for season := 2022; season <= 2025; season++ {
|
||||
for season := 2025; season <= 2025; season++ {
|
||||
if err := services.FetchAndStorePlayerAdvancedScrapedStats(db, season, true); err != nil {
|
||||
log.Printf("advanced import failed for %d: %v", season, err)
|
||||
}
|
||||
@@ -35,7 +35,7 @@ func importPlayerAdvancedPlayoffs(db *gorm.DB) {
|
||||
|
||||
// importPlayerTotalsScrape fetches & stores scraped regular-season total stats
|
||||
func importPlayerTotalsScrape(db *gorm.DB) {
|
||||
for season := 2022; season <= 2025; season++ {
|
||||
for season := 2025; season <= 2025; season++ {
|
||||
if err := services.FetchAndStorePlayerTotalScrapedStats(db, season, false); err != nil {
|
||||
log.Printf("scraped totals import failed for %d: %v", season, err)
|
||||
}
|
||||
@@ -47,7 +47,7 @@ func importPlayerTotalsScrape(db *gorm.DB) {
|
||||
|
||||
// importPlayerPlayoffsScrape fetches & stores scraped playoff total stats
|
||||
func importPlayerTotalsPlayoffsScrape(db *gorm.DB) {
|
||||
for season := 2022; season <= 2025; season++ {
|
||||
for season := 2025; season <= 2025; season++ {
|
||||
if err := services.FetchAndStorePlayerTotalScrapedStats(db, season, true); err != nil {
|
||||
log.Printf("scraped playoffs import failed for %d: %v", season, err)
|
||||
}
|
||||
@@ -57,6 +57,49 @@ func importPlayerTotalsPlayoffsScrape(db *gorm.DB) {
|
||||
}
|
||||
}
|
||||
|
||||
// importGameSchedules fetches and stores game schedules
|
||||
func importGameSchedules(db *gorm.DB) {
|
||||
// An NBA season typically runs from October to June
|
||||
months := []string{
|
||||
"october", "november", "december", "january",
|
||||
"february", "march", "april", "may", "june",
|
||||
}
|
||||
|
||||
for season := 2025; season <= 2025; season++ {
|
||||
log.Printf("--- Starting Game Schedule Import for Season: %d ---", season)
|
||||
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)
|
||||
if err := services.FetchAndStoreGameSchedule(db, season, month); err != nil {
|
||||
// Log the error but continue to the next month/season
|
||||
log.Printf("Game schedule import failed for %s %d: %v", month, season, err)
|
||||
}
|
||||
log.Printf("Game schedule import for %s, %d complete.", month, season)
|
||||
// Respectful delay between requests
|
||||
time.Sleep(1100 * time.Millisecond)
|
||||
utils.SleepWithJitter(1000 * time.Millisecond)
|
||||
}
|
||||
log.Printf("--- Finished Game Schedule Import for Season: %d ---", season)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// importBoxScores fetches and stores all box score data (line scores, player/team stats)
|
||||
// for games within a recent date range.
|
||||
func importBoxScores(db *gorm.DB) {
|
||||
// Define the date range for the import.
|
||||
// This example fetches data for games in the last 90 days.
|
||||
to := time.Now()
|
||||
from := to.AddDate(0, -1, 1) // 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"))
|
||||
|
||||
if err := services.FetchAndStoreBoxScoreDataForDateRange(db, from, to); err != nil {
|
||||
log.Fatalf("Box score import failed: %v", err)
|
||||
}
|
||||
|
||||
log.Printf("--- Finished Box Score Data Import ---")
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user