|
|
|
|
@ -92,26 +92,29 @@ class Round: ModelObject, Storable { |
|
|
|
|
|
|
|
|
|
func seed(_ team: TeamPosition, inMatchIndex matchIndex: Int) -> TeamRegistration? { |
|
|
|
|
return Store.main.filter(isIncluded: { |
|
|
|
|
$0.tournament == tournament && $0.bracketPosition != nil |
|
|
|
|
}).first(where: { |
|
|
|
|
($0.bracketPosition! / 2) == matchIndex |
|
|
|
|
$0.tournament == tournament |
|
|
|
|
&& $0.bracketPosition != nil |
|
|
|
|
&& ($0.bracketPosition! / 2) == matchIndex |
|
|
|
|
&& ($0.bracketPosition! % 2) == team.rawValue |
|
|
|
|
}) |
|
|
|
|
}).first |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func seeds(inMatchIndex matchIndex: Int) -> [TeamRegistration] { |
|
|
|
|
return Store.main.filter(isIncluded: { |
|
|
|
|
$0.tournament == tournament && $0.bracketPosition != nil |
|
|
|
|
}).filter({ |
|
|
|
|
($0.bracketPosition! / 2) == matchIndex |
|
|
|
|
$0.tournament == tournament |
|
|
|
|
&& $0.bracketPosition != nil |
|
|
|
|
&& ($0.bracketPosition! / 2) == matchIndex |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func seeds() -> [TeamRegistration] { |
|
|
|
|
let initialMatchIndex = RoundRule.matchIndex(fromRoundIndex: index) |
|
|
|
|
let numberOfMatches = RoundRule.numberOfMatches(forRoundIndex: index) |
|
|
|
|
return Store.main.filter(isIncluded: { |
|
|
|
|
$0.tournament == tournament && $0.bracketPosition != nil |
|
|
|
|
}).filter({ |
|
|
|
|
($0.bracketPosition! / 2) >= RoundRule.matchIndex(fromRoundIndex: index) && ($0.bracketPosition! / 2) < RoundRule.matchIndex(fromRoundIndex: index) + RoundRule.numberOfMatches(forRoundIndex: index) |
|
|
|
|
$0.tournament == tournament |
|
|
|
|
&& $0.bracketPosition != nil |
|
|
|
|
&& ($0.bracketPosition! / 2) >= initialMatchIndex |
|
|
|
|
&& ($0.bracketPosition! / 2) < initialMatchIndex + numberOfMatches |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -246,8 +249,8 @@ class Round: ModelObject, Storable { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func getActiveLoserRound() -> Round? { |
|
|
|
|
let rounds = loserRounds() |
|
|
|
|
return rounds.filter({ $0.hasStarted() && $0.hasEnded() == false && $0.isDisabled() == false }).sorted(by: \.index).reversed().first ?? rounds.first(where: { $0.isDisabled() == false }) |
|
|
|
|
let rounds = loserRounds().filter({ $0.isDisabled() == false }).sorted(by: \.index).reversed() |
|
|
|
|
return rounds.first(where: { $0.hasStarted() && $0.hasEnded() == false }) ?? rounds.first |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func enableRound() { |
|
|
|
|
@ -299,31 +302,43 @@ class Round: ModelObject, Storable { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func correspondingLoserRoundTitle(_ displayStyle: DisplayStyle = .wide) -> String { |
|
|
|
|
if let parentRound, let initialRound = parentRound.initialRound() { |
|
|
|
|
let parentMatchCount = parentRound.cumulativeMatchCount - initialRound.playedMatches().count |
|
|
|
|
// print("initialRound", initialRound.roundTitle()) |
|
|
|
|
if let initialRoundNextRound = initialRound.nextRound() { |
|
|
|
|
let total = initialRoundNextRound.playedMatches().count * 2 + initialRoundNextRound.disabledMatches().count |
|
|
|
|
let previousRoundMatchCount = (previousRound() ?? parentRound).playedMatches().count |
|
|
|
|
let seedInterval = SeedInterval(first: parentMatchCount + total + 1, last: parentMatchCount + total + previousRoundMatchCount).localizedLabel(displayStyle) |
|
|
|
|
// print("seedInterval", seedInterval, parentMatchCount, total, previousRoundMatchCount) |
|
|
|
|
return seedInterval |
|
|
|
|
} |
|
|
|
|
let initialMatchIndexFromRoundIndex = RoundRule.matchIndex(fromRoundIndex: index) |
|
|
|
|
let seedsAfterThisRound : [TeamRegistration] = Store.main.filter(isIncluded: { |
|
|
|
|
$0.tournament == tournament |
|
|
|
|
&& $0.bracketPosition != nil |
|
|
|
|
&& ($0.bracketPosition! / 2) < initialMatchIndexFromRoundIndex |
|
|
|
|
}) |
|
|
|
|
let playedMatches = playedMatches() |
|
|
|
|
let seedInterval = SeedInterval(first: playedMatches.count + seedsAfterThisRound.count + 1, last: playedMatches.count * 2 + seedsAfterThisRound.count) |
|
|
|
|
return seedInterval.localizedLabel(displayStyle) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func seedInterval() -> SeedInterval? { |
|
|
|
|
if loser == nil { |
|
|
|
|
let numberOfMatches = RoundRule.numberOfMatches(forRoundIndex: index + 1) |
|
|
|
|
let initialMatchIndexFromRoundIndex = RoundRule.matchIndex(fromRoundIndex: index) |
|
|
|
|
let seedsAfterThisRound : [TeamRegistration] = Store.main.filter(isIncluded: { |
|
|
|
|
$0.tournament == tournament |
|
|
|
|
&& $0.bracketPosition != nil |
|
|
|
|
&& ($0.bracketPosition! / 2) < initialMatchIndexFromRoundIndex |
|
|
|
|
}) |
|
|
|
|
let playedMatches = playedMatches() |
|
|
|
|
let reduce = numberOfMatches / 2 - (playedMatches.count + seedsAfterThisRound.count) |
|
|
|
|
return SeedInterval(first: 1, last: numberOfMatches, reduce: reduce) |
|
|
|
|
} |
|
|
|
|
return RoundRule.roundName(fromRoundIndex: index) |
|
|
|
|
|
|
|
|
|
if let previousRound = previousRound() { |
|
|
|
|
return previousRound.seedInterval()?.chunks()?.first |
|
|
|
|
} else if let parentRound = parentRound { |
|
|
|
|
return parentRound.seedInterval()?.chunks()?.last |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func roundTitle(_ displayStyle: DisplayStyle = .wide) -> String { |
|
|
|
|
if let parentRound, let initialRound = parentRound.initialRound() { |
|
|
|
|
let parentMatchCount = parentRound.theoryCumulativeMatchCount - RoundRule.numberOfMatches(forRoundIndex: initialRound.index) |
|
|
|
|
// print("initialRound", initialRound.roundTitle()) |
|
|
|
|
if let initialRoundNextRound = initialRound.nextRound() { |
|
|
|
|
let total = initialRoundNextRound.playedMatches().count * 2 + initialRoundNextRound.disabledMatches().count |
|
|
|
|
let previousRoundMatchCount = RoundRule.numberOfMatches(forRoundIndex: (previousRound() ?? parentRound).index) |
|
|
|
|
let seedInterval = SeedInterval(first: parentMatchCount + total + 1, last: parentMatchCount + total + previousRoundMatchCount).localizedLabel(displayStyle) |
|
|
|
|
// print("seedInterval", seedInterval, parentMatchCount, total, previousRoundMatchCount) |
|
|
|
|
return seedInterval |
|
|
|
|
} |
|
|
|
|
if loser != nil { |
|
|
|
|
return seedInterval()?.localizedLabel(displayStyle) ?? "Pas trouvé" |
|
|
|
|
} |
|
|
|
|
return RoundRule.roundName(fromRoundIndex: index) |
|
|
|
|
} |
|
|
|
|
|