chore: commit all pending changes
This commit is contained in:
@@ -221,22 +221,26 @@ final class AppDataProvider: ObservableObject {
|
||||
|
||||
var richGames: [RichGame] = []
|
||||
var droppedGames: [(game: Game, reason: String)] = []
|
||||
var stadiumFallbacksApplied = 0
|
||||
|
||||
for game in games {
|
||||
let homeTeam = teamsById[game.homeTeamId]
|
||||
let awayTeam = teamsById[game.awayTeamId]
|
||||
let stadium = stadiumsById[game.stadiumId]
|
||||
let resolvedStadium = resolveStadium(for: game, homeTeam: homeTeam, awayTeam: awayTeam)
|
||||
if resolvedStadium?.id != game.stadiumId {
|
||||
stadiumFallbacksApplied += 1
|
||||
}
|
||||
|
||||
if homeTeam == nil || awayTeam == nil || stadium == nil {
|
||||
if homeTeam == nil || awayTeam == nil || resolvedStadium == nil {
|
||||
var reasons: [String] = []
|
||||
if homeTeam == nil { reasons.append("homeTeam(\(game.homeTeamId))") }
|
||||
if awayTeam == nil { reasons.append("awayTeam(\(game.awayTeamId))") }
|
||||
if stadium == nil { reasons.append("stadium(\(game.stadiumId))") }
|
||||
if resolvedStadium == nil { reasons.append("stadium(\(game.stadiumId))") }
|
||||
droppedGames.append((game, "missing: \(reasons.joined(separator: ", "))"))
|
||||
continue
|
||||
}
|
||||
|
||||
richGames.append(RichGame(game: game, homeTeam: homeTeam!, awayTeam: awayTeam!, stadium: stadium!))
|
||||
richGames.append(RichGame(game: game, homeTeam: homeTeam!, awayTeam: awayTeam!, stadium: resolvedStadium!))
|
||||
}
|
||||
|
||||
if !droppedGames.isEmpty {
|
||||
@@ -248,6 +252,9 @@ final class AppDataProvider: ObservableObject {
|
||||
print("⚠️ [DATA] ... and \(droppedGames.count - 10) more")
|
||||
}
|
||||
}
|
||||
if stadiumFallbacksApplied > 0 {
|
||||
print("⚠️ [DATA] Applied stadium fallback for \(stadiumFallbacksApplied) games")
|
||||
}
|
||||
|
||||
print("🎮 [DATA] Returning \(richGames.count) rich games")
|
||||
return richGames
|
||||
@@ -260,7 +267,7 @@ final class AppDataProvider: ObservableObject {
|
||||
return games.compactMap { game in
|
||||
guard let homeTeam = teamsById[game.homeTeamId],
|
||||
let awayTeam = teamsById[game.awayTeamId],
|
||||
let stadium = stadiumsById[game.stadiumId] else {
|
||||
let stadium = resolveStadium(for: game, homeTeam: homeTeam, awayTeam: awayTeam) else {
|
||||
return nil
|
||||
}
|
||||
return RichGame(game: game, homeTeam: homeTeam, awayTeam: awayTeam, stadium: stadium)
|
||||
@@ -270,7 +277,7 @@ final class AppDataProvider: ObservableObject {
|
||||
func richGame(from game: Game) -> RichGame? {
|
||||
guard let homeTeam = teamsById[game.homeTeamId],
|
||||
let awayTeam = teamsById[game.awayTeamId],
|
||||
let stadium = stadiumsById[game.stadiumId] else {
|
||||
let stadium = resolveStadium(for: game, homeTeam: homeTeam, awayTeam: awayTeam) else {
|
||||
return nil
|
||||
}
|
||||
return RichGame(game: game, homeTeam: homeTeam, awayTeam: awayTeam, stadium: stadium)
|
||||
@@ -299,13 +306,27 @@ final class AppDataProvider: ObservableObject {
|
||||
let game = canonical.toDomain()
|
||||
guard let homeTeam = teamsById[game.homeTeamId],
|
||||
let awayTeam = teamsById[game.awayTeamId],
|
||||
let stadium = stadiumsById[game.stadiumId] else {
|
||||
let stadium = resolveStadium(for: game, homeTeam: homeTeam, awayTeam: awayTeam) else {
|
||||
continue
|
||||
}
|
||||
teamGames.append(RichGame(game: game, homeTeam: homeTeam, awayTeam: awayTeam, stadium: stadium))
|
||||
}
|
||||
return teamGames
|
||||
}
|
||||
|
||||
// Resolve stadium defensively: direct game reference first, then team home-venue fallbacks.
|
||||
private func resolveStadium(for game: Game, homeTeam: Team?, awayTeam: Team?) -> Stadium? {
|
||||
if let stadium = stadiumsById[game.stadiumId] {
|
||||
return stadium
|
||||
}
|
||||
if let homeTeam, let fallback = stadiumsById[homeTeam.stadiumId] {
|
||||
return fallback
|
||||
}
|
||||
if let awayTeam, let fallback = stadiumsById[awayTeam.stadiumId] {
|
||||
return fallback
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Errors
|
||||
|
||||
Reference in New Issue
Block a user