diff --git a/TournamentStats.xcodeproj/project.pbxproj b/TournamentStats.xcodeproj/project.pbxproj index f08fdf5..87a9a7c 100644 --- a/TournamentStats.xcodeproj/project.pbxproj +++ b/TournamentStats.xcodeproj/project.pbxproj @@ -40,7 +40,6 @@ 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 /* InfographyViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D39B6F022F829A500625E31 /* InfographyViewController.swift */; }; 4D39B6F322F8549100625E31 /* DataSourceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D39B6F222F8549100625E31 /* DataSourceWrapper.swift */; }; 4D39B6F522F856EF00625E31 /* StackTableCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4D39B6F422F856EF00625E31 /* StackTableCell.xib */; }; 4D39B6F722F8573900625E31 /* StackTableCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D39B6F622F8573900625E31 /* StackTableCell.swift */; }; @@ -52,6 +51,7 @@ 4DB113D923054A4100D0C671 /* InfographyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DB113D823054A4100D0C671 /* InfographyView.swift */; }; 4DB113DB230559F600D0C671 /* Label.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DB113DA230559F600D0C671 /* Label.swift */; }; 4DB113DD2305882A00D0C671 /* Fonts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DB113DC2305882A00D0C671 /* Fonts.swift */; }; + 4DD9C5BD2316D092003501A4 /* PlayerNotableFinishes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DD9C5BC2316D092003501A4 /* PlayerNotableFinishes.swift */; }; 4DDEF11422AE4FB900F4D7C1 /* TournamentStats.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DDEF11322AE4FB900F4D7C1 /* TournamentStats.swift */; }; 4DF7608422A3FB96004B0EF1 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DF7608322A3FB96004B0EF1 /* AppDelegate.swift */; }; 4DF7608622A3FB96004B0EF1 /* MasterViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DF7608522A3FB96004B0EF1 /* MasterViewController.swift */; }; @@ -190,7 +190,6 @@ 4D2F1C4322CC92D1007C639E /* event84 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = event84; sourceTree = ""; }; 4D30463122F4232600DA86C4 /* event57 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = event57; sourceTree = ""; }; 4D30463222F4232600DA86C4 /* event78 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = event78; sourceTree = ""; }; - 4D39B6F022F829A500625E31 /* InfographyViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfographyViewController.swift; sourceTree = ""; }; 4D39B6F222F8549100625E31 /* DataSourceWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataSourceWrapper.swift; sourceTree = ""; }; 4D39B6F422F856EF00625E31 /* StackTableCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = StackTableCell.xib; sourceTree = ""; }; 4D39B6F622F8573900625E31 /* StackTableCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StackTableCell.swift; sourceTree = ""; }; @@ -202,6 +201,7 @@ 4DB113D823054A4100D0C671 /* InfographyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfographyView.swift; sourceTree = ""; }; 4DB113DA230559F600D0C671 /* Label.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Label.swift; sourceTree = ""; }; 4DB113DC2305882A00D0C671 /* Fonts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Fonts.swift; sourceTree = ""; }; + 4DD9C5BC2316D092003501A4 /* PlayerNotableFinishes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerNotableFinishes.swift; sourceTree = ""; }; 4DDEF11322AE4FB900F4D7C1 /* TournamentStats.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TournamentStats.swift; sourceTree = ""; }; 4DF7608022A3FB96004B0EF1 /* TournamentStats.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TournamentStats.app; sourceTree = BUILT_PRODUCTS_DIR; }; 4DF7608322A3FB96004B0EF1 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; @@ -324,7 +324,6 @@ 4D97941222F827A5004A2D7F /* reports */ = { isa = PBXGroup; children = ( - 4D39B6F022F829A500625E31 /* InfographyViewController.swift */, 4DB113D62305480600D0C671 /* InfographyView.xib */, 4DB113D823054A4100D0C671 /* InfographyView.swift */, 4D26A95023152A6B001C98D2 /* StatCollectionViewCell.swift */, @@ -556,6 +555,7 @@ 4DF7615022A7AECA004B0EF1 /* TournamentRepresentable.swift */, 4DDEF11322AE4FB900F4D7C1 /* TournamentStats.swift */, 4DF7614922A66675004B0EF1 /* TournamentWinner.swift */, + 4DD9C5BC2316D092003501A4 /* PlayerNotableFinishes.swift */, ); path = structures; sourceTree = ""; @@ -798,7 +798,6 @@ 4DF760B022A47C74004B0EF1 /* RowImporter.swift in Sources */, 4DF7614A22A66675004B0EF1 /* TournamentWinner.swift in Sources */, 4D0F103722C4C08F005F797A /* ChipCount.swift in Sources */, - 4D39B6F122F829A500625E31 /* InfographyViewController.swift in Sources */, 4DF760B322A47CAE004B0EF1 /* Realm+Extensions.swift in Sources */, 4DF7608822A3FB96004B0EF1 /* DetailViewController.swift in Sources */, 4D26A95423156F6F001C98D2 /* Game.swift in Sources */, @@ -809,6 +808,7 @@ 4DF7608622A3FB96004B0EF1 /* MasterViewController.swift in Sources */, 4DF7608422A3FB96004B0EF1 /* AppDelegate.swift in Sources */, 4D39B6F322F8549100625E31 /* DataSourceWrapper.swift in Sources */, + 4DD9C5BD2316D092003501A4 /* PlayerNotableFinishes.swift in Sources */, 4DDEF11422AE4FB900F4D7C1 /* TournamentStats.swift in Sources */, 4DF760A722A3FD12004B0EF1 /* Model.swift in Sources */, 4D39B6FC22F8686300625E31 /* CumulatedWins.swift in Sources */, diff --git a/TournamentStats/UI/reports/InfographyView.swift b/TournamentStats/UI/reports/InfographyView.swift index e378db0..d9c44a5 100644 --- a/TournamentStats/UI/reports/InfographyView.swift +++ b/TournamentStats/UI/reports/InfographyView.swift @@ -31,6 +31,8 @@ class InfographyView: UIView { @IBOutlet weak var tableView12: TableView! @IBOutlet weak var tableView13: TableView! + @IBOutlet weak var mostCollectionView: UICollectionView! + @IBOutlet weak var hStack2a: UIStackView! @IBOutlet weak var label21: UILabel! @IBOutlet weak var label22: UILabel! @@ -102,6 +104,12 @@ class InfographyView: UIView { self.collectionView.delegate = generator.festivalStats self.collectionView.dataSource = generator.festivalStats + ///// + + self.mostCollectionView.register(UINib(nibName: "StatCollectionViewCell", bundle: Bundle.main), forCellWithReuseIdentifier: "Stat") + self.mostCollectionView.delegate = generator.rankings + self.mostCollectionView.dataSource = generator.rankings + ///// self.tableView11.setData(data: generator.biggestWinners) @@ -150,7 +158,7 @@ class InfographyView: UIView { self.container41.addMaxConstraints(view: USABraceletsDistribPie) let holdemDistributionPie = PieChart(frame: pieChartFrame) - holdemDistributionPie.data = generator.holdemTournamentsDistribution.pieChartData + holdemDistributionPie.data = generator.gamesDistribution.pieChartData self.container42.addSubview(holdemDistributionPie) self.container42.addMaxConstraints(view: holdemDistributionPie) diff --git a/TournamentStats/UI/reports/InfographyView.xib b/TournamentStats/UI/reports/InfographyView.xib index c64ec39..4fd90c9 100644 --- a/TournamentStats/UI/reports/InfographyView.xib +++ b/TournamentStats/UI/reports/InfographyView.xib @@ -17,7 +17,7 @@ - + + + + + + + + + + + + + + - + @@ -72,7 +85,7 @@ - + @@ -88,7 +101,7 @@ - + - + @@ -124,7 +137,7 @@ - + @@ -132,7 +145,7 @@ - + @@ -144,7 +157,7 @@ - + @@ -152,7 +165,7 @@ - + @@ -164,7 +177,7 @@ - + @@ -172,7 +185,7 @@ - + - + @@ -208,7 +221,7 @@ - + - + @@ -285,6 +298,7 @@ + diff --git a/TournamentStats/UI/reports/InfographyViewController.swift b/TournamentStats/UI/reports/InfographyViewController.swift deleted file mode 100644 index b9d81c5..0000000 --- a/TournamentStats/UI/reports/InfographyViewController.swift +++ /dev/null @@ -1,192 +0,0 @@ -// -// InfographyView.swift -// TournamentStats -// -// Created by Laurent Morvillier on 05/08/2019. -// Copyright © 2019 Stax River. All rights reserved. -// - -import Foundation -import UIKit -import Charts - -class InfographyViewController : UIViewController { - - var generator: ReportGenerator? - - override func viewDidLayoutSubviews() { - - super.viewDidLayoutSubviews() - - let gradient: CAGradientLayer = CAGradientLayer() - - let startColor = UIColor(red: 23/255, green: 72/255, blue: 61/255, alpha: 1) - let endColor = UIColor(red: 47/255, green: 149/255, blue: 126/255, alpha: 1) - - gradient.colors = [startColor.cgColor, endColor.cgColor] - gradient.locations = [0.2 , 1.0] - gradient.startPoint = CGPoint(x: 0.0, y: 0.0) - gradient.endPoint = CGPoint(x: 1.0, y: 1.0) - gradient.frame = self.view.bounds - - self.view.layer.insertSublayer(gradient, at: 0) - - } - - override func viewDidLoad() { - - let totalWidth: CGFloat = 1500.0 - let defaultSpacing: CGFloat = 8.0 - - guard let generator = self.generator else { - return - } - - let mainTitle = UILabel() - mainTitle.textColor = UIColor.white - mainTitle.font = UIFont.boldSystemFont(ofSize: 64.0) - mainTitle.textAlignment = .center - mainTitle.text = "2019 WSOP" - -// let table1 = TableView(data: generator.biggestWinners, frame: CGRect.zero, style: .grouped) -// table1.defineConstraints(width: 500 - defaultSpacing / 3, height: 500) -// -// let table2 = TableView(data: generator.mostWins, frame: CGRect.zero, style: .grouped) -// table2.defineConstraints(width: 500 - defaultSpacing / 3, height: 500) -// -// let table3 = TableView(data: generator.averageCash, frame: CGRect.zero, style: .grouped) -// table3.defineConstraints(width: 500 - defaultSpacing / 3, height: 500) -// -// let hstack1: UIStackView = UIStackView(arrangedSubviews: [table1, table2, table3]) -// hstack1.defineConstraints(width: totalWidth, height: 300.0) -// hstack1.distribution = .equalSpacing -// hstack1.spacing = 8.0 -// hstack1.axis = .horizontal -// hstack1.alignment = .top -// -// ///// -// -// let title1 = TitleLabel(frame: CGRect.zero, text: "Buy-in distribution") -// let title2 = TitleLabel(frame: CGRect.zero, text: "First prizes distribution") -// let title3 = TitleLabel(frame: CGRect.zero, text: "Prizepool distribution") -// -// let hstack2a: UIStackView = UIStackView(arrangedSubviews: [title1, title2, title3]) -// hstack2a.defineConstraints(width: totalWidth) -// hstack2a.distribution = .fillEqually -// hstack2a.axis = .horizontal -// hstack2a.alignment = .top -// -// ///// -// -// let buyinDistribPie = PieChart(frame: CGRect.zero) -// buyinDistribPie.data = generator.tournamentBuyinDistribution.pieChartData -// buyinDistribPie.defineConstraints(height: 300) -// buyinDistribPie.notifyDataSetChanged() -// -// let firstPrizeDistributionPie = PieChart(frame: CGRect.zero) -// firstPrizeDistributionPie.data = generator.firstPrizeDistribution.pieChartData -// firstPrizeDistributionPie.defineConstraints(height: 300) -// -// let prizepoolDistribPie = PieChart(frame: CGRect.zero) -// prizepoolDistribPie.data = generator.tournamentPrizepoolDistribution.pieChartData -// prizepoolDistribPie.defineConstraints(height: 400) -// -// let hstack2: UIStackView = UIStackView(arrangedSubviews: [buyinDistribPie, firstPrizeDistributionPie, prizepoolDistribPie]) -// hstack2.defineConstraints(width: totalWidth, height: 350.0) -// hstack2.distribution = .fillEqually -// hstack2.axis = .horizontal -// hstack2.alignment = .top -// -// -// ///// -// -// let title31 = TitleLabel(frame: CGRect.zero, text: "Events by prizepool") -// let title32 = TitleLabel(frame: CGRect.zero, text: "Events by entries") -// -// let hstack3a: UIStackView = UIStackView(arrangedSubviews: [title31, title32]) -// hstack3a.defineConstraints(width: totalWidth) -// hstack3a.distribution = .fillEqually -// hstack3a.axis = .horizontal -// hstack3a.alignment = .top -// -// ///// -// -// let table31 = TableView(data: generator.tourniesByPrizepool, frame: CGRect.zero, style: .grouped) -// table31.defineConstraints(width: 750, height: 500) -// -// let table32 = TableView(data: generator.tourniesByEntries, frame: CGRect.zero, style: .grouped) -// table32.defineConstraints(width: 750, height: 500) -// -// let hstack3: UIStackView = UIStackView(arrangedSubviews: [table31, table32]) -// hstack3.defineConstraints(width: totalWidth, height: 300.0) -// hstack3.distribution = .equalSpacing -// hstack3.spacing = 8.0 -// hstack3.axis = .horizontal -// hstack3.alignment = .top - - ///// - - let vstack: UIStackView = UIStackView(arrangedSubviews: [mainTitle]) -// let vstack: UIStackView = UIStackView(arrangedSubviews: [mainTitle, hstack1, hstack2a, hstack2, hstack3a, hstack3]) - vstack.axis = .vertical - vstack.distribution = .equalCentering - vstack.alignment = .center - vstack.spacing = 10.0 - self.view.addSubview(vstack) - - vstack.translatesAutoresizingMaskIntoConstraints = false - vstack.leadingAnchor.constraint(equalTo: self.view.leadingAnchor, constant: 16.0).isActive = true - vstack.trailingAnchor.constraint(equalTo: self.view.trailingAnchor, constant: -16.0).isActive = true - vstack.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor, constant: 16.0).isActive = true - - } - -} - -//class InfographyView : UIView { -// -// var references: [UITableViewDataSource] = [] -// -// init(frame: CGRect, generator: ReportGenerator) { -// super.init(frame: frame) -// self.backgroundColor = UIColor.lightGray -// -// let table1 = TableView(data: generator.biggestWinners, frame: CGRect.zero, style: .grouped) -// table1.defineConstraints(width: 500, height: 500) -// -// let table2 = TableView(data: generator.mostWins, frame: CGRect.zero, style: .grouped) -// table2.defineConstraints(width: 500, height: 500) -// -// let pieChart = PieChartView(frame: CGRect.zero) -// pieChart.data = generator.tournamentBuyinDistribution.pieChartData -// pieChart.defineConstraints(width: 300, height: 300) -// -// let hstack1: UIStackView = UIStackView(arrangedSubviews: [table1, table2]) -// hstack1.defineConstraints(width: 1000, height: 500) -// hstack1.distribution = .fill -// hstack1.axis = .horizontal -// hstack1.alignment = .top -// hstack1.backgroundColor = UIColor.red -// -// let hstack2: UIStackView = UIStackView(arrangedSubviews: [pieChart]) -// hstack2.defineConstraints(width: 1000, height: 300) -// hstack2.distribution = .fill -// hstack2.axis = .horizontal -// hstack2.alignment = .top -// hstack2.backgroundColor = UIColor.green -// -// let vstack: UIStackView = UIStackView(arrangedSubviews: [hstack1, hstack2]) -// vstack.axis = .vertical -// vstack.distribution = .fill -// vstack.alignment = .leading -// vstack.backgroundColor = UIColor.blue -// self.addSubview(vstack) -// self.addMaxConstraints(view: vstack) -// -// } -// -// required init?(coder aDecoder: NSCoder) { -// fatalError("init(coder:) has not been implemented") -// } -// -//} diff --git a/TournamentStats/realm/Model.swift b/TournamentStats/realm/Model.swift index fbee3f1..3cd5576 100644 --- a/TournamentStats/realm/Model.swift +++ b/TournamentStats/realm/Model.swift @@ -22,7 +22,20 @@ class Tournament : Object, Named { @objc dynamic var date: Date = Date() @objc dynamic var number: Int = 0 @objc dynamic var buyin: Int = 0 - @objc dynamic var name: String = "" + @objc dynamic var tableSize: Int = 0 + @objc dynamic var name: String = "" { + didSet { + if name.contains("6-Handed") { + self.tableSize = 6 + } else if name.contains("8-Handed") { + self.tableSize = 8 + } else if name.contains("Heads-Up") { + self.tableSize = 2 + } else { + self.tableSize = 10 + } + } + } let results = List() @objc dynamic var prizepool: Double = 0.0 diff --git a/TournamentStats/report/Queries.swift b/TournamentStats/report/Queries.swift index 45d7a1b..15faf12 100644 --- a/TournamentStats/report/Queries.swift +++ b/TournamentStats/report/Queries.swift @@ -297,4 +297,36 @@ class Queries { return games } + static func rankingCounts(realm: Realm) -> [PlayerNotableFinishes] { + + let players: Results = realm.objects(Player.self) + + var notableFinishes: [PlayerNotableFinishes] = [] + + players.forEach { player in + + var wins: [Result] = [] + var runnerUps: [Result] = [] + var finalTables: [Result] = [] + + player.results.forEach { result in + switch result.rank { + case 1: + wins.append(result) + case 2: + runnerUps.append(result) + default: + if result.rank <= result.tournaments.first?.tableSize ?? 10 { + finalTables.append(result) + } + } + } + + notableFinishes.append(PlayerNotableFinishes(player: player, wins: wins, runnerUps: runnerUps, finalTables: finalTables)) + + } + + return notableFinishes + } + } diff --git a/TournamentStats/report/ReportGenerator.swift b/TournamentStats/report/ReportGenerator.swift index 160ceb2..cf18bfb 100644 --- a/TournamentStats/report/ReportGenerator.swift +++ b/TournamentStats/report/ReportGenerator.swift @@ -65,7 +65,8 @@ class ReportGenerator { var tournamentBuyinDistribution: [DistributionCounter] = [] var tournamentPrizepoolDistribution: [DistributionCounter] = [] var firstPrizeDistribution: [DistributionCounter] = [] - var holdemTournamentsDistribution: [DistributionCounter] = [] + var gamesDistribution: [DistributionCounter] = [] + var rankings: PlayerNotableFinishesDataSource = PlayerNotableFinishesDataSource(notableFinishes: []) func generateReports() { @@ -89,7 +90,8 @@ class ReportGenerator { self.tournamentBuyinDistribution = Queries.tournamentBuyinDistribution(realm: realm) self.tournamentPrizepoolDistribution = Queries.tournamentPrizepoolDistribution(realm: realm) self.firstPrizeDistribution = Queries.firstPrizeDistribution(realm: realm) - self.holdemTournamentsDistribution = Queries.holdemTournamentsDistribution(realm: realm) + self.gamesDistribution = Queries.holdemTournamentsDistribution(realm: realm) + self.rankings = PlayerNotableFinishesDataSource(notableFinishes: Queries.rankingCounts(realm: realm)) let tourniesDate = realm.objects(Tournament.self).distinct(by: ["date"]) @@ -126,7 +128,7 @@ class ReportGenerator { self.tournamentBuyinDistribution.writeHTML(fileName: "reports/buyinDistribution.html") self.tournamentPrizepoolDistribution.writeHTML(fileName: "reports/prizepoolDistribution.html") self.firstPrizeDistribution.writeHTML(fileName: "reports/firstPrizeDistribution.html") - self.holdemTournamentsDistribution.writeHTML(fileName: "reports/holdemDistribution.html") + self.gamesDistribution.writeHTML(fileName: "reports/holdemDistribution.html") } diff --git a/TournamentStats/report/structures/PlayerNotableFinishes.swift b/TournamentStats/report/structures/PlayerNotableFinishes.swift new file mode 100644 index 0000000..9e01c42 --- /dev/null +++ b/TournamentStats/report/structures/PlayerNotableFinishes.swift @@ -0,0 +1,105 @@ +// +// PlayerNotableFinishes.swift +// TournamentStats +// +// Created by Laurent Morvillier on 28/08/2019. +// Copyright © 2019 Stax River. All rights reserved. +// + +import Foundation +import UIKit + +struct PlayerNotableFinishes { + + var player: Player + var wins: [Result] = [] + var runnerUps: [Result] = [] + var finalTables: [Result] = [] + +} + +class PlayerNotableFinishesDataSource : NSObject, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout { + + let notableFinishes: [PlayerNotableFinishes] + let mostWins: [Player] + let mostWinsCount: Int + let mostRunnerUps: [Player] + let mostRunnerUpsCount: Int + let mostFinalTables: [Player] + let mostFinalTablesCount: Int + + init(notableFinishes: [PlayerNotableFinishes]) { + self.notableFinishes = notableFinishes + + /////// + var nWins = notableFinishes + nWins.sort { (p1, p2) -> Bool in + return p1.wins.count > p2.wins.count + } + let winsTopCount = nWins.first?.wins.count ?? 0 + self.mostWins = nWins.filter { $0.wins.count == winsTopCount}.map { $0.player } + + /////// + var nRunnerups = notableFinishes + nRunnerups.sort { (p1, p2) -> Bool in + return p1.runnerUps.count > p2.runnerUps.count + } + let runnerUpsTopCount = nRunnerups.first?.runnerUps.count ?? 0 + self.mostRunnerUps = nRunnerups.filter { $0.runnerUps.count == runnerUpsTopCount}.map { $0.player } + + /////// + var nFinalTables = notableFinishes + nFinalTables.sort { (p1, p2) -> Bool in + return p1.finalTables.count > p2.finalTables.count + } + let finalTablesTopCount = nFinalTables.first?.finalTables.count ?? 0 + self.mostFinalTables = nFinalTables.filter { $0.finalTables.count == finalTablesTopCount}.map { $0.player } + + self.mostWinsCount = winsTopCount + self.mostRunnerUpsCount = runnerUpsTopCount + self.mostFinalTablesCount = finalTablesTopCount + + } + + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + return 3 + } + + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Stat", for: indexPath) as! StatCollectionViewCell + + let name: String + let value: String + switch indexPath.row { + case 0: + name = "Most Wins" + value = self.mostWins.map { $0.formattedName }.joined(separator: ", ") + " (\(self.mostWinsCount))" + case 1: + name = "Most Runner-up" + value = self.mostRunnerUps.map { $0.formattedName }.joined(separator: ", ") + " (\(self.mostRunnerUpsCount))" + case 2: + name = "Most final tables" + value = self.mostFinalTables.map { $0.formattedName }.joined(separator: ", ") + " (\(self.mostFinalTablesCount))" + default: + name = "" + value = "" + } + + cell.nameLabel.text = name.uppercased() + cell.valueLabel.text = value + + cell.nameLabel.textColor = UIColor.white + cell.valueLabel.textColor = UIColor.white + + cell.nameLabel.font = Fonts.regular + cell.valueLabel.font = Fonts.bigNumbers + + return cell + } + + func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { + return CGSize(width: 800.0, height: 90.0) + } + +}