From 6152c92d9ab9cf4fc0a27a28e5673d76727b23a8 Mon Sep 17 00:00:00 2001 From: Razmig Sarkissian Date: Wed, 22 Oct 2025 09:30:30 +0200 Subject: [PATCH] fix issue with p25 format --- PadelClubData/Data/PlayerRegistration.swift | 2 +- PadelClubData/Data/TeamRegistration.swift | 23 ++++++++++++++++++++- PadelClubData/Data/Tournament.swift | 4 +--- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/PadelClubData/Data/PlayerRegistration.swift b/PadelClubData/Data/PlayerRegistration.swift index 392c6d2..115f7d4 100644 --- a/PadelClubData/Data/PlayerRegistration.swift +++ b/PadelClubData/Data/PlayerRegistration.swift @@ -185,7 +185,7 @@ final public class PlayerRegistration: BasePlayerRegistration, SideStorable { } public func setComputedRank(in tournament: Tournament) { - let maleUnranked = tournament.unrankValue(for: isMalePlayer()) ?? 90_415 + let maleUnranked = tournament.unrankValue(for: isMalePlayer()) ?? 92_327 let femaleUnranked = tournament.unrankValue(for: false) ?? 0 let currentRank = rank ?? maleUnranked switch tournament.tournamentCategory { diff --git a/PadelClubData/Data/TeamRegistration.swift b/PadelClubData/Data/TeamRegistration.swift index 1520187..3f7e9ee 100644 --- a/PadelClubData/Data/TeamRegistration.swift +++ b/PadelClubData/Data/TeamRegistration.swift @@ -551,7 +551,7 @@ final public class TeamRegistration: BaseTeamRegistration, SideStorable { } public func unrankValue(for malePlayer: Bool) -> Int { - return tournamentObject()?.unrankValue(for: malePlayer) ?? 90_415 + return tournamentObject()?.unrankValue(for: malePlayer) ?? 92_327 } public func groupStageObject() -> GroupStage? { @@ -697,6 +697,27 @@ final public class TeamRegistration: BaseTeamRegistration, SideStorable { }) return matches.sorted(by: \.computedStartDateForSorting) } + + public func nextMatch(in followingMatches: [Match]) -> Match? { + return followingMatches.filter({ $0.hasEnded() == false }).first + } + + public func lastMatchPlayed(in followingMatches: [Match]) -> Match? { + return followingMatches.first(where: { $0.hasEnded() }) + } + + public func numberOfRotation(in followingMatches: [Match]) -> (Int, Int)? { + if let nextMatch = nextMatch(in: followingMatches), let nextMatchPlannedStartDate = nextMatch.plannedStartDate, let lastMatchPlayed = lastMatchPlayed(in: followingMatches), let lastMatchPlayedPlannedStartDate = lastMatchPlayed.plannedStartDate { + + let courtCount = self.tournamentStore?.matches.filter({ $0.plannedStartDate == nextMatchPlannedStartDate && $0.disabled == false && $0.hasEnded() == false && $0.confirmed == true && $0.id != nextMatch.id && $0.hasStarted() == false }).count ?? 0 + let interval = nextMatchPlannedStartDate.timeIntervalSince(lastMatchPlayedPlannedStartDate) + let matchDuration = lastMatchPlayed.matchFormat.defaultEstimatedDuration * 60 + let rotation = Int(interval) / matchDuration + print("numberOfRotation", interval, matchDuration, courtCount, rotation) + return (rotation, (rotation - 1) * lastMatchPlayed.courtCount() + courtCount + 1) + } + return nil + } func insertOnServer() { self.tournamentStore?.teamRegistrations.writeChangeAndInsertOnServer(instance: self) diff --git a/PadelClubData/Data/Tournament.swift b/PadelClubData/Data/Tournament.swift index ad2446c..d1ea740 100644 --- a/PadelClubData/Data/Tournament.swift +++ b/PadelClubData/Data/Tournament.swift @@ -1472,7 +1472,7 @@ defer { var _groupStages = [GroupStage]() for index in 0.. MatchFormat { let format = tournamentLevel.federalFormatForGroupStage() - if tournamentLevel == .p25 { return .superTie } if format.rank < groupStageMatchFormat.rank { return format } else { @@ -1858,7 +1857,6 @@ defer { public func roundSmartMatchFormat(_ roundIndex: Int) -> MatchFormat { let format = tournamentLevel.federalFormatForBracketRound(roundIndex) - if tournamentLevel == .p25 { return .superTie } if format.rank < matchFormat.rank { return format } else {