|
|
|
|
@ -169,7 +169,19 @@ class FederalPlayer: Decodable { |
|
|
|
|
club = result[10] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static func lastRank(mostRecentDateAvailable: Date?, man: Bool) async -> Int? { |
|
|
|
|
static func anonymousCount(mostRecentDateAvailable: Date?) async -> Int? { |
|
|
|
|
let context = PersistenceController.shared.localContainer.newBackgroundContext() |
|
|
|
|
let importedPlayerFetchRequest = ImportedPlayer.fetchRequest() |
|
|
|
|
var predicate = NSPredicate(format: "lastName == %@ && firstName == %@", "", "") |
|
|
|
|
if let mostRecentDateAvailable { |
|
|
|
|
predicate = NSCompoundPredicate(andPredicateWithSubpredicates: [predicate, NSPredicate(format: "importDate == %@", mostRecentDateAvailable as CVarArg)]) |
|
|
|
|
} |
|
|
|
|
importedPlayerFetchRequest.predicate = predicate |
|
|
|
|
let count = try? context.count(for: importedPlayerFetchRequest) |
|
|
|
|
return count |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static func lastRank(mostRecentDateAvailable: Date?, man: Bool) async -> (Int, Int?)? { |
|
|
|
|
let context = PersistenceController.shared.localContainer.newBackgroundContext() |
|
|
|
|
let lastPlayerFetch = ImportedPlayer.fetchRequest() |
|
|
|
|
lastPlayerFetch.sortDescriptors = [NSSortDescriptor(keyPath: \ImportedPlayer.rank, ascending: false)] |
|
|
|
|
@ -178,7 +190,7 @@ class FederalPlayer: Decodable { |
|
|
|
|
predicate = NSCompoundPredicate(andPredicateWithSubpredicates: [predicate, NSPredicate(format: "importDate == %@", mostRecentDateAvailable as CVarArg)]) |
|
|
|
|
} |
|
|
|
|
lastPlayerFetch.predicate = predicate |
|
|
|
|
|
|
|
|
|
let count = try? context.count(for: lastPlayerFetch) |
|
|
|
|
do { |
|
|
|
|
if let lr = try context.fetch(lastPlayerFetch).first?.rank { |
|
|
|
|
let fetch = ImportedPlayer.fetchRequest() |
|
|
|
|
@ -189,7 +201,7 @@ class FederalPlayer: Decodable { |
|
|
|
|
fetch.predicate = rankPredicate |
|
|
|
|
|
|
|
|
|
let lastPlayersCount = try context.count(for: fetch) |
|
|
|
|
return Int(lr) + Int(lastPlayersCount) - 1 |
|
|
|
|
return (Int(lr) + Int(lastPlayersCount) - 1, count) |
|
|
|
|
} |
|
|
|
|
} catch { |
|
|
|
|
print("ImportedPlayer.fetchRequest", error) |
|
|
|
|
|