From 651461899602f38477572625fe68eb86319955ed Mon Sep 17 00:00:00 2001 From: Razmig Sarkissian Date: Wed, 4 Jun 2025 07:54:40 +0200 Subject: [PATCH 1/3] add a forfait button in team group stage view --- PadelClubData/Data/Match.swift | 10 ++++++++++ PadelClubData/ViewModel/PadelRule.swift | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/PadelClubData/Data/Match.swift b/PadelClubData/Data/Match.swift index ff89c4e..3023515 100644 --- a/PadelClubData/Data/Match.swift +++ b/PadelClubData/Data/Match.swift @@ -509,6 +509,16 @@ defer { updateFollowingMatchTeamScore() } + public func teamPosition(for teamRegistration: TeamRegistration) -> TeamPosition? { + if self.team(.one)?.id == teamRegistration.id { + return .one + } else if self.team(.two)?.id == teamRegistration.id { + return .two + } else { + return nil + } + } + public func setWalkOut(_ teamPosition: TeamPosition) { let teamScoreWalkout = teamScore(teamPosition) ?? TeamScore(match: id, team: team(teamPosition)) teamScoreWalkout.walkOut = 0 diff --git a/PadelClubData/ViewModel/PadelRule.swift b/PadelClubData/ViewModel/PadelRule.swift index 152d23d..8cc6a51 100644 --- a/PadelClubData/ViewModel/PadelRule.swift +++ b/PadelClubData/ViewModel/PadelRule.swift @@ -1273,7 +1273,7 @@ public enum MatchFormat: Int, Hashable, Codable, CaseIterable, Identifiable { self.init(rawValue: value) } - func defaultWalkOutScore(_ asWalkOutTeam: Bool) -> [Int] { + public func defaultWalkOutScore(_ asWalkOutTeam: Bool) -> [Int] { Array(repeating: asWalkOutTeam ? 0 : setFormat.scoreToWin, count: setsToWin) } From e5f7cbfcd1976e693929fcef2e77d8bb20774730 Mon Sep 17 00:00:00 2001 From: Razmig Sarkissian Date: Wed, 4 Jun 2025 09:00:08 +0200 Subject: [PATCH 2/3] add stat view for event / tournament --- PadelClubData/Data/Event.swift | 4 ++++ PadelClubData/Data/PlayerRegistration.swift | 13 ++++++++++++- PadelClubData/Data/Tournament.swift | 9 +++++++++ PadelClubData/ViewModel/Screen.swift | 1 + 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/PadelClubData/Data/Event.swift b/PadelClubData/Data/Event.swift index 15eb2ab..29f3fc6 100644 --- a/PadelClubData/Data/Event.swift +++ b/PadelClubData/Data/Event.swift @@ -100,6 +100,10 @@ final public class Event: BaseEvent { tournaments.filter({ $0.isFree() == false && $0.isCanceled == false && $0.isDeleted == false }) } + public func confirmedTournaments() -> [Tournament] { + tournaments.filter({ $0.isCanceled == false && $0.isDeleted == false }) + } + public func shareURL() -> URL? { return URL(string: URLs.main.url.appending(path: "event/\(id)").absoluteString.removingPercentEncoding!) } diff --git a/PadelClubData/Data/PlayerRegistration.swift b/PadelClubData/Data/PlayerRegistration.swift index 773934b..afc6c4d 100644 --- a/PadelClubData/Data/PlayerRegistration.swift +++ b/PadelClubData/Data/PlayerRegistration.swift @@ -230,7 +230,18 @@ final public class PlayerRegistration: BasePlayerRegistration, SideStorable { return 0.0 } } - + + public func totalIncome(_ tournament: Tournament) -> Double { + if let entryFee = tournament.entryFee { + if clubMember, let clubMemberFeeDeduction = tournament.clubMemberFeeDeduction { + return entryFee - clubMemberFeeDeduction + } else { + return entryFee + } + } else { + return 0.0 + } + } public enum PlayerDataSource: Int, Codable { case frenchFederation = 0 diff --git a/PadelClubData/Data/Tournament.swift b/PadelClubData/Data/Tournament.swift index 6304f72..045bf79 100644 --- a/PadelClubData/Data/Tournament.swift +++ b/PadelClubData/Data/Tournament.swift @@ -1235,6 +1235,15 @@ defer { public func remainingAmount() -> Double { return selectedPlayers().compactMap { $0.remainingAmount(self) }.reduce(0.0, +) } + + public func totalIncome() -> Double { + if let entryFee { + return Double(teamCount) * entryFee * 2.0 + } else { + return 0.0 + } + } + public func paidCompletion() -> Double { let selectedPlayers = selectedPlayers() diff --git a/PadelClubData/ViewModel/Screen.swift b/PadelClubData/ViewModel/Screen.swift index 251ac6b..bb53ac7 100644 --- a/PadelClubData/ViewModel/Screen.swift +++ b/PadelClubData/ViewModel/Screen.swift @@ -23,4 +23,5 @@ public enum Screen: String, Codable { case share case restingTime case stateSettings + case statistics } From fae2e79207b47c8501d20dbac1dd5caadfc96f05 Mon Sep 17 00:00:00 2001 From: Razmig Sarkissian Date: Sun, 8 Jun 2025 16:40:24 +0200 Subject: [PATCH 3/3] fix issue with groupstage start date --- PadelClubData/Data/GroupStage.swift | 4 ++++ PadelClubData/Data/MatchScheduler.swift | 3 +++ 2 files changed, 7 insertions(+) diff --git a/PadelClubData/Data/GroupStage.swift b/PadelClubData/Data/GroupStage.swift index 414322a..23a597d 100644 --- a/PadelClubData/Data/GroupStage.swift +++ b/PadelClubData/Data/GroupStage.swift @@ -606,6 +606,10 @@ final public class GroupStage: BaseGroupStage, SideStorable { guard hasEnded() else { return nil } return teams(true).firstIndex(of: team) } + + public func computedStartDate() -> Date? { + return _matches().sorted(by: \.computedStartDateForSorting).first?.startDate + } public override func deleteDependencies(store: Store, shouldBeSynchronized: Bool) { diff --git a/PadelClubData/Data/MatchScheduler.swift b/PadelClubData/Data/MatchScheduler.swift index a5e5ee7..8999fa0 100644 --- a/PadelClubData/Data/MatchScheduler.swift +++ b/PadelClubData/Data/MatchScheduler.swift @@ -131,6 +131,9 @@ final public class MatchScheduler: BaseMatchScheduler, SideStorable { } catch { Logger.error(error) } + + groupStages.forEach({ $0.startDate = $0.computedStartDate() }) + self.tournamentStore?.groupStages.addOrUpdate(contentOfs: groupStages) return lastDate }