|
|
|
|
@ -886,8 +886,16 @@ class Tournament : ModelObject, Storable { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try? DataStore.shared.teamRegistrations.addOrUpdate(contentOfs: teamsToImport) |
|
|
|
|
try? DataStore.shared.playerRegistrations.addOrUpdate(contentOfs: teams.flatMap { $0.players }) |
|
|
|
|
do { |
|
|
|
|
try DataStore.shared.teamRegistrations.addOrUpdate(contentOfs: teamsToImport) |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
do { |
|
|
|
|
try DataStore.shared.playerRegistrations.addOrUpdate(contentOfs: teams.flatMap { $0.players }) |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -998,7 +1006,11 @@ class Tournament : ModelObject, Storable { |
|
|
|
|
teams.forEach { team in |
|
|
|
|
team.lockedWeight = team.weight |
|
|
|
|
} |
|
|
|
|
try? DataStore.shared.teamRegistrations.addOrUpdate(contentOfs: teams) |
|
|
|
|
do { |
|
|
|
|
try DataStore.shared.teamRegistrations.addOrUpdate(contentOfs: teams) |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func updateWeights() { |
|
|
|
|
@ -1007,9 +1019,17 @@ class Tournament : ModelObject, Storable { |
|
|
|
|
let players = team.unsortedPlayers() |
|
|
|
|
players.forEach { $0.setComputedRank(in: self) } |
|
|
|
|
team.setWeight(from: players, inTournamentCategory: tournamentCategory) |
|
|
|
|
try? DataStore.shared.playerRegistrations.addOrUpdate(contentOfs: players) |
|
|
|
|
do { |
|
|
|
|
try DataStore.shared.playerRegistrations.addOrUpdate(contentOfs: players) |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
do { |
|
|
|
|
try DataStore.shared.teamRegistrations.addOrUpdate(contentOfs: teams) |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
try? DataStore.shared.teamRegistrations.addOrUpdate(contentOfs: teams) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func updateRank(to newDate: Date?) async throws { |
|
|
|
|
@ -1023,7 +1043,11 @@ class Tournament : ModelObject, Storable { |
|
|
|
|
let monthData = MonthData(monthKey: URL.importDateFormatter.string(from: newDate)) |
|
|
|
|
monthData.maleUnrankedValue = lastRankMan |
|
|
|
|
monthData.femaleUnrankedValue = lastRankWoman |
|
|
|
|
try? DataStore.shared.monthData.addOrUpdate(instance: monthData) |
|
|
|
|
do { |
|
|
|
|
try DataStore.shared.monthData.addOrUpdate(instance: monthData) |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -1232,7 +1256,11 @@ class Tournament : ModelObject, Storable { |
|
|
|
|
_groupStages.append(groupStage) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try? DataStore.shared.groupStages.addOrUpdate(contentOfs: _groupStages) |
|
|
|
|
do { |
|
|
|
|
try DataStore.shared.groupStages.addOrUpdate(contentOfs: _groupStages) |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
refreshGroupStages() |
|
|
|
|
} |
|
|
|
|
@ -1250,7 +1278,11 @@ class Tournament : ModelObject, Storable { |
|
|
|
|
Round(tournament: id, index: $0) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try? DataStore.shared.rounds.addOrUpdate(contentOfs: rounds) |
|
|
|
|
do { |
|
|
|
|
try DataStore.shared.rounds.addOrUpdate(contentOfs: rounds) |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
let matchCount = RoundRule.numberOfMatches(forTeams: bracketTeamCount()) |
|
|
|
|
|
|
|
|
|
let matches = (0..<matchCount).map { //0 is final match |
|
|
|
|
@ -1263,7 +1295,11 @@ class Tournament : ModelObject, Storable { |
|
|
|
|
(RoundRule.roundName(fromMatchIndex: $0.index), RoundRule.matchIndexWithinRound(fromMatchIndex: $0.index)) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
try? DataStore.shared.matches.addOrUpdate(contentOfs: matches) |
|
|
|
|
do { |
|
|
|
|
try DataStore.shared.matches.addOrUpdate(contentOfs: matches) |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
self.rounds().forEach { round in |
|
|
|
|
round.buildLoserBracket() |
|
|
|
|
@ -1364,7 +1400,11 @@ class Tournament : ModelObject, Storable { |
|
|
|
|
chunks[index][jIndex].groupStage = groupStages[jIndex].id |
|
|
|
|
chunks[index][jIndex].groupStagePosition = index |
|
|
|
|
|
|
|
|
|
try? DataStore.shared.teamRegistrations.addOrUpdate(instance: chunks[index][jIndex]) |
|
|
|
|
do { |
|
|
|
|
try DataStore.shared.teamRegistrations.addOrUpdate(instance: chunks[index][jIndex]) |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|