club_update
Razmig Sarkissian 1 year ago
parent 9dfcfc1441
commit b72ce42d95
  1. 43
      PadelClub/Data/Tournament.swift

@ -1660,31 +1660,32 @@ defer {
if groupStageCount != numberOfBracketsAsInt { if groupStageCount != numberOfBracketsAsInt {
deleteGroupStages() deleteGroupStages()
buildGroupStages() buildGroupStages()
} } else {
let max = groupStages.map { $0.size }.reduce(0,+) let max = groupStages.map { $0.size }.reduce(0,+)
var chunks = selectedSortedTeams().suffix(max).chunked(into: groupStageCount) var chunks = selectedSortedTeams().suffix(max).chunked(into: groupStageCount)
for (index, _) in chunks.enumerated() { for (index, _) in chunks.enumerated() {
if randomize { if randomize {
chunks[index].shuffle() chunks[index].shuffle()
} else if index % 2 != 0 { } else if index % 2 != 0 {
chunks[index].reverse() chunks[index].reverse()
}
print("Equipes \(chunks[index].map { $0.weight })")
for (jIndex, _) in chunks[index].enumerated() {
print("Position \(index + 1) Poule \(groupStages[jIndex].index)")
chunks[index][jIndex].groupStage = groupStages[jIndex].id
chunks[index][jIndex].groupStagePosition = index
}
} }
print("Equipes \(chunks[index].map { $0.weight })") do {
for (jIndex, _) in chunks[index].enumerated() { try self.tournamentStore.teamRegistrations.addOrUpdate(contentOfs: unsortedTeams())
print("Position \(index + 1) Poule \(groupStages[jIndex].index)") } catch {
chunks[index][jIndex].groupStage = groupStages[jIndex].id Logger.error(error)
chunks[index][jIndex].groupStagePosition = index
} }
groupStages.forEach { $0.buildMatches() }
} }
do {
try self.tournamentStore.teamRegistrations.addOrUpdate(contentOfs: unsortedTeams())
} catch {
Logger.error(error)
}
groupStages.forEach { $0.buildMatches() }
} }

Loading…
Cancel
Save