mirror of
https://github.com/nprasad2077/NBA_Go.git
synced 2026-09-22 14:05:13 +00:00
shoot date update service manual
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
"fmt"
|
||||
|
||||
"github.com/nprasad2077/NBA_Go/services"
|
||||
"github.com/nprasad2077/NBA_Go/utils"
|
||||
@@ -12,7 +16,7 @@ import (
|
||||
|
||||
// importPlayerAdvanced fetches and stores advanced stats for seasons
|
||||
func importPlayerAdvanced(db *gorm.DB) {
|
||||
for season := 2001; season <= 2002; season++ {
|
||||
for season := 2001; season <= 2001; season++ {
|
||||
if err := services.FetchAndStorePlayerAdvancedScrapedStats(db, season, false); err != nil {
|
||||
log.Printf("advanced import failed for %d: %v", season, err)
|
||||
}
|
||||
@@ -24,7 +28,7 @@ func importPlayerAdvanced(db *gorm.DB) {
|
||||
|
||||
// importPlayerAdvancedPlayoffs fetches and stores advanced stats for playoffs seasons
|
||||
func importPlayerAdvancedPlayoffs(db *gorm.DB) {
|
||||
for season := 2001; season <= 2002; season++ {
|
||||
for season := 2001; season <= 2001; season++ {
|
||||
if err := services.FetchAndStorePlayerAdvancedScrapedStats(db, season, true); err != nil {
|
||||
log.Printf("advanced import failed for %d: %v", season, err)
|
||||
}
|
||||
@@ -36,7 +40,7 @@ func importPlayerAdvancedPlayoffs(db *gorm.DB) {
|
||||
|
||||
// importPlayerTotalsScrape fetches & stores scraped regular-season total stats
|
||||
func importPlayerTotalsScrape(db *gorm.DB) {
|
||||
for season := 2001; season <= 2002; season++ {
|
||||
for season := 2001; season <= 2001; season++ {
|
||||
if err := services.FetchAndStorePlayerTotalScrapedStats(db, season, false); err != nil {
|
||||
log.Printf("scraped totals import failed for %d: %v", season, err)
|
||||
}
|
||||
@@ -48,7 +52,7 @@ func importPlayerTotalsScrape(db *gorm.DB) {
|
||||
|
||||
// importPlayerPlayoffsScrape fetches & stores scraped playoff total stats
|
||||
func importPlayerTotalsPlayoffsScrape(db *gorm.DB) {
|
||||
for season := 2001; season <= 2002; season++ {
|
||||
for season := 2001; season <= 2001; season++ {
|
||||
if err := services.FetchAndStorePlayerTotalScrapedStats(db, season, true); err != nil {
|
||||
log.Printf("scraped playoffs import failed for %d: %v", season, err)
|
||||
}
|
||||
@@ -62,7 +66,7 @@ func importPlayerTotalsPlayoffsScrape(db *gorm.DB) {
|
||||
func importGameSchedules(db *gorm.DB) {
|
||||
months := []string{"october", "november", "december", "january", "february", "march", "april", "may", "june"}
|
||||
|
||||
for season := 2001; season <= 2002; season++ {
|
||||
for season := 2001; season <= 2001; season++ {
|
||||
log.Printf("--- Starting Game Schedule Import for Season: %d ---", season)
|
||||
for _, month := range months {
|
||||
if err := services.FetchAndStoreGameSchedule(db, season, month); err != nil {
|
||||
@@ -77,18 +81,23 @@ func importGameSchedules(db *gorm.DB) {
|
||||
}
|
||||
|
||||
// importBoxScores fetches and stores all box score data (line scores, player/team stats)
|
||||
// for games within a recent date range.
|
||||
// in safe 20-day session chunks with cool-off pauses and immediate database upserts.
|
||||
func importBoxScores(db *gorm.DB) {
|
||||
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
||||
defer stop()
|
||||
|
||||
from := time.Date(2000, time.October, 31, 0, 0, 0, 0, time.UTC)
|
||||
to := time.Date(2001, time.June, 30, 23, 59, 59, 0, time.UTC)
|
||||
|
||||
dateRangeComment := fmt.Sprintf("--- Starting Box Score Data Import for games between %s and %s ---",
|
||||
from.Format("January 2, 2006"),
|
||||
to.Format("January 2, 2006"))
|
||||
chunkDays := 20 // 20-day session chunks
|
||||
coolOff := 20 * time.Second // 20s cool-off with jitter between chunks
|
||||
skipExisting := true // Automatically skip games that already have line scores
|
||||
|
||||
log.Println(dateRangeComment)
|
||||
|
||||
if err := services.FetchAndStoreBoxScoreDataForDateRange(db, from, to); err != nil {
|
||||
if err := services.FetchAndStoreBoxScoreDataChunked(ctx, db, from, to, chunkDays, coolOff, skipExisting); err != nil {
|
||||
if errors.Is(err, context.Canceled) {
|
||||
log.Println("👋 Box score import interrupted by user. Safe to resume anytime!")
|
||||
return
|
||||
}
|
||||
log.Fatalf("Box score import failed: %v", err)
|
||||
}
|
||||
|
||||
@@ -175,8 +184,8 @@ func importPlayerShotCharts(db *gorm.DB) {
|
||||
|
||||
// importMarkPlayoffGames marks games as playoff using the dedicated Basketball Reference playoff schedule.
|
||||
func importMarkPlayoffGames(db *gorm.DB) {
|
||||
for season := 2001; season <= 2002; season++ {
|
||||
if err := services.FetchAndMarkPlayoffGames(db, season+1); err != nil {
|
||||
for season := 2001; season <= 2001; season++ {
|
||||
if err := services.FetchAndMarkPlayoffGames(db, season); err != nil {
|
||||
log.Printf("playoff marking failed for %d: %v", season, err)
|
||||
}
|
||||
log.Printf("Playoff games marked for season: %d", season)
|
||||
|
||||
Reference in New Issue
Block a user