added ColumnRepresentable to serve as basis for various exports

master
Laurent 6 years ago
parent 782450c10e
commit 262b68edb7
  1. 20
      TournamentStats.xcodeproj/project.pbxproj
  2. 22
      TournamentStats/UI/reports/InfographyView.swift
  3. 38
      TournamentStats/report/structures/CountryCounter.swift
  4. 47
      TournamentStats/report/structures/CumulatedResults.swift
  5. 25
      TournamentStats/report/structures/PlayerResult.swift
  6. 31
      TournamentStats/report/structures/TournamentCounter.swift
  7. 36
      TournamentStats/report/structures/TournamentRepresentable.swift
  8. 8
      TournamentStats/report/structures/TournamentStats.swift
  9. 34
      TournamentStats/report/structures/TournamentWinner.swift
  10. 65
      TournamentStats/utils/ColumnRepresentable.swift

@ -36,6 +36,7 @@
4D2F1C5B22CC92D1007C639E /* event84 in Resources */ = {isa = PBXBuildFile; fileRef = 4D2F1C4322CC92D1007C639E /* event84 */; };
4D30463322F4232600DA86C4 /* event57 in Resources */ = {isa = PBXBuildFile; fileRef = 4D30463122F4232600DA86C4 /* event57 */; };
4D30463422F4232600DA86C4 /* event78 in Resources */ = {isa = PBXBuildFile; fileRef = 4D30463222F4232600DA86C4 /* event78 */; };
4D39B6F122F829A500625E31 /* InfographyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D39B6F022F829A500625E31 /* InfographyView.swift */; };
4DA5CA1E22AD078A00AC628E /* CountryCounter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DA5CA1D22AD078A00AC628E /* CountryCounter.swift */; };
4DDEF11422AE4FB900F4D7C1 /* TournamentStats.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DDEF11322AE4FB900F4D7C1 /* TournamentStats.swift */; };
4DF7608422A3FB96004B0EF1 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DF7608322A3FB96004B0EF1 /* AppDelegate.swift */; };
@ -55,7 +56,7 @@
4DF760BA22A524F4004B0EF1 /* Formatters.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DF760B922A524F4004B0EF1 /* Formatters.swift */; };
4DF760BC22A5270E004B0EF1 /* Queries.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DF760BB22A5270E004B0EF1 /* Queries.swift */; };
4DF760BF22A560AA004B0EF1 /* FileWriter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DF760BE22A560AA004B0EF1 /* FileWriter.swift */; };
4DF760C222A561FF004B0EF1 /* CSVUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DF760C122A561FF004B0EF1 /* CSVUtils.swift */; };
4DF760C222A561FF004B0EF1 /* ColumnRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DF760C122A561FF004B0EF1 /* ColumnRepresentable.swift */; };
4DF760C522A56451004B0EF1 /* event1 in Resources */ = {isa = PBXBuildFile; fileRef = 4DF760C422A56451004B0EF1 /* event1 */; };
4DF760C922A56497004B0EF1 /* Seed.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DF760C822A56497004B0EF1 /* Seed.swift */; };
4DF760CB22A56765004B0EF1 /* event4 in Resources */ = {isa = PBXBuildFile; fileRef = 4DF760CA22A56765004B0EF1 /* event4 */; };
@ -167,6 +168,7 @@
4D2F1C4322CC92D1007C639E /* event84 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = event84; sourceTree = "<group>"; };
4D30463122F4232600DA86C4 /* event57 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = event57; sourceTree = "<group>"; };
4D30463222F4232600DA86C4 /* event78 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = event78; sourceTree = "<group>"; };
4D39B6F022F829A500625E31 /* InfographyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfographyView.swift; sourceTree = "<group>"; };
4DA5CA1D22AD078A00AC628E /* CountryCounter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CountryCounter.swift; sourceTree = "<group>"; };
4DDEF11322AE4FB900F4D7C1 /* TournamentStats.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TournamentStats.swift; sourceTree = "<group>"; };
4DF7608022A3FB96004B0EF1 /* TournamentStats.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TournamentStats.app; sourceTree = BUILT_PRODUCTS_DIR; };
@ -190,7 +192,7 @@
4DF760B922A524F4004B0EF1 /* Formatters.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Formatters.swift; sourceTree = "<group>"; };
4DF760BB22A5270E004B0EF1 /* Queries.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Queries.swift; sourceTree = "<group>"; };
4DF760BE22A560AA004B0EF1 /* FileWriter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileWriter.swift; sourceTree = "<group>"; };
4DF760C122A561FF004B0EF1 /* CSVUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CSVUtils.swift; sourceTree = "<group>"; };
4DF760C122A561FF004B0EF1 /* ColumnRepresentable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColumnRepresentable.swift; sourceTree = "<group>"; };
4DF760C422A56451004B0EF1 /* event1 */ = {isa = PBXFileReference; lastKnownFileType = text; path = event1; sourceTree = "<group>"; };
4DF760C822A56497004B0EF1 /* Seed.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Seed.swift; sourceTree = "<group>"; };
4DF760CA22A56765004B0EF1 /* event4 */ = {isa = PBXFileReference; lastKnownFileType = text; path = event4; sourceTree = "<group>"; };
@ -282,6 +284,14 @@
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
4D97941222F827A5004A2D7F /* reports */ = {
isa = PBXGroup;
children = (
4D39B6F022F829A500625E31 /* InfographyView.swift */,
);
path = reports;
sourceTree = "<group>";
};
4DF7607722A3FB96004B0EF1 = {
isa = PBXGroup;
children = (
@ -458,6 +468,7 @@
4DF760C022A561A8004B0EF1 /* UI */ = {
isa = PBXGroup;
children = (
4D97941222F827A5004A2D7F /* reports */,
4DF7608722A3FB96004B0EF1 /* DetailViewController.swift */,
4DF7608522A3FB96004B0EF1 /* MasterViewController.swift */,
);
@ -467,7 +478,7 @@
4DF760C322A56207004B0EF1 /* utils */ = {
isa = PBXGroup;
children = (
4DF760C122A561FF004B0EF1 /* CSVUtils.swift */,
4DF760C122A561FF004B0EF1 /* ColumnRepresentable.swift */,
4DF760BE22A560AA004B0EF1 /* FileWriter.swift */,
);
path = utils;
@ -713,10 +724,11 @@
buildActionMask = 2147483647;
files = (
4DF7614822A59660004B0EF1 /* ReportGenerator.swift in Sources */,
4DF760C222A561FF004B0EF1 /* CSVUtils.swift in Sources */,
4DF760C222A561FF004B0EF1 /* ColumnRepresentable.swift in Sources */,
4DF760B022A47C74004B0EF1 /* Importer.swift in Sources */,
4DF7614A22A66675004B0EF1 /* TournamentWinner.swift in Sources */,
4D0F103722C4C08F005F797A /* ChipCount.swift in Sources */,
4D39B6F122F829A500625E31 /* InfographyView.swift in Sources */,
4DF760B322A47CAE004B0EF1 /* Realm+Extensions.swift in Sources */,
4DF7608822A3FB96004B0EF1 /* DetailViewController.swift in Sources */,
4DF7615122A7AECA004B0EF1 /* TournamentRepresentable.swift in Sources */,

@ -0,0 +1,22 @@
//
// InfographyView.swift
// TournamentStats
//
// Created by Laurent Morvillier on 05/08/2019.
// Copyright © 2019 Stax River. All rights reserved.
//
import Foundation
import UIKit
class InfographyView : UIView {
override init(frame: CGRect) {
super.init(frame: frame)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

@ -22,16 +22,11 @@ class CountryCounter : HTMLRepresentable {
self.counter += 1
}
static func htmlHeaders() -> String {
var strings: [String] = []
strings.append("Country")
strings.append("Cashes")
let all = strings.joined(separator: "</td><td>")
return "<tr class=\"table-header\"><td>\(all)</td></tr>"
static func headers() -> [String] {
return ["Country", "Cashes"]
}
func html() -> String {
func colums() -> [String] {
let formattedCountry: String
if let flagoji = Locale.current.flagoji(from: self.country) {
formattedCountry = "\(flagoji) \(self.country)"
@ -42,8 +37,31 @@ class CountryCounter : HTMLRepresentable {
var strings: [String] = []
strings.append(formattedCountry)
strings.append("\(counter)")
let all = strings.joined(separator: "</td><td>")
return "<tr><td>\(all)</td></tr>"
return strings
}
// static func htmlHeaders() -> String {
// var strings: [String] = []
// strings.append("Country")
// strings.append("Cashes")
// let all = strings.joined(separator: "</td><td>")
// return "<tr class=\"table-header\"><td>\(all)</td></tr>"
// }
//
// func html() -> String {
//
// let formattedCountry: String
// if let flagoji = Locale.current.flagoji(from: self.country) {
// formattedCountry = "\(flagoji) \(self.country)"
// } else {
// formattedCountry = self.country
// }
//
// var strings: [String] = []
// strings.append(formattedCountry)
// strings.append("\(counter)")
// let all = strings.joined(separator: "</td><td>")
// return "<tr><td>\(all)</td></tr>"
// }
}

@ -8,8 +8,13 @@
import Foundation
class CumulatedResults : HTMLRepresentable, ColumnRepresentable {
class CumulatedResults : HTMLRepresentable {
enum Fields : String, CaseIterable {
case name = "Name"
case earnings = "Total Earnings"
case cashes = "Cashes"
}
var player: Player
var total: Double = 0.0
@ -33,24 +38,32 @@ class CumulatedResults : HTMLRepresentable {
self.results.append(result)
}
static func htmlHeaders() -> String {
var strings: [String] = []
strings.append("Name")
// strings.append("Places (Year)")
strings.append("Total Earnings")
strings.append("Cashes")
let all = strings.joined(separator: "</td><td>")
return "<tr class=\"table-header\"><td>\(all)</td></tr>"
static func headers() -> [String] {
return Fields.allCases.map { $0.rawValue }
}
func html() -> String {
var strings: [String] = []
strings.append(self.player.formattedName)
// strings.append(self.results.map { "\($0.rank.rankFormatted) (\($0.tournaments.first?.date.year ?? ""))" }.joined(separator: ", "))
strings.append(self.total.currencyFormatted)
strings.append("\(self.numberOfCashes)")
let all = strings.joined(separator: "</td><td>")
return "<tr><td>\(all)</td></tr>"
func colums() -> [String] {
return [self.player.formattedName, self.total.currencyFormatted, "\(self.numberOfCashes)"]
}
// static func htmlHeaders() -> String {
// var strings: [String] = []
// strings.append("Name")
//// strings.append("Places (Year)")
// strings.append("Total Earnings")
// strings.append("Cashes")
// let all = strings.joined(separator: "</td><td>")
// return "<tr class=\"table-header\"><td>\(all)</td></tr>"
// }
//
// func html() -> String {
// var strings: [String] = []
// strings.append(self.player.formattedName)
//// strings.append(self.results.map { "\($0.rank.rankFormatted) (\($0.tournaments.first?.date.year ?? ""))" }.joined(separator: ", "))
// strings.append(self.total.currencyFormatted)
// strings.append("\(self.numberOfCashes)")
// let all = strings.joined(separator: "</td><td>")
// return "<tr><td>\(all)</td></tr>"
// }
}

@ -13,6 +13,20 @@ struct PlayerResult : HTMLRepresentable {
var tournament: Tournament
var result: Result
static func headers() -> [String] {
return ["Player", "Place", "Earnings", "#", "Event"]
}
func colums() -> [String] {
return [
self.result.player?.formattedName ?? "",
self.result.rank.rankFormatted,
result.earnings.currencyFormatted,
"\(tournament.number)",
"\(tournament.buyin.currencyFormatted) \(tournament.name)"
]
}
static func htmlHeaders() -> String {
var strings: String = ""
strings.append("<td width=\"30%\">Player</td>")
@ -23,15 +37,4 @@ struct PlayerResult : HTMLRepresentable {
return "<tr class=\"table-header\">\(strings)</tr>"
}
func html() -> String {
var strings: [String] = []
strings.append(self.result.player?.formattedName ?? "")
strings.append(self.result.rank.rankFormatted)
strings.append(result.earnings.currencyFormatted)
strings.append("\(tournament.number)")
strings.append("\(tournament.buyin.currencyFormatted) \(tournament.name)")
let all = strings.joined(separator: "</td><td>")
return "<tr><td>\(all)</td></tr>"
}
}

@ -21,21 +21,32 @@ class DistributionCounter : HTMLRepresentable {
self.counter += 1
}
static func htmlHeaders() -> String {
var strings: [String] = []
strings.append("Tournament")
strings.append("Counter")
let all = strings.joined(separator: "</td><td>")
return "<tr class=\"table-header\"><td>\(all)</td></tr>"
static func headers() -> [String] {
return ["Tournament", "Counter"]
}
func html() -> String {
func colums() -> [String] {
var strings: [String] = []
strings.append(self.name)
strings.append("\(self.counter)")
let all = strings.joined(separator: "</td><td>")
return "<tr><td>\(all)</td></tr>"
return strings
}
// static func htmlHeaders() -> String {
// var strings: [String] = []
// strings.append("Tournament")
// strings.append("Counter")
// let all = strings.joined(separator: "</td><td>")
// return "<tr class=\"table-header\"><td>\(all)</td></tr>"
// }
//
// func html() -> String {
//
// var strings: [String] = []
// strings.append(self.name)
// strings.append("\(self.counter)")
// let all = strings.joined(separator: "</td><td>")
// return "<tr><td>\(all)</td></tr>"
// }
}

@ -12,6 +12,20 @@ struct TournamentRepresentable : HTMLRepresentable {
var tournament: Tournament
static func headers() -> [String] {
return ["#", "Buy-in", "Event", "Prizepool", "Entries"]
}
func colums() -> [String] {
return [
"\(tournament.number)",
tournament.buyin.currencyFormatted,
tournament.name,
tournament.prizepool.currencyFormatted,
"\(tournament.entries)"
]
}
static func htmlHeaders() -> String {
var strings: [String] = []
// strings.append("Date")
@ -24,16 +38,16 @@ struct TournamentRepresentable : HTMLRepresentable {
return "<tr class=\"table-header\"><td width=\"50\">\(all)</td></tr>"
}
func html() -> String {
var strings: [String] = []
// strings.append(tournament.date.year)
strings.append("\(tournament.number)")
strings.append(tournament.buyin.currencyFormatted)
strings.append(tournament.name)
strings.append(tournament.prizepool.currencyFormatted)
strings.append("\(tournament.entries)")
let all = strings.joined(separator: "</td><td>")
return "<tr><td>\(all)</td></tr>"
}
// func html() -> String {
// var strings: [String] = []
//// strings.append(tournament.date.year)
// strings.append("\(tournament.number)")
// strings.append(tournament.buyin.currencyFormatted)
// strings.append(tournament.name)
// strings.append(tournament.prizepool.currencyFormatted)
// strings.append("\(tournament.entries)")
// let all = strings.joined(separator: "</td><td>")
// return "<tr><td>\(all)</td></tr>"
// }
}

@ -15,6 +15,14 @@ struct TournamentStats : HTMLRepresentable {
var prizepool: Double
var itmValue: Double
static func headers() -> [String] {
return []
}
func colums() -> [String] {
return []
}
static func htmlHeaders() -> String {
return ""
}

@ -13,6 +13,19 @@ struct TournamentWinner : HTMLRepresentable {
var tournament: Tournament
var result: Result
static func headers() -> [String] {
return ["#", "Buy-in", "Event", "Player", "Prize"]
}
func colums() -> [String] {
return ["\(tournament.number)",
tournament.buyin.currencyFormatted,
tournament.name,
result.player?.formattedName ?? "",
result.earnings.currencyFormatted
]
}
static func htmlHeaders() -> String {
var header = ""
header.append("<td width=\"50\">#</td>")
@ -23,14 +36,15 @@ struct TournamentWinner : HTMLRepresentable {
return "<tr class=\"table-header\">\(header)</tr>"
}
func html() -> String {
var strings: [String] = []
strings.append("\(tournament.number)")
strings.append(tournament.buyin.currencyFormatted)
strings.append(tournament.name)
strings.append(result.player?.formattedName ?? "")
strings.append(result.earnings.currencyFormatted)
let all = strings.joined(separator: "</td><td>")
return "<tr><td>\(all)</td></tr>"
}
// func html() -> String {
// var strings: [String] = []
// strings.append("\(tournament.number)")
// strings.append(tournament.buyin.currencyFormatted)
// strings.append(tournament.name)
// strings.append(result.player?.formattedName ?? "")
// strings.append(result.earnings.currencyFormatted)
// let all = strings.joined(separator: "</td><td>")
// return "<tr><td>\(all)</td></tr>"
// }
}

@ -8,27 +8,26 @@
import Foundation
extension Array where Element : CSVRepresentable {
public protocol ColumnRepresentable {
static func headers() -> [String]
func colums() -> [String]
}
func writeCSV(file: String, limit: Int? = 10) {
public protocol HTMLRepresentable : ColumnRepresentable {
static func htmlHeaders() -> String
func html() -> String
}
var string = Element.csvHeaders()
let max = limit ?? Int.max
for (index, rep) in self.enumerated() {
string.append("/n")
string.append(rep.csv())
extension HTMLRepresentable {
if index >= max {
break
}
}
do {
try FileWriter.writeToDocumentDirectory(content: string, fileName: file)
} catch {
print(error)
}
static func htmlHeaders() -> String {
let all = self.headers().joined(separator: "</td><td>")
return "<tr class=\"table-header\"><td>\(all)</td></tr>"
}
func html() -> String {
let all = self.colums().joined(separator: "</td><td>")
return "<tr><td>\(all)</td></tr>"
}
}
@ -62,13 +61,33 @@ extension Array where Element : HTMLRepresentable {
}
extension Array where Element : CSVRepresentable {
func writeCSV(file: String, limit: Int? = 10) {
var string = Element.csvHeaders()
let max = limit ?? Int.max
for (index, rep) in self.enumerated() {
string.append("/n")
string.append(rep.csv())
if index >= max {
break
}
}
do {
try FileWriter.writeToDocumentDirectory(content: string, fileName: file)
} catch {
print(error)
}
}
}
public protocol CSVRepresentable {
static func csvHeaders() -> String
func csv() -> String
}
public protocol HTMLRepresentable {
static func htmlHeaders() -> String
func html() -> String
}
Loading…
Cancel
Save