|
|
|
|
@ -58,6 +58,8 @@ final class Tournament : ModelObject, Storable { |
|
|
|
|
var hidePointsEarned: Bool = false |
|
|
|
|
var publishRankings: Bool = false |
|
|
|
|
var loserBracketMode: LoserBracketMode = .automatic |
|
|
|
|
var initialSeedRound: Int = 0 |
|
|
|
|
var initialSeedCount: Int = 0 |
|
|
|
|
|
|
|
|
|
@ObservationIgnored |
|
|
|
|
var navigationPath: [Screen] = [] |
|
|
|
|
@ -107,9 +109,12 @@ final class Tournament : ModelObject, Storable { |
|
|
|
|
case _hidePointsEarned = "hidePointsEarned" |
|
|
|
|
case _publishRankings = "publishRankings" |
|
|
|
|
case _loserBracketMode = "loserBracketMode" |
|
|
|
|
case _initialSeedRound = "initialSeedRound" |
|
|
|
|
case _initialSeedCount = "initialSeedCount" |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
internal init(event: String? = nil, name: String? = nil, startDate: Date = Date(), endDate: Date? = nil, creationDate: Date = Date(), isPrivate: Bool = false, groupStageFormat: MatchFormat? = nil, roundFormat: MatchFormat? = nil, loserRoundFormat: MatchFormat? = nil, groupStageSortMode: GroupStageOrderingMode, groupStageCount: Int = 4, rankSourceDate: Date? = nil, dayDuration: Int = 1, teamCount: Int = 24, teamSorting: TeamSortingType? = nil, federalCategory: TournamentCategory, federalLevelCategory: TournamentLevel, federalAgeCategory: FederalTournamentAge, closedRegistrationDate: Date? = nil, groupStageAdditionalQualified: Int = 0, courtCount: Int = 2, prioritizeClubMembers: Bool = false, qualifiedPerGroupStage: Int = 1, teamsPerGroupStage: Int = 4, entryFee: Double? = nil, additionalEstimationDuration: Int = 0, isDeleted: Bool = false, publishTeams: Bool = false, publishSummons: Bool = false, publishGroupStages: Bool = false, publishBrackets: Bool = false, shouldVerifyBracket: Bool = false, shouldVerifyGroupStage: Bool = false, hideTeamsWeight: Bool = false, publishTournament: Bool = false, hidePointsEarned: Bool = false, publishRankings: Bool = false, loserBracketMode: LoserBracketMode = .automatic) { |
|
|
|
|
internal init(event: String? = nil, name: String? = nil, startDate: Date = Date(), endDate: Date? = nil, creationDate: Date = Date(), isPrivate: Bool = false, groupStageFormat: MatchFormat? = nil, roundFormat: MatchFormat? = nil, loserRoundFormat: MatchFormat? = nil, groupStageSortMode: GroupStageOrderingMode, groupStageCount: Int = 4, rankSourceDate: Date? = nil, dayDuration: Int = 1, teamCount: Int = 24, teamSorting: TeamSortingType? = nil, federalCategory: TournamentCategory, federalLevelCategory: TournamentLevel, federalAgeCategory: FederalTournamentAge, closedRegistrationDate: Date? = nil, groupStageAdditionalQualified: Int = 0, courtCount: Int = 2, prioritizeClubMembers: Bool = false, qualifiedPerGroupStage: Int = 1, teamsPerGroupStage: Int = 4, entryFee: Double? = nil, additionalEstimationDuration: Int = 0, isDeleted: Bool = false, publishTeams: Bool = false, publishSummons: Bool = false, publishGroupStages: Bool = false, publishBrackets: Bool = false, shouldVerifyBracket: Bool = false, shouldVerifyGroupStage: Bool = false, hideTeamsWeight: Bool = false, publishTournament: Bool = false, hidePointsEarned: Bool = false, publishRankings: Bool = false, loserBracketMode: LoserBracketMode = .automatic, initialSeedRound: Int = 0, initialSeedCount: Int = 0) { |
|
|
|
|
self.event = event |
|
|
|
|
self.name = name |
|
|
|
|
self.startDate = startDate |
|
|
|
|
@ -148,6 +153,9 @@ final class Tournament : ModelObject, Storable { |
|
|
|
|
self.hidePointsEarned = hidePointsEarned |
|
|
|
|
self.publishRankings = publishRankings |
|
|
|
|
self.loserBracketMode = loserBracketMode |
|
|
|
|
self.initialSeedRound = initialSeedRound |
|
|
|
|
self.initialSeedCount = initialSeedCount |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
required init(from decoder: Decoder) throws { |
|
|
|
|
@ -193,6 +201,8 @@ final class Tournament : ModelObject, Storable { |
|
|
|
|
hidePointsEarned = try container.decodeIfPresent(Bool.self, forKey: ._hidePointsEarned) ?? false |
|
|
|
|
publishRankings = try container.decodeIfPresent(Bool.self, forKey: ._publishRankings) ?? false |
|
|
|
|
loserBracketMode = try container.decodeIfPresent(LoserBracketMode.self, forKey: ._loserBracketMode) ?? .automatic |
|
|
|
|
initialSeedRound = try container.decodeIfPresent(Int.self, forKey: ._initialSeedRound) ?? 0 |
|
|
|
|
initialSeedCount = try container.decodeIfPresent(Int.self, forKey: ._initialSeedCount) ?? 0 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fileprivate static let _numberFormatter: NumberFormatter = NumberFormatter() |
|
|
|
|
@ -279,6 +289,8 @@ final class Tournament : ModelObject, Storable { |
|
|
|
|
try container.encode(hidePointsEarned, forKey: ._hidePointsEarned) |
|
|
|
|
try container.encode(publishRankings, forKey: ._publishRankings) |
|
|
|
|
try container.encode(loserBracketMode, forKey: ._loserBracketMode) |
|
|
|
|
try container.encode(initialSeedRound, forKey: ._initialSeedRound) |
|
|
|
|
try container.encode(initialSeedCount, forKey: ._initialSeedCount) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fileprivate func _encodePayment(container: inout KeyedEncodingContainer<CodingKeys>) throws { |
|
|
|
|
@ -673,11 +685,15 @@ defer { |
|
|
|
|
if availableSeeds().isEmpty == false && roundIndex >= lastSeedRound() { |
|
|
|
|
|
|
|
|
|
if availableSeedGroup == SeedInterval(first: 1, last: 2) { return availableSeedGroup } |
|
|
|
|
|
|
|
|
|
let availableSeeds = seeds(inSeedGroup: availableSeedGroup) |
|
|
|
|
let availableSeedSpot = availableSeedSpot(inRoundIndex: roundIndex) |
|
|
|
|
let availableSeedOpponentSpot = availableSeedOpponentSpot(inRoundIndex: roundIndex) |
|
|
|
|
|
|
|
|
|
if availableSeedGroup == SeedInterval(first: 3, last: 4), availableSeedSpot.count == 6 { |
|
|
|
|
print("availableSeedGroup == SeedInterval(first: 3, last: 4)") |
|
|
|
|
return availableSeedGroup |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if availableSeeds.count == availableSeedSpot.count && availableSeedGroup.count == availableSeeds.count { |
|
|
|
|
return availableSeedGroup |
|
|
|
|
} else if availableSeeds.count == availableSeedOpponentSpot.count && availableSeedGroup.count == availableSeedOpponentSpot.count { |
|
|
|
|
@ -711,22 +727,35 @@ defer { |
|
|
|
|
let availableSeedOpponentSpot = availableSeedOpponentSpot(inRoundIndex: roundIndex) |
|
|
|
|
let availableSeeds = seeds(inSeedGroup: seedGroup) |
|
|
|
|
|
|
|
|
|
if availableSeeds.count <= availableSeedSpot.count { |
|
|
|
|
let spots = availableSeedSpot.shuffled() |
|
|
|
|
for (index, seed) in availableSeeds.enumerated() { |
|
|
|
|
seed.setSeedPosition(inSpot: spots[index], slot: nil, opposingSeeding: false) |
|
|
|
|
} |
|
|
|
|
} else if (availableSeeds.count <= availableSeedOpponentSpot.count && availableSeeds.count <= self.availableSeeds().count) { |
|
|
|
|
|
|
|
|
|
let spots = availableSeedOpponentSpot.shuffled() |
|
|
|
|
for (index, seed) in availableSeeds.enumerated() { |
|
|
|
|
seed.setSeedPosition(inSpot: spots[index], slot: nil, opposingSeeding: true) |
|
|
|
|
if seedGroup == SeedInterval(first: 3, last: 4) { |
|
|
|
|
print("availableSeedGroup == SeedInterval(first: 3, last: 4)") |
|
|
|
|
if availableSeedSpot.count == 6 { |
|
|
|
|
var spots = [Match]() |
|
|
|
|
spots.append(availableSeedSpot[1]) |
|
|
|
|
spots.append(availableSeedSpot[4]) |
|
|
|
|
spots = spots.shuffled() |
|
|
|
|
for (index, seed) in availableSeeds.enumerated() { |
|
|
|
|
seed.setSeedPosition(inSpot: spots[index], slot: nil, opposingSeeding: false) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else if let chunks = seedGroup.chunks() { |
|
|
|
|
if let chunk = chunks.first(where: { seedInterval in |
|
|
|
|
seedInterval.first >= self.seededTeams().count |
|
|
|
|
}) { |
|
|
|
|
setSeeds(inRoundIndex: roundIndex, inSeedGroup: chunk) |
|
|
|
|
} else { |
|
|
|
|
if availableSeeds.count <= availableSeedSpot.count { |
|
|
|
|
let spots = availableSeedSpot.shuffled() |
|
|
|
|
for (index, seed) in availableSeeds.enumerated() { |
|
|
|
|
seed.setSeedPosition(inSpot: spots[index], slot: nil, opposingSeeding: false) |
|
|
|
|
} |
|
|
|
|
} else if (availableSeeds.count <= availableSeedOpponentSpot.count && availableSeeds.count <= self.availableSeeds().count) { |
|
|
|
|
|
|
|
|
|
let spots = availableSeedOpponentSpot.shuffled() |
|
|
|
|
for (index, seed) in availableSeeds.enumerated() { |
|
|
|
|
seed.setSeedPosition(inSpot: spots[index], slot: nil, opposingSeeding: true) |
|
|
|
|
} |
|
|
|
|
} else if let chunks = seedGroup.chunks() { |
|
|
|
|
if let chunk = chunks.first(where: { seedInterval in |
|
|
|
|
seedInterval.first >= self.seededTeams().count |
|
|
|
|
}) { |
|
|
|
|
setSeeds(inRoundIndex: roundIndex, inSeedGroup: chunk) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -829,7 +858,7 @@ defer { |
|
|
|
|
let wcBracket = _teams.filter { $0.wildCardBracket }.sorted(using: _currentSelectionSorting, order: .ascending) |
|
|
|
|
|
|
|
|
|
let groupStageSpots: Int = self.groupStageSpots() |
|
|
|
|
var bracketSeeds: Int = min(teamCount, _completeTeams.count) - groupStageSpots - wcBracket.count |
|
|
|
|
var bracketSeeds: Int = min(teamCount, _teams.count) - groupStageSpots - wcBracket.count |
|
|
|
|
var groupStageTeamCount: Int = groupStageSpots - wcGroupStage.count |
|
|
|
|
if groupStageTeamCount < 0 { groupStageTeamCount = 0 } |
|
|
|
|
if bracketSeeds < 0 { bracketSeeds = 0 } |
|
|
|
|
|