From e064dc88e9ae24cbc983e5154f706185ac0bab4d Mon Sep 17 00:00:00 2001 From: Razmig Sarkissian Date: Sat, 11 May 2024 10:10:31 +0200 Subject: [PATCH] update toolbox for json to csv convert and grammar --- PadelClub/Data/Federal/FederalPlayer.swift | 26 ++++++++++++++++--- .../Navigation/Toolbox/ToolboxView.swift | 2 +- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/PadelClub/Data/Federal/FederalPlayer.swift b/PadelClub/Data/Federal/FederalPlayer.swift index 059f7aa..fde88d1 100644 --- a/PadelClub/Data/Federal/FederalPlayer.swift +++ b/PadelClub/Data/Federal/FederalPlayer.swift @@ -82,13 +82,33 @@ struct FederalPlayer: Decodable { } func exportToCSV() -> String { - let pointsString = points != nil ? Int(points!).formatted() : "" - let tournamentCountString = tournamentCount != nil ? tournamentCount!.formatted() : "" + let pointsString = points != nil ? String(Int(points!)) : "" + let tournamentCountString = tournamentCount != nil ? String(tournamentCount!) : "" let strippedLicense = license.strippedLicense ?? "" - let line = ";\(rank);\(lastName);\(firstName);\(country);\(strippedLicense);\(pointsString);\(assimilation);\(tournamentCountString);\(ligue);\(clubCode);\(club);" + let line = ";\(rank);\(lastName);\(firstName);\(country);\(strippedLicense);\(pointsString);\(assimilation);\(tournamentCountString);\(ligue);\(formatNumbers(clubCode));\(club);" return line } + func formatNumbers(_ input: String) -> String { + // Insert spaces at appropriate positions + let formattedString = insertSeparator(input, separator: " ", every: [2, 4]) + return formattedString + } + + func insertSeparator(_ input: String, separator: String, every positions: [Int]) -> String { + var modifiedString = input + // Adjust for the index shift caused by inserting characters + var offset = 0 + // Insert separator at specified positions + for position in positions { + let index = modifiedString.index(modifiedString.startIndex, offsetBy: position + offset) + modifiedString.insert(contentsOf: separator, at: index) + // Increase offset to adjust for the inserted character + offset += separator.count + } + return modifiedString + } + var fullNameCanonical: String /* diff --git a/PadelClub/Views/Navigation/Toolbox/ToolboxView.swift b/PadelClub/Views/Navigation/Toolbox/ToolboxView.swift index 3e110e0..91cf3cc 100644 --- a/PadelClub/Views/Navigation/Toolbox/ToolboxView.swift +++ b/PadelClub/Views/Navigation/Toolbox/ToolboxView.swift @@ -42,7 +42,7 @@ struct ToolboxView: View { Label("Définir les durées moyennes", systemImage: "deskclock") } } footer: { - Text("Vous pouvez définir vos propores estimations de durées de match en fonction du format de jeu.") + Text("Vous pouvez définir vos propres estimations de durées de match en fonction du format de jeu.") } } .navigationTitle(TabDestination.toolbox.title)