Merge pull request #57 from nprasad2077/limits

Limits
This commit is contained in:
2026-06-11 03:47:05 -05:00
committed by GitHub
8 changed files with 3162 additions and 2 deletions
Vendored
BIN
View File
Binary file not shown.
+1 -1
View File
@@ -3,6 +3,6 @@
"current_from": "2006-12-15",
"current_to": "2007-02-13",
"target_end": "2026-06-15",
"window_days": 60,
"window_days": 45,
"completed": false
}
+10
View File
@@ -158,4 +158,14 @@ func importPlayerShotCharts(db *gorm.DB) {
log.Println("--- Finished Player Shot Chart Import from Predefined List ---")
}
// importMarkPlayoffGames marks games as playoff using the dedicated Basketball Reference playoff schedule.
func importMarkPlayoffGames(db *gorm.DB) {
for season := ${SEASON}; season <= ${SEASON}; season++ {
if err := services.FetchAndMarkPlayoffGames(db, season+1); err != nil {
log.Printf("playoff marking failed for %d: %v", season, err)
}
log.Printf("Playoff games marked for season: %d", season)
}
}
EOF
+3 -1
View File
@@ -45,4 +45,6 @@ docs/postman
docs/kiro.md
docs/digital_ocean/digitaal ocean llms.txt
.docs
.docs
NBA_Go
File diff suppressed because one or more lines are too long
+10
View File
@@ -95,6 +95,16 @@ func importBoxScores(db *gorm.DB) {
log.Println("--- Finished Box Score Data Import ---")
}
// importMarkPlayoffGames marks games as playoff using the dedicated Basketball Reference playoff schedule.
func importMarkPlayoffGames(db *gorm.DB) {
for season := 2006; season <= 2006; season++ {
if err := services.FetchAndMarkPlayoffGames(db, season+1); err != nil {
log.Printf("playoff marking failed for %d: %v", season, err)
}
log.Printf("Playoff games marked for season: %d", season)
}
}
// importPlayerShotCharts fetches shot charts for a PREDEFINED list of players for a given range of seasons.
func importPlayerShotCharts(db *gorm.DB) {
log.Println("--- Starting Player Shot Chart Import from Predefined List ---")
+3
View File
@@ -68,6 +68,9 @@ func main() {
importBoxScores(db)
log.Println("🎉 Related Box Score Imports completed successfully 📦")
importMarkPlayoffGames(db)
log.Println("🎉 Playoff games marked successfully 🏆")
// importPlayerShotCharts(db)
// log.Println("🎉 Player Shot Chart Import completed successfully 🎯")
+51
View File
@@ -17,6 +17,57 @@ import (
)
const gameScheduleURLFmt = "https://www.basketball-reference.com/leagues/NBA_%d_games-%s.html"
const playoffScheduleURLFmt = "https://www.basketball-reference.com/playoffs/NBA_%d_games.html"
// FetchAndMarkPlayoffGames scrapes the dedicated playoff schedule page and
// batch-updates all matching games in the DB to set IsPlayoff=true.
// This is a post-processing step that does not modify the normal import flow.
func FetchAndMarkPlayoffGames(db *gorm.DB, season int) error {
url := fmt.Sprintf(playoffScheduleURLFmt, season)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return err
}
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36")
resp, err := http.DefaultClient.Do(req)
if err != nil {
return fmt.Errorf("failed to fetch playoff schedule for %d: %w", season, err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("playoff schedule returned status %s for season %d", resp.Status, season)
}
doc, err := goquery.NewDocumentFromReader(resp.Body)
if err != nil {
return fmt.Errorf("failed to parse playoff schedule HTML: %w", err)
}
var gameIDs []string
doc.Find(`td[data-stat="box_score_text"] a`).Each(func(i int, s *goquery.Selection) {
if href, exists := s.Attr("href"); exists {
parts := strings.Split(href, "/")
fileName := parts[len(parts)-1]
gameID := strings.TrimSuffix(fileName, ".html")
if gameID != "" {
gameIDs = append(gameIDs, gameID)
}
}
})
if len(gameIDs) == 0 {
log.Printf("No playoff game IDs found for season %d.", season)
return nil
}
if err := db.Model(&models.Game{}).Where("game_id IN ?", gameIDs).Update("is_playoff", true).Error; err != nil {
return fmt.Errorf("failed to mark playoff games: %w", err)
}
log.Printf("✅ Marked %d games as playoff for season %d.", len(gameIDs), season)
return nil
}
// FetchAndStoreGameSchedule scrapes the game schedule for a given season and month.
// The month should be the full lowercase name, e.g., "october", "november".