|
|
|
|
@ -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 |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|