|
|
|
|
@ -57,6 +57,8 @@ struct InscriptionManagerView: View { |
|
|
|
|
@State private var gatheringDone: Bool = false |
|
|
|
|
@State private var totalUnrankedUnsourced: Double = 0 |
|
|
|
|
|
|
|
|
|
@State private var selectedSortedTeams: [TeamRegistration] = [] |
|
|
|
|
|
|
|
|
|
var tournamentStore: TournamentStore { |
|
|
|
|
return self.tournament.tournamentStore |
|
|
|
|
} |
|
|
|
|
@ -190,14 +192,18 @@ struct InscriptionManagerView: View { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func _setHash() { |
|
|
|
|
#if _DEBUG_TIME //DEBUGING TIME |
|
|
|
|
self.selectedSortedTeams = self.tournament.selectedSortedTeams() |
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if DEBUG //DEBUGING TIME |
|
|
|
|
let start = Date() |
|
|
|
|
defer { |
|
|
|
|
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000) |
|
|
|
|
print("func _setHash", duration.formatted(.units(allowed: [.seconds, .milliseconds]))) |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
let selectedSortedTeams = tournament.selectedSortedTeams() |
|
|
|
|
//let selectedSortedTeams = tournament.selectedSortedTeams() |
|
|
|
|
if self.teamsHash == nil, selectedSortedTeams.isEmpty == false { |
|
|
|
|
self.teamsHash = _simpleHash(ids: selectedSortedTeams.map { $0.id }) |
|
|
|
|
} |
|
|
|
|
@ -208,7 +214,7 @@ struct InscriptionManagerView: View { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func _handleHashDiff() { |
|
|
|
|
let selectedSortedTeams = tournament.selectedSortedTeams() |
|
|
|
|
//let selectedSortedTeams = tournament.selectedSortedTeams() |
|
|
|
|
let newHash = _simpleHash(ids: selectedSortedTeams.map { $0.id }) |
|
|
|
|
if (self.teamsHash != nil && newHash != teamsHash!) || (self.teamsHash == nil && selectedSortedTeams.isEmpty == false) { |
|
|
|
|
self.teamsHash = newHash |
|
|
|
|
@ -465,22 +471,22 @@ struct InscriptionManagerView: View { |
|
|
|
|
|
|
|
|
|
private func _sharingTeamsMenuView() -> some View { |
|
|
|
|
Menu { |
|
|
|
|
if let teamPaste = teamPaste() { |
|
|
|
|
ShareLink(item: teamPaste) { |
|
|
|
|
Text("En texte") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if let teamPaste = teamPaste(.csv) { |
|
|
|
|
ShareLink(item: teamPaste) { |
|
|
|
|
Text("En csv") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// if let teamPaste = teamPaste() { |
|
|
|
|
// ShareLink(item: teamPaste) { |
|
|
|
|
// Text("En texte") |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
// if let teamPaste = teamPaste(.csv) { |
|
|
|
|
// ShareLink(item: teamPaste) { |
|
|
|
|
// Text("En csv") |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
if let teamPaste = teamPaste(.championship) { |
|
|
|
|
ShareLink(item: teamPaste) { |
|
|
|
|
Text("En csv pour la ligue") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// if let teamPaste = teamPaste(.championship) { |
|
|
|
|
// ShareLink(item: teamPaste) { |
|
|
|
|
// Text("En csv pour la ligue") |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
} label: { |
|
|
|
|
Label("Exporter les paires", systemImage: "square.and.arrow.up") |
|
|
|
|
} |
|
|
|
|
@ -504,9 +510,9 @@ struct InscriptionManagerView: View { |
|
|
|
|
|
|
|
|
|
var sortedTeams: [TeamRegistration] { |
|
|
|
|
if filterMode == .waiting { |
|
|
|
|
return tournament.waitingListSortedTeams() |
|
|
|
|
return tournament.waitingListTeams(in: selectedSortedTeams, includingWalkOuts: false) |
|
|
|
|
} else { |
|
|
|
|
return tournament.sortedTeams() |
|
|
|
|
return selectedSortedTeams + tournament.waitingListTeams(in: selectedSortedTeams, includingWalkOuts: true) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -585,7 +591,7 @@ struct InscriptionManagerView: View { |
|
|
|
|
|
|
|
|
|
private func _teamRegisteredView() -> some View { |
|
|
|
|
List { |
|
|
|
|
let selectedSortedTeams = tournament.selectedSortedTeams() |
|
|
|
|
let sortedTeams = sortedTeams |
|
|
|
|
|
|
|
|
|
if presentSearch == false { |
|
|
|
|
_informationView() |
|
|
|
|
@ -629,16 +635,12 @@ struct InscriptionManagerView: View { |
|
|
|
|
EditingTeamView(team: team) |
|
|
|
|
.environment(tournament) |
|
|
|
|
} label: { |
|
|
|
|
TeamRowView(team: team) |
|
|
|
|
TeamRowView(team: team, teamIndex: teamIndex) |
|
|
|
|
} |
|
|
|
|
.swipeActions(edge: .trailing, allowsFullSwipe: true) { |
|
|
|
|
_teamDeleteButtonView(team) |
|
|
|
|
} |
|
|
|
|
.listRowView(isActive: true, color: team.initialRoundColor() ?? tournament.cutLabelColor(index: teamIndex, teamCount: filterMode == .waiting ? 0 : selectedSortedTeams.count), hideColorVariation: true) |
|
|
|
|
.onAppear { |
|
|
|
|
let w = team.players().prefix(6).map({ $0.computedRank }).reduce(0,+) |
|
|
|
|
print(team.teamLabel(), w, team.weight) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} header: { |
|
|
|
|
if filterMode == .all && walkoutTeams.isEmpty == false { |
|
|
|
|
@ -739,15 +741,15 @@ struct InscriptionManagerView: View { |
|
|
|
|
private func _teamCountForFilterMode(filterMode: FilterMode) -> String { |
|
|
|
|
switch filterMode { |
|
|
|
|
case .wildcardBracket: |
|
|
|
|
return tournament.selectedSortedTeams().filter({ $0.wildCardBracket }).count.formatted() |
|
|
|
|
return selectedSortedTeams.filter({ $0.wildCardBracket }).count.formatted() |
|
|
|
|
case .wildcardGroupStage: |
|
|
|
|
return tournament.selectedSortedTeams().filter({ $0.wildCardGroupStage }).count.formatted() |
|
|
|
|
return selectedSortedTeams.filter({ $0.wildCardGroupStage }).count.formatted() |
|
|
|
|
case .all: |
|
|
|
|
return unsortedTeamsWithoutWO.count.formatted() |
|
|
|
|
case .bracket: |
|
|
|
|
return tournament.selectedSortedTeams().filter({ $0.inRound() && $0.inGroupStage() == false }).count.formatted() |
|
|
|
|
return selectedSortedTeams.filter({ $0.inRound() && $0.inGroupStage() == false }).count.formatted() |
|
|
|
|
case .groupStage: |
|
|
|
|
return tournament.selectedSortedTeams().filter({ $0.inGroupStage() }).count.formatted() |
|
|
|
|
return selectedSortedTeams.filter({ $0.inGroupStage() }).count.formatted() |
|
|
|
|
case .walkOut: |
|
|
|
|
let wo = walkoutTeams.count.formatted() |
|
|
|
|
return wo |
|
|
|
|
@ -878,26 +880,43 @@ struct InscriptionManagerView: View { |
|
|
|
|
gatheringInProgress = true |
|
|
|
|
gathered = 0 |
|
|
|
|
gatheringDone = false |
|
|
|
|
let unrankedUnsourced = tournament.players().filter({ $0.isUnranked() && $0.source == nil }) |
|
|
|
|
let unrankedUnsourced = tournament.players().filter { $0.isUnranked() && $0.source == nil } |
|
|
|
|
totalUnrankedUnsourced = Double(unrankedUnsourced.count) |
|
|
|
|
print("total", unrankedUnsourced.count) |
|
|
|
|
for player in unrankedUnsourced { |
|
|
|
|
do { |
|
|
|
|
if let playerData = try await player.fetchUnrankPlayerData() { |
|
|
|
|
player.lastName = playerData.nom |
|
|
|
|
player.birthdate = playerData.dateNaissanceFr |
|
|
|
|
player.clubCode = playerData.codeClub |
|
|
|
|
player.source = .frenchFederation |
|
|
|
|
try tournamentStore.playerRegistrations.addOrUpdate(instance: player) |
|
|
|
|
|
|
|
|
|
await withTaskGroup(of: Void.self) { group in |
|
|
|
|
var playersToSave = [PlayerRegistration]() |
|
|
|
|
for player in unrankedUnsourced { |
|
|
|
|
group.addTask { |
|
|
|
|
do { |
|
|
|
|
if let playerData = try await player.fetchUnrankPlayerData() { |
|
|
|
|
player.lastName = playerData.nom |
|
|
|
|
player.birthdate = playerData.dateNaissanceFr |
|
|
|
|
player.clubCode = playerData.codeClub |
|
|
|
|
player.source = .frenchFederation |
|
|
|
|
playersToSave.append(player) |
|
|
|
|
} |
|
|
|
|
await MainActor.run { |
|
|
|
|
gathered += 1 |
|
|
|
|
print("gathered", gathered) |
|
|
|
|
} |
|
|
|
|
} catch { |
|
|
|
|
print("Error fetching data for player \(player):", error) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
gathered += 1 |
|
|
|
|
print("gathered", gathered) |
|
|
|
|
|
|
|
|
|
} catch { |
|
|
|
|
print(error) |
|
|
|
|
|
|
|
|
|
do { |
|
|
|
|
try tournamentStore.playerRegistrations.addOrUpdate(contentOfs: playersToSave) |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Wait for all tasks to complete |
|
|
|
|
await group.waitForAll() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
gatheringDone = true |
|
|
|
|
gatheringInProgress = false |
|
|
|
|
} |
|
|
|
|
|