wip fix slow

paca_championship
Raz 10 months ago
parent 28a0536248
commit a6b4b46afa
  1. 8
      PadelClub/Data/GroupStage.swift
  2. 8
      PadelClub/Data/Match.swift
  3. 24
      PadelClub/Data/Round.swift
  4. 53
      PadelClub/Data/Tournament.swift
  5. 2
      PadelClub/Views/Navigation/Umpire/PadelClubView.swift
  6. 2
      PadelClub/Views/Round/LoserRoundView.swift
  7. 10
      PadelClub/Views/Round/LoserRoundsView.swift
  8. 9
      PadelClub/Views/Team/Components/TeamWeightView.swift
  9. 3
      PadelClub/Views/Team/TeamRowView.swift
  10. 107
      PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift

@ -301,7 +301,7 @@ final class GroupStage: ModelObject, Storable {
}
func availableToStart(playedMatches: [Match], in runningMatches: [Match], checkCanPlay: Bool = true) -> [Match] {
#if _DEBUG_TIME //DEBUGING TIME
#if DEBUG //DEBUGING TIME
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)
@ -312,7 +312,7 @@ final class GroupStage: ModelObject, Storable {
}
func runningMatches(playedMatches: [Match]) -> [Match] {
#if _DEBUG_TIME //DEBUGING TIME
#if DEBUG //DEBUGING TIME
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)
@ -323,7 +323,7 @@ final class GroupStage: ModelObject, Storable {
}
func readyMatches(playedMatches: [Match]) -> [Match] {
#if _DEBUG_TIME //DEBUGING TIME
#if DEBUG //DEBUGING TIME
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)
@ -334,7 +334,7 @@ final class GroupStage: ModelObject, Storable {
}
func finishedMatches(playedMatches: [Match]) -> [Match] {
#if _DEBUG_TIME //DEBUGING TIME
#if DEBUG //DEBUGING TIME
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)

@ -108,7 +108,7 @@ final class Match: ModelObject, Storable, Equatable {
}
func indexInRound(in matches: [Match]? = nil) -> Int {
#if _DEBUG_TIME //DEBUGING TIME
#if DEBUG //DEBUGING TIME
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)
@ -132,7 +132,7 @@ defer {
}
func matchTitle(_ displayStyle: DisplayStyle = .wide, inMatches matches: [Match]? = nil) -> String {
#if _DEBUG_TIME //DEBUGING TIME
#if DEBUG //DEBUGING TIME
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)
@ -808,7 +808,7 @@ defer {
}
func teams() -> [TeamRegistration] {
#if _DEBUG_TIME //DEBUGING TIME
#if DEBUG //DEBUGING TIME
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)
@ -883,7 +883,7 @@ defer {
}
func team(_ team: TeamPosition) -> TeamRegistration? {
#if _DEBUG_TIME //DEBUGING TIME
#if DEBUG //DEBUGING TIME
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)

@ -175,7 +175,7 @@ final class Round: ModelObject, Storable {
}
func roundProjectedTeam(_ team: TeamPosition, inMatch match: Match, previousRound: Round?) -> TeamRegistration? {
#if _DEBUG_TIME //DEBUGING TIME
#if DEBUG //DEBUGING TIME
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)
@ -217,7 +217,7 @@ defer {
}
func upperBracketTopMatch(ofMatchIndex matchIndex: Int, previousRound: Round?) -> Match? {
#if _DEBUG_TIME //DEBUGING TIME
#if DEBUG //DEBUGING TIME
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)
@ -237,7 +237,7 @@ defer {
}
func upperBracketBottomMatch(ofMatchIndex matchIndex: Int, previousRound: Round?) -> Match? {
#if _DEBUG_TIME //DEBUGING TIME
#if DEBUG //DEBUGING TIME
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)
@ -259,7 +259,7 @@ defer {
func topPreviousRoundMatch(ofMatch match: Match, previousRound: Round?) -> Match? {
#if _DEBUG_TIME //DEBUGING TIME
#if DEBUG //DEBUGING TIME
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)
@ -275,7 +275,7 @@ defer {
}
func bottomPreviousRoundMatch(ofMatch match: Match, previousRound: Round?) -> Match? {
#if _DEBUG_TIME //DEBUGING TIME
#if DEBUG //DEBUGING TIME
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)
@ -302,7 +302,7 @@ defer {
}
// func displayableMatches() -> [Match] {
//#if _DEBUG_TIME //DEBUGING TIME
//#if DEBUG //DEBUGING TIME
// let start = Date()
// defer {
// let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)
@ -328,7 +328,7 @@ defer {
}
func previousRound() -> Round? {
#if _DEBUG_TIME //DEBUGING TIME
#if DEBUG //DEBUGING TIME
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)
@ -462,7 +462,7 @@ defer {
func correspondingLoserRoundTitle(_ displayStyle: DisplayStyle = .wide) -> String {
if let _cachedSeedInterval { return _cachedSeedInterval.localizedLabel(displayStyle) }
#if _DEBUG_TIME //DEBUGING TIME
#if DEBUG //DEBUGING TIME
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)
@ -513,7 +513,7 @@ defer {
func seedInterval(initialMode: Bool = false) -> SeedInterval? {
if initialMode == false, let _cachedSeedInterval { return _cachedSeedInterval }
#if _DEBUG_TIME //DEBUGING TIME
#if DEBUG //DEBUGING TIME
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)
@ -607,7 +607,7 @@ defer {
func loserRounds() -> [Round] {
#if _DEBUG_TIME //DEBUGING TIME
#if DEBUG //DEBUGING TIME
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)
@ -801,7 +801,7 @@ extension Round: Selectable, Equatable {
}
func badgeValue() -> Int? {
#if _DEBUG_TIME //DEBUGING TIME
#if DEBUG //DEBUGING TIME
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)
@ -822,7 +822,7 @@ extension Round: Selectable, Equatable {
}
func badgeImage() -> Badge? {
#if _DEBUG_TIME //DEBUGING TIME
#if DEBUG //DEBUGING TIME
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)

@ -430,6 +430,14 @@ final class Tournament : ModelObject, Storable {
// MARK: - Computed Dependencies
func unsortedTeams() -> [TeamRegistration] {
#if DEBUG //DEBUGING TIME
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)
print("func tournament unsortedTeams", duration.formatted(.units(allowed: [.seconds, .milliseconds])))
}
#endif
return Array(self.tournamentStore.teamRegistrations)
}
@ -748,7 +756,7 @@ defer {
}
func availableSeeds() -> [TeamRegistration] {
#if _DEBUG_TIME //DEBUGING TIME
#if DEBUG //DEBUGING TIME
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)
@ -985,7 +993,7 @@ defer {
func selectedSortedTeams() -> [TeamRegistration] {
#if _DEBUG_TIME //DEBUGING TIME
#if DEBUG //DEBUGING TIME
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)
@ -1092,11 +1100,28 @@ defer {
}
func unsortedTeamsWithoutWO() -> [TeamRegistration] {
#if DEBUG //DEBUGING TIME
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)
print("func unsortedTeamsWithoutWO", id, tournamentTitle(), duration.formatted(.units(allowed: [.seconds, .milliseconds])))
}
#endif
return self.tournamentStore.teamRegistrations.filter { $0.isOutOfTournament() == false }
// return Store.main.filter { $0.tournament == self.id && $0.walkOut == false }
}
func walkoutTeams() -> [TeamRegistration] {
#if DEBUG //DEBUGING TIME
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)
print("func walkoutTeams", id, tournamentTitle(), duration.formatted(.units(allowed: [.seconds, .milliseconds])))
}
#endif
return self.tournamentStore.teamRegistrations.filter { $0.walkOut == true }
// return Store.main.filter { $0.tournament == self.id && $0.walkOut == true }
}
@ -1117,6 +1142,14 @@ defer {
}
func unsortedPlayers() -> [PlayerRegistration] {
#if DEBUG //DEBUGING TIME
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)
print("func unsortedPlayers", id, tournamentTitle(), duration.formatted(.units(allowed: [.seconds, .milliseconds])))
}
#endif
return Array(self.tournamentStore.playerRegistrations)
}
@ -1282,6 +1315,8 @@ defer {
}
func registrationIssues() async -> Int {
return 0
let players : [PlayerRegistration] = unsortedPlayers()
let selectedTeams : [TeamRegistration] = selectedSortedTeams()
let callDateIssue : [TeamRegistration] = selectedTeams.filter { $0.callDate != nil && isStartDateIsDifferentThanCallDate($0) }
@ -1319,7 +1354,7 @@ defer {
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)
print("func tournament availableToStart", id, duration.formatted(.units(allowed: [.seconds, .milliseconds])))
print("func tournament availableToStart", duration.formatted(.units(allowed: [.seconds, .milliseconds])))
}
#endif
return allMatches.filter({ $0.isRunning() == false && $0.canBeStarted(inMatches: runningMatches, checkCanPlay: checkCanPlay) }).sorted(using: defaultSorting, order: .ascending)
@ -1330,7 +1365,7 @@ defer {
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)
print("func tournament runningMatches", id, duration.formatted(.units(allowed: [.seconds, .milliseconds])))
print("func tournament runningMatches", duration.formatted(.units(allowed: [.seconds, .milliseconds])))
}
#endif
return allMatches.filter({ $0.isRunning() && $0.isReady() }).sorted(using: defaultSorting, order: .ascending)
@ -1341,7 +1376,7 @@ defer {
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)
print("func tournament readyMatches", id, duration.formatted(.units(allowed: [.seconds, .milliseconds])))
print("func tournament readyMatches", duration.formatted(.units(allowed: [.seconds, .milliseconds])))
}
#endif
return allMatches.filter({ $0.isReady() && $0.isRunning() == false && $0.hasEnded() == false }).sorted(using: defaultSorting, order: .ascending)
@ -1352,7 +1387,7 @@ defer {
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)
print("func tournament readyMatches", id, duration.formatted(.units(allowed: [.seconds, .milliseconds])))
print("func tournament readyMatches", duration.formatted(.units(allowed: [.seconds, .milliseconds])))
}
#endif
return allMatches.filter({ $0.isRunning() == false && $0.hasEnded() == false }).sorted(using: defaultSorting, order: .ascending)
@ -1360,11 +1395,11 @@ defer {
static func finishedMatches(_ allMatches: [Match], limit: Int?) -> [Match] {
#if _DEBUG_TIME //DEBUGING TIME
#if DEBUG //DEBUGING TIME
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)
print("func tournament finishedMatches", id, duration.formatted(.units(allowed: [.seconds, .milliseconds])))
print("func tournament finishedMatches", duration.formatted(.units(allowed: [.seconds, .milliseconds])))
}
#endif
if let limit {
@ -1685,7 +1720,7 @@ defer {
func availableQualifiedTeams() -> [TeamRegistration] {
#if _DEBUG_TIME //DEBUGING TIME
#if DEBUG //DEBUGING TIME
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)

@ -269,7 +269,7 @@ func fetchPlayerData(for licenseID: String) async throws -> [Player]? {
request.setValue("XMLHttpRequest", forHTTPHeaderField: "X-Requested-With")
// Add cookies if needed (example cookie header value shown, replace with valid cookies)
request.setValue("JSESSIONID=DB3022D6D4C26667F90F974DEF0839D9; AWSALB=LEi0K3Uo1nILtAPwiQlDKHLVbGLlB6i53kPkmiqt3F5ZjsJ9GmJ+HIF68KASM0cOkvZy1xVBlBvPDXV5b8M/v1agy5zM8FQTDzU7RDSoAjWa8/r2TnYG945lFfyH; AWSALBCORS=LEi0K3Uo1nILtAPwiQlDKHLVbGLlB6i53kPkmiqt3F5ZjsJ9GmJ+HIF68KASM0cOkvZy1xVBlBvPDXV5b8M/v1agy5zM8FQTDzU7RDSoAjWa8/r2TnYG945lFfyH; datadome=Pu2quQW9IroVbvV3nzzbzlUlblZ0tWxdKTa~hJ6xJMZF5XsUWe0BOmUwt046PDc6YKJGmK4EpBmHHGzftQFYWpVSUpsVqFdNLBelUhW_BqvcD3vyatOwSrTo0kAUOVd3; tc_cj_v2=%5Ecl_%5Dny%5B%5D%5D_mmZZZZZZKQMMORPMMMQNNZZZ%5D777m_iZZZ%22**%22%27%20ZZZKQMMQMPMPMKOPZZZ%5D777%5Ecl_%5Dny%5B%5D%5D_mmZZZZZZKQMNNOOQOJPKJZZZ%5D; tc_cj_v2_cmp=; tc_cj_v2_med=; xtan=-; xtant=1; tCdebugLib=1; _pcid=%7B%22browserId%22%3A%22m42mi4kbtfuyj367%22%2C%22_t%22%3A%22mjr1fm32%7Cm42mi4r2%22%7D; _pctx=%7Bu%7DN4IgrgzgpgThIC4B2YA2qA05owMoBcBDfSREQpAeyRCwgEt8oBJAE0RXSwH18yBbAFYwAjADN%2BAZgCsAH34AWAEz96CmNJABfIA; _pprv=eyJjb25zZW50Ijp7IjAiOnsibW9kZSI6ImVzc2VudGlhbCJ9LCI3Ijp7Im1vZGUiOiJvcHQtaW4ifX0sInB1cnBvc2VzIjpudWxsLCJfdCI6Im1qcjFmbHdofG00Mm1pNGtoIn0%3D; TCID=124122155494907703483; TCPID=124115115191501043230; xtvrn=$548419$; visid_incap_2712217=PSfJngzoSuiowsuXXhvOu5K+7mUAAAAAQUIPAAAAAAAleL9ldvN/FC1VykkU9ret; SessionStatId=10.91.140.42.1662124965429001", forHTTPHeaderField: "Cookie")
request.setValue("JSESSIONID=3F3FA6B65006ECB82BDE13DC967F9A69; AWSALB=02TQyp76WCX9Mb3T9gn2jXRsiW87dAa7BVK+2QrO1PBeZoMqRSRkLP57oIUBb8ZXX+1/V2SbQxS7DccXJ7ltAM0uH2QJJ6ozkHAoLHGhoIwenc45xGb8xhl7NQnM; AWSALBCORS=02TQyp76WCX9Mb3T9gn2jXRsiW87dAa7BVK+2QrO1PBeZoMqRSRkLP57oIUBb8ZXX+1/V2SbQxS7DccXJ7ltAM0uH2QJJ6ozkHAoLHGhoIwenc45xGb8xhl7NQnM; tc_cj_v2=%5Ecl_%5Dny%5B%5D%5D_mmZZZZZZKQMMORPMMMQNNZZZ%5D777m_iZZZ%22**%22%27%20ZZZKQMMQMPMPMKOPZZZ%5D777%5Ecl_%5Dny%5B%5D%5D_mmZZZZZZKQMONRLNRJRKPZZZ%5D; tc_cj_v2_cmp=; tc_cj_v2_med=; datadome=IqayPD8CsX1wdn7WEztZm0WkmQI5kUoY7BoHwRUdn0yoaKCy9io9E2EWvwVCCpYjMQKcJP9fjl_8QbqneO91bMACS89SQS5pG8u42ZPKuZO9FQTVq95INQBXJREO3Ksm; xtan=-; xtant=1; TCSESSION=12412015254641319805; incap_ses_1176_2712217=vdDULxWxfWqmwMCR8/1REL1bcWcAAAAApBZ9vm58pHhX5W6KOdLwAA==; nlbi_2712217=sIdMLO/23jYzlS3Ib9lUTgAAAAA35MukHyQ4MRuJCVxhdpk9; tCdebugLib=1; _pcid=%7B%22browserId%22%3A%22m42mi4kbtfuyj367%22%2C%22_t%22%3A%22mjr1fm32%7Cm42mi4r2%22%7D; _pctx=%7Bu%7DN4IgrgzgpgThIC4B2YA2qA05owMoBcBDfSREQpAeyRCwgEt8oBJAE0RXSwH18yBbAFYwAjADN%2BAZgCsAH34AWAEz96CmNJABfIA; _pprv=eyJjb25zZW50Ijp7IjAiOnsibW9kZSI6ImVzc2VudGlhbCJ9LCI3Ijp7Im1vZGUiOiJvcHQtaW4ifX0sInB1cnBvc2VzIjpudWxsLCJfdCI6Im1qcjFmbHdofG00Mm1pNGtoIn0%3D; TCID=124122155494907703483; TCPID=124115115191501043230; xtvrn=$548419$; visid_incap_2712217=PSfJngzoSuiowsuXXhvOu5K+7mUAAAAAQUIPAAAAAAAleL9ldvN/FC1VykkU9ret; SessionStatId=10.91.140.42.1662124965429001", forHTTPHeaderField: "Cookie")
let (data, _) = try await URLSession.shared.data(for: request)
let decoder = JSONDecoder()

@ -15,7 +15,7 @@ struct LoserRoundView: View {
let loserBracket: LoserRound
private func _roundDisabled() -> Bool {
#if _DEBUG_TIME //DEBUGING TIME
#if DEBUG //DEBUGING TIME
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)

@ -42,7 +42,7 @@ extension UpperRound: Equatable {
}
func badgeValue() -> Int? {
#if _DEBUG_TIME //DEBUGING TIME
#if DEBUG //DEBUGING TIME
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)
@ -57,7 +57,7 @@ extension UpperRound: Equatable {
}
func badgeImage() -> Badge? {
#if _DEBUG_TIME //DEBUGING TIME
#if DEBUG //DEBUGING TIME
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)
@ -85,7 +85,7 @@ struct LoserRound: Identifiable, Selectable {
}
var shouldBeDisplayed: Bool {
#if _DEBUG_TIME //DEBUGING TIME
#if DEBUG //DEBUGING TIME
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)
@ -97,7 +97,7 @@ struct LoserRound: Identifiable, Selectable {
}
static func updateDestinations(fromLoserRounds loserRounds: [Round], inUpperBracketRound upperBracketRound: Round) -> [LoserRound] {
#if _DEBUG_TIME //DEBUGING TIME
#if DEBUG //DEBUGING TIME
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)
@ -146,7 +146,7 @@ extension LoserRound: Equatable {
}
func badgeImage() -> Badge? {
#if _DEBUG_TIME //DEBUGING TIME
#if DEBUG //DEBUGING TIME
let start = Date()
defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)

@ -11,9 +11,10 @@ struct TeamWeightView: View {
@EnvironmentObject var dataStore: DataStore
let team: TeamRegistration
var teamPosition: TeamPosition? = nil
var teamIndex: Int?
var teamIndex: Int? {
team.tournamentObject()?.indexOf(team: team)
private var _teamIndex: Int? {
teamIndex ?? team.tournamentObject()?.indexOf(team: team)
}
var displayWeight: Bool {
@ -27,8 +28,8 @@ struct TeamWeightView: View {
.monospacedDigit()
.font(.caption)
}
if let teamIndex {
Text("#" + (teamIndex + 1).formatted(.number.precision(.integerLength(2...3))))
if let _teamIndex {
Text("#" + (_teamIndex + 1).formatted(.number.precision(.integerLength(2...3))))
.monospacedDigit()
}
if teamPosition == .two && displayWeight {

@ -10,13 +10,14 @@ import SwiftUI
struct TeamRowView: View {
@EnvironmentObject var dataStore: DataStore
var team: TeamRegistration
var teamIndex: Int?
var teamPosition: TeamPosition? = nil
var displayCallDate: Bool = false
var displayRestingTime: Bool = false
var body: some View {
LabeledContent {
TeamWeightView(team: team, teamPosition: teamPosition)
TeamWeightView(team: team, teamPosition: teamPosition, teamIndex: teamIndex)
} label: {
VStack(alignment: .leading) {
TeamHeadlineView(team: team)

@ -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
}

Loading…
Cancel
Save