fix: resolve specificStadium achievement ID mismatch

The Green Monster (Fenway) and Ivy League (Wrigley) achievements
weren't working because:
1. Symbolic IDs use lowercase sport (stadium_mlb_bos)
2. Sport enum uses uppercase raw values (MLB)
3. Visits store stadium UUIDs, not symbolic IDs

Added resolveSymbolicStadiumId() helper that:
- Uppercases the sport string before Sport(rawValue:)
- Looks up team by abbreviation and sport
- Returns the team's stadiumId as UUID string

Also fixed:
- getStadiumIdsForLeague returns UUID strings (not symbolic IDs)
- AchievementProgress.isEarned computed from progress OR stored record
- getStadiumIdsForDivision queries CanonicalTeam properly

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Trey t
2026-01-11 22:22:29 -06:00
parent dcd5edb229
commit 5c13650742
20 changed files with 1619 additions and 141 deletions

View File

@@ -47,6 +47,9 @@ final class PhotoImportViewModel {
func processSelectedPhotos(_ items: [PhotosPickerItem]) async {
guard !items.isEmpty else { return }
print("📷 [PhotoImport] ════════════════════════════════════════════════")
print("📷 [PhotoImport] Starting photo import with \(items.count) items")
isProcessing = true
totalCount = items.count
processedCount = 0
@@ -57,33 +60,69 @@ final class PhotoImportViewModel {
// Load PHAssets from PhotosPickerItems
var assets: [PHAsset] = []
for item in items {
for (index, item) in items.enumerated() {
print("📷 [PhotoImport] ────────────────────────────────────────────────")
print("📷 [PhotoImport] Processing item \(index + 1)/\(items.count)")
print("📷 [PhotoImport] Item identifier: \(item.itemIdentifier ?? "nil")")
print("📷 [PhotoImport] Item supportedContentTypes: \(item.supportedContentTypes)")
if let assetId = item.itemIdentifier {
let fetchResult = PHAsset.fetchAssets(withLocalIdentifiers: [assetId], options: nil)
print("📷 [PhotoImport] PHAsset fetch result count: \(fetchResult.count)")
if let asset = fetchResult.firstObject {
print("📷 [PhotoImport] ✅ Found PHAsset")
print("📷 [PhotoImport] - localIdentifier: \(asset.localIdentifier)")
print("📷 [PhotoImport] - mediaType: \(asset.mediaType.rawValue)")
print("📷 [PhotoImport] - creationDate: \(asset.creationDate?.description ?? "nil")")
print("📷 [PhotoImport] - location: \(asset.location?.description ?? "nil")")
print("📷 [PhotoImport] - sourceType: \(asset.sourceType.rawValue)")
print("📷 [PhotoImport] - pixelWidth: \(asset.pixelWidth)")
print("📷 [PhotoImport] - pixelHeight: \(asset.pixelHeight)")
assets.append(asset)
} else {
print("📷 [PhotoImport] ⚠️ No PHAsset found for identifier")
}
} else {
print("📷 [PhotoImport] ⚠️ No itemIdentifier on PhotosPickerItem")
}
processedCount += 1
}
print("📷 [PhotoImport] ────────────────────────────────────────────────")
print("📷 [PhotoImport] Loaded \(assets.count) PHAssets, extracting metadata...")
// Extract metadata from all assets
let metadataList = await metadataExtractor.extractMetadata(from: assets)
print("📷 [PhotoImport] ────────────────────────────────────────────────")
print("📷 [PhotoImport] Extracted \(metadataList.count) metadata records")
// Summarize metadata extraction results
let withLocation = metadataList.filter { $0.hasValidLocation }.count
let withDate = metadataList.filter { $0.hasValidDate }.count
print("📷 [PhotoImport] Photos with location: \(withLocation)/\(metadataList.count)")
print("📷 [PhotoImport] Photos with date: \(withDate)/\(metadataList.count)")
// Process each photo through game matcher
processedCount = 0
for metadata in metadataList {
for (index, metadata) in metadataList.enumerated() {
print("📷 [PhotoImport] Matching photo \(index + 1): date=\(metadata.captureDate?.description ?? "nil"), location=\(metadata.hasValidLocation)")
let candidate = await gameMatcher.processPhotoForImport(metadata: metadata)
processedPhotos.append(candidate)
// Auto-confirm high-confidence matches
if candidate.canAutoProcess {
confirmedImports.insert(candidate.id)
print("📷 [PhotoImport] ✅ Auto-confirmed match")
}
processedCount += 1
}
print("📷 [PhotoImport] ════════════════════════════════════════════════")
print("📷 [PhotoImport] Import complete: \(processedPhotos.count) photos, \(confirmedImports.count) auto-confirmed")
isProcessing = false
}
@@ -143,8 +182,8 @@ final class PhotoImportViewModel {
visitType: .game,
homeTeamName: match.homeTeam.fullName,
awayTeamName: match.awayTeam.fullName,
finalScore: nil,
scoreSource: nil,
finalScore: match.formattedFinalScore,
scoreSource: match.formattedFinalScore != nil ? .scraped : nil,
dataSource: .automatic,
seatLocation: nil,
notes: nil,