update toolbox for json to csv convert and grammar

multistore
Razmig Sarkissian 2 years ago
parent f417a084b9
commit e064dc88e9
  1. 26
      PadelClub/Data/Federal/FederalPlayer.swift
  2. 2
      PadelClub/Views/Navigation/Toolbox/ToolboxView.swift

@ -82,13 +82,33 @@ struct FederalPlayer: Decodable {
} }
func exportToCSV() -> String { func exportToCSV() -> String {
let pointsString = points != nil ? Int(points!).formatted() : "" let pointsString = points != nil ? String(Int(points!)) : ""
let tournamentCountString = tournamentCount != nil ? tournamentCount!.formatted() : "" let tournamentCountString = tournamentCount != nil ? String(tournamentCount!) : ""
let strippedLicense = license.strippedLicense ?? "" 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 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 var fullNameCanonical: String
/* /*

@ -42,7 +42,7 @@ struct ToolboxView: View {
Label("Définir les durées moyennes", systemImage: "deskclock") Label("Définir les durées moyennes", systemImage: "deskclock")
} }
} footer: { } 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) .navigationTitle(TabDestination.toolbox.title)

Loading…
Cancel
Save