|
|
|
@ -88,6 +88,25 @@ final public class Tournament: BaseTournament { |
|
|
|
return self.tournamentStore?.teamRegistrations.count ?? 0 |
|
|
|
return self.tournamentStore?.teamRegistrations.count ?? 0 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public func deleteGroupStage(_ groupStage: GroupStage) { |
|
|
|
|
|
|
|
groupStage.removeAllTeams() |
|
|
|
|
|
|
|
let index = groupStage.index |
|
|
|
|
|
|
|
self.tournamentStore?.groupStages.delete(instance: groupStage) |
|
|
|
|
|
|
|
self.groupStageCount -= 1 |
|
|
|
|
|
|
|
let groupStages = self.groupStages() |
|
|
|
|
|
|
|
groupStages.filter({ $0.index > index }).forEach { gs in |
|
|
|
|
|
|
|
gs.index -= 1 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
self.tournamentStore?.groupStages.addOrUpdate(contentOfs: groupStages) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public func addGroupStage() { |
|
|
|
|
|
|
|
let groupStage = GroupStage(tournament: id, index: groupStageCount, size: teamsPerGroupStage, format: groupStageFormat) |
|
|
|
|
|
|
|
self.tournamentStore?.groupStages.addOrUpdate(instance: groupStage) |
|
|
|
|
|
|
|
groupStage.buildMatches(keepExistingMatches: false) |
|
|
|
|
|
|
|
self.groupStageCount += 1 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public func groupStages(atStep step: Int = 0) -> [GroupStage] { |
|
|
|
public func groupStages(atStep step: Int = 0) -> [GroupStage] { |
|
|
|
guard let tournamentStore = self.tournamentStore else { return [] } |
|
|
|
guard let tournamentStore = self.tournamentStore else { return [] } |
|
|
|
let groupStages: [GroupStage] = tournamentStore.groupStages.filter { $0.tournament == self.id && $0.step == step } |
|
|
|
let groupStages: [GroupStage] = tournamentStore.groupStages.filter { $0.tournament == self.id && $0.step == step } |
|
|
|
@ -856,7 +875,7 @@ defer { |
|
|
|
return allMatches.filter({ $0.isRunning() && $0.isReady() }).sorted(using: defaultSorting, order: .ascending) |
|
|
|
return allMatches.filter({ $0.isRunning() && $0.isReady() }).sorted(using: defaultSorting, order: .ascending) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static func readyMatches(_ allMatches: [Match]) -> [Match] { |
|
|
|
public static func readyMatches(_ allMatches: [Match], runningMatches: [Match]) -> [Match] { |
|
|
|
#if _DEBUG_TIME //DEBUGING TIME |
|
|
|
#if _DEBUG_TIME //DEBUGING TIME |
|
|
|
let start = Date() |
|
|
|
let start = Date() |
|
|
|
defer { |
|
|
|
defer { |
|
|
|
@ -864,7 +883,10 @@ defer { |
|
|
|
print("func tournament readyMatches", id, duration.formatted(.units(allowed: [.seconds, .milliseconds]))) |
|
|
|
print("func tournament readyMatches", id, duration.formatted(.units(allowed: [.seconds, .milliseconds]))) |
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
return allMatches.filter({ $0.isReady() && $0.isRunning() == false && $0.hasEnded() == false }).sorted(using: defaultSorting, order: .ascending) |
|
|
|
|
|
|
|
|
|
|
|
let playingTeams = runningMatches.flatMap({ $0.teams() }).map({ $0.id }) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return allMatches.filter({ $0.isReady() && $0.isRunning() == false && $0.hasEnded() == false && $0.containsTeamIds(playingTeams) == false }).sorted(using: defaultSorting, order: .ascending) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static func matchesLeft(_ allMatches: [Match]) -> [Match] { |
|
|
|
public static func matchesLeft(_ allMatches: [Match]) -> [Match] { |
|
|
|
|