|
|
|
@ -727,12 +727,13 @@ class Tournament : ModelObject, Storable { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func selectedSortedTeams() -> [TeamRegistration] { |
|
|
|
func selectedSortedTeams() -> [TeamRegistration] { |
|
|
|
// let start = Date() |
|
|
|
#if DEBUG_TIME |
|
|
|
// defer { |
|
|
|
let start = Date() |
|
|
|
// let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000) |
|
|
|
defer { |
|
|
|
// print("func selectedSortedTeams", id, tournamentTitle(), duration.formatted(.units(allowed: [.seconds, .milliseconds]))) |
|
|
|
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000) |
|
|
|
// } |
|
|
|
print("func selectedSortedTeams", id, tournamentTitle(), duration.formatted(.units(allowed: [.seconds, .milliseconds]))) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|
var _sortedTeams : [TeamRegistration] = [] |
|
|
|
var _sortedTeams : [TeamRegistration] = [] |
|
|
|
let _teams = unsortedTeams().filter({ $0.walkOut == false }) |
|
|
|
let _teams = unsortedTeams().filter({ $0.walkOut == false }) |
|
|
|
|
|
|
|
|
|
|
|
@ -956,47 +957,57 @@ class Tournament : ModelObject, Storable { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func availableToStart(_ allMatches: [Match], in runningMatches: [Match]) async -> [Match] { |
|
|
|
func availableToStart(_ allMatches: [Match], in runningMatches: [Match]) async -> [Match] { |
|
|
|
|
|
|
|
#if DEBUG_TIME |
|
|
|
let start = Date() |
|
|
|
let start = Date() |
|
|
|
defer { |
|
|
|
defer { |
|
|
|
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000) |
|
|
|
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000) |
|
|
|
print("func tournament availableToStart", id, duration.formatted(.units(allowed: [.seconds, .milliseconds]))) |
|
|
|
print("func tournament availableToStart", id, duration.formatted(.units(allowed: [.seconds, .milliseconds]))) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|
return allMatches.filter({ $0.canBeStarted(inMatches: runningMatches) && $0.isRunning() == false }).sorted(by: \.computedStartDateForSorting) |
|
|
|
return allMatches.filter({ $0.canBeStarted(inMatches: runningMatches) && $0.isRunning() == false }).sorted(by: \.computedStartDateForSorting) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func asyncRunningMatches(_ allMatches: [Match]) async -> [Match] { |
|
|
|
func asyncRunningMatches(_ allMatches: [Match]) async -> [Match] { |
|
|
|
|
|
|
|
#if DEBUG_TIME |
|
|
|
let start = Date() |
|
|
|
let start = Date() |
|
|
|
defer { |
|
|
|
defer { |
|
|
|
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000) |
|
|
|
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000) |
|
|
|
print("func tournament runningMatches", id, duration.formatted(.units(allowed: [.seconds, .milliseconds]))) |
|
|
|
print("func tournament runningMatches", id, duration.formatted(.units(allowed: [.seconds, .milliseconds]))) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|
return allMatches.filter({ $0.isRunning() && $0.isReady() }).sorted(by: \.computedStartDateForSorting) |
|
|
|
return allMatches.filter({ $0.isRunning() && $0.isReady() }).sorted(by: \.computedStartDateForSorting) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func runningMatches(_ allMatches: [Match]) -> [Match] { |
|
|
|
func runningMatches(_ allMatches: [Match]) -> [Match] { |
|
|
|
|
|
|
|
#if DEBUG_TIME |
|
|
|
let start = Date() |
|
|
|
let start = Date() |
|
|
|
defer { |
|
|
|
defer { |
|
|
|
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000) |
|
|
|
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000) |
|
|
|
print("func tournament runningMatches", id, duration.formatted(.units(allowed: [.seconds, .milliseconds]))) |
|
|
|
print("func tournament runningMatches", id, duration.formatted(.units(allowed: [.seconds, .milliseconds]))) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|
return allMatches.filter({ $0.isRunning() && $0.isReady() }).sorted(by: \.computedStartDateForSorting) |
|
|
|
return allMatches.filter({ $0.isRunning() && $0.isReady() }).sorted(by: \.computedStartDateForSorting) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func readyMatches(_ allMatches: [Match]) async -> [Match] { |
|
|
|
func readyMatches(_ allMatches: [Match]) async -> [Match] { |
|
|
|
|
|
|
|
#if DEBUG_TIME |
|
|
|
let start = Date() |
|
|
|
let start = Date() |
|
|
|
defer { |
|
|
|
defer { |
|
|
|
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000) |
|
|
|
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000) |
|
|
|
print("func tournament readyMatches", id, duration.formatted(.units(allowed: [.seconds, .milliseconds]))) |
|
|
|
print("func tournament readyMatches", id, duration.formatted(.units(allowed: [.seconds, .milliseconds]))) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|
return allMatches.filter({ $0.isReady() && $0.isRunning() == false && $0.hasEnded() == false }).sorted(by: \.computedStartDateForSorting) |
|
|
|
return allMatches.filter({ $0.isReady() && $0.isRunning() == false && $0.hasEnded() == false }).sorted(by: \.computedStartDateForSorting) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func finishedMatches(_ allMatches: [Match], limit: Int? = nil) -> [Match] { |
|
|
|
func finishedMatches(_ allMatches: [Match], limit: Int? = nil) -> [Match] { |
|
|
|
|
|
|
|
#if DEBUG_TIME |
|
|
|
let start = Date() |
|
|
|
let start = Date() |
|
|
|
defer { |
|
|
|
defer { |
|
|
|
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000) |
|
|
|
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000) |
|
|
|
print("func tournament finishedMatches", id, duration.formatted(.units(allowed: [.seconds, .milliseconds]))) |
|
|
|
print("func tournament finishedMatches", id, duration.formatted(.units(allowed: [.seconds, .milliseconds]))) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|
let _limit = limit ?? courtCount |
|
|
|
let _limit = limit ?? courtCount |
|
|
|
return Array(allMatches.filter({ $0.hasEnded() }).sorted(by: \.computedEndDateForSorting).reversed().prefix(_limit)) |
|
|
|
return Array(allMatches.filter({ $0.hasEnded() }).sorted(by: \.computedEndDateForSorting).reversed().prefix(_limit)) |
|
|
|
} |
|
|
|
} |
|
|
|
@ -1653,7 +1664,10 @@ class Tournament : ModelObject, Storable { |
|
|
|
|
|
|
|
|
|
|
|
func getGroupStageChunkValue() -> Int { |
|
|
|
func getGroupStageChunkValue() -> Int { |
|
|
|
if teamsPerGroupStage >= 2 { |
|
|
|
if teamsPerGroupStage >= 2 { |
|
|
|
return min(groupStageCount, courtCount / (teamsPerGroupStage / 2)) |
|
|
|
let result = courtCount / (teamsPerGroupStage / 2) |
|
|
|
|
|
|
|
let remainder = courtCount % (teamsPerGroupStage / 2) |
|
|
|
|
|
|
|
let value = remainder == 0 ? result : result + 1 |
|
|
|
|
|
|
|
return min(groupStageCount, value) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return 1 |
|
|
|
return 1 |
|
|
|
} |
|
|
|
} |
|
|
|
|