Files
NBA_Go/import.go
T
2025-05-12 21:06:03 -05:00

61 lines
2.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package main
import (
"log"
"time"
"gorm.io/gorm"
"github.com/nprasad2077/NBA_Go/services"
)
// importPlayerAdvanced fetches and stores advanced stats for seasons 20232025
func importPlayerAdvanced(db *gorm.DB) {
for season := 2023; season <= 2025; season++ {
if err := services.FetchAndStorePlayerAdvancedStats(db, season, false); err != nil {
log.Printf("advanced import failed for %d: %v", season, err)
}
time.Sleep(1100 * time.Millisecond)
}
}
// importPlayerAdvancedPlayoffs fetches and stores advanced stats for playoffs seasons 20232025
func importPlayerAdvancedPlayoffs (db *gorm.DB) {
for season := 2023; season <= 2024; season++ {
if err := services.FetchAndStorePlayerAdvancedPlayoffsStats(db, season, true); err != nil {
log.Printf("advanced import failed for %d: %v", season, err)
}
time.Sleep(1100 * time.Millisecond)
}
}
// importPlayerTotals fetches and stores regular-season total stats for seasons 20232025
func importPlayerTotals(db *gorm.DB) {
for season := 2023; season <= 2025; season++ {
if err := services.FetchAndStorePlayerTotalStats(db, season, false); err != nil {
log.Printf("totals import failed for %d: %v", season, err)
}
time.Sleep(1000 * time.Millisecond)
}
}
// importPlayerPlayoffs fetches and stores playoff total stats for seasons 20232024
func importPlayerPlayoffs(db *gorm.DB) {
for season := 2023; season <= 2024; season++ {
if err := services.FetchAndStorePlayerTotalPlayoffsStats(db, season, true); err != nil {
log.Printf("playoffs import failed for %d: %v", season, err)
}
time.Sleep(1500 * time.Millisecond)
}
}
// importPlayerShotChart fetches shot-charts for every known player
func importPlayerShotChart(db *gorm.DB) {
const firstID = "hardeja01"
log.Printf("▶️ importing shot chart for player %s…", firstID)
if err := services.FetchAndStoreShotChartForPlayer(db, firstID); err != nil {
log.Printf("shot chart import failed for %s: %v", firstID, err)
}
// you can add more IDs here or just rely on the API endpoint after
}