mirror of
https://github.com/nprasad2077/NBA_Go.git
synced 2026-09-22 14:05:13 +00:00
line score OT fix
This commit is contained in:
@@ -25,14 +25,22 @@ func FetchAndStoreLineScore(db *gorm.DB, doc *goquery.Document, gameID string) e
|
||||
GameID: gameID,
|
||||
Team: teamName,
|
||||
}
|
||||
|
||||
// Regular Quarters - no changes here
|
||||
ls.Q1 = mustAtoi(row.Find(`td[data-stat="1"]`).Text())
|
||||
ls.Q2 = mustAtoi(row.Find(`td[data-stat="2"]`).Text())
|
||||
ls.Q3 = mustAtoi(row.Find(`td[data-stat="3"]`).Text())
|
||||
ls.Q4 = mustAtoi(row.Find(`td[data-stat="4"]`).Text())
|
||||
ls.OT1 = mustAtoi(row.Find(`td[data-stat="OT1"]`).Text())
|
||||
ls.OT2 = mustAtoi(row.Find(`td[data-stat="OT2"]`).Text())
|
||||
ls.OT3 = mustAtoi(row.Find(`td[data-stat="OT3"]`).Text())
|
||||
|
||||
// --- FIX: Corrected selectors for Overtime periods ---
|
||||
// The HTML uses "1OT", "2OT", etc., not "OT1", "OT2".
|
||||
ls.OT1 = mustAtoi(row.Find(`td[data-stat="1OT"]`).Text())
|
||||
ls.OT2 = mustAtoi(row.Find(`td[data-stat="2OT"]`).Text())
|
||||
ls.OT3 = mustAtoi(row.Find(`td[data-stat="3OT"]`).Text())
|
||||
|
||||
// Total score
|
||||
ls.Total = mustAtoi(row.Find(`td[data-stat="T"]`).Text())
|
||||
|
||||
lineScores = append(lineScores, ls)
|
||||
})
|
||||
|
||||
@@ -42,13 +50,20 @@ func FetchAndStoreLineScore(db *gorm.DB, doc *goquery.Document, gameID string) e
|
||||
}
|
||||
|
||||
// Upsert the data into the database.
|
||||
if err := db.Clauses(clause.OnConflict{
|
||||
Columns: []clause.Column{{Name: "game_id"}, {Name: "team"}},
|
||||
DoUpdates: clause.AssignmentColumns([]string{"q1", "q2", "q3", "q4", "ot1", "ot2", "ot3", "total"}),
|
||||
}).Create(&lineScores).Error; err != nil {
|
||||
// Using a transaction is a good practice for atomicity.
|
||||
err := db.Transaction(func(tx *gorm.DB) error {
|
||||
return tx.Clauses(clause.OnConflict{
|
||||
Columns: []clause.Column{{Name: "game_id"}, {Name: "team"}},
|
||||
DoUpdates: clause.AssignmentColumns([]string{"q1", "q2", "q3", "q4", "ot1", "ot2", "ot3", "total"}),
|
||||
}).Create(&lineScores).Error
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
log.Printf("Error upserting line scores for game %s: %v", gameID, err)
|
||||
return err
|
||||
}
|
||||
|
||||
log.Printf("Successfully processed line scores for game %s.", gameID)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user