fix(schedule): use start of day for date range queries
- Fix startDate to use Calendar.startOfDay instead of Date() to include games earlier in the current day - Add SyncLogger for file-based sync logging viewable in Settings - Add "View Sync Logs" button in Settings debug section - Add diagnostics and NBA game logging to ScheduleViewModel - Add dropped game logging to DataProvider.filterRichGames - Use SyncLogger in SportsTimeApp and CloudKitService for sync operations Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -217,14 +217,40 @@ final class AppDataProvider: ObservableObject {
|
||||
func filterRichGames(sports: Set<Sport>, startDate: Date, endDate: Date) async throws -> [RichGame] {
|
||||
let games = try await filterGames(sports: sports, startDate: startDate, endDate: endDate)
|
||||
|
||||
return games.compactMap { game in
|
||||
guard let homeTeam = teamsById[game.homeTeamId],
|
||||
let awayTeam = teamsById[game.awayTeamId],
|
||||
let stadium = stadiumsById[game.stadiumId] else {
|
||||
return nil
|
||||
print("🎮 [DATA] filterRichGames: \(games.count) games from SwiftData for \(sports.map(\.rawValue).joined(separator: ", "))")
|
||||
|
||||
var richGames: [RichGame] = []
|
||||
var droppedGames: [(game: Game, reason: String)] = []
|
||||
|
||||
for game in games {
|
||||
let homeTeam = teamsById[game.homeTeamId]
|
||||
let awayTeam = teamsById[game.awayTeamId]
|
||||
let stadium = stadiumsById[game.stadiumId]
|
||||
|
||||
if homeTeam == nil || awayTeam == nil || stadium == 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))") }
|
||||
droppedGames.append((game, "missing: \(reasons.joined(separator: ", "))"))
|
||||
continue
|
||||
}
|
||||
return RichGame(game: game, homeTeam: homeTeam, awayTeam: awayTeam, stadium: stadium)
|
||||
|
||||
richGames.append(RichGame(game: game, homeTeam: homeTeam!, awayTeam: awayTeam!, stadium: stadium!))
|
||||
}
|
||||
|
||||
if !droppedGames.isEmpty {
|
||||
print("⚠️ [DATA] Dropped \(droppedGames.count) games due to missing lookups:")
|
||||
for (game, reason) in droppedGames.prefix(10) {
|
||||
print("⚠️ [DATA] \(game.sport.rawValue) game \(game.id): \(reason)")
|
||||
}
|
||||
if droppedGames.count > 10 {
|
||||
print("⚠️ [DATA] ... and \(droppedGames.count - 10) more")
|
||||
}
|
||||
}
|
||||
|
||||
print("🎮 [DATA] Returning \(richGames.count) rich games")
|
||||
return richGames
|
||||
}
|
||||
|
||||
/// Get all games with full team and stadium data (no date filtering)
|
||||
|
||||
Reference in New Issue
Block a user