diff --git a/TournamentStats.xcodeproj/project.pbxproj b/TournamentStats.xcodeproj/project.pbxproj index 87a9a7c..68546b0 100644 --- a/TournamentStats.xcodeproj/project.pbxproj +++ b/TournamentStats.xcodeproj/project.pbxproj @@ -46,6 +46,7 @@ 4D39B6FA22F85C3400625E31 /* UIView+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D39B6F922F85C3400625E31 /* UIView+Extensions.swift */; }; 4D39B6FC22F8686300625E31 /* CumulatedWins.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D39B6FB22F8686300625E31 /* CumulatedWins.swift */; }; 4D39B6FE22F87C3700625E31 /* Charts.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D39B6FD22F87C3700625E31 /* Charts.framework */; }; + 4D5425CA23190EA900B16ECF /* TableSize.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D5425C923190EA900B16ECF /* TableSize.swift */; }; 4DA5CA1E22AD078A00AC628E /* CountryCounter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DA5CA1D22AD078A00AC628E /* CountryCounter.swift */; }; 4DB113D72305480600D0C671 /* InfographyView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4DB113D62305480600D0C671 /* InfographyView.xib */; }; 4DB113D923054A4100D0C671 /* InfographyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DB113D823054A4100D0C671 /* InfographyView.swift */; }; @@ -196,6 +197,7 @@ 4D39B6F922F85C3400625E31 /* UIView+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+Extensions.swift"; sourceTree = ""; }; 4D39B6FB22F8686300625E31 /* CumulatedWins.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CumulatedWins.swift; sourceTree = ""; }; 4D39B6FD22F87C3700625E31 /* Charts.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Charts.framework; path = Carthage/Build/iOS/Charts.framework; sourceTree = ""; }; + 4D5425C923190EA900B16ECF /* TableSize.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableSize.swift; sourceTree = ""; }; 4DA5CA1D22AD078A00AC628E /* CountryCounter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CountryCounter.swift; sourceTree = ""; }; 4DB113D62305480600D0C671 /* InfographyView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = InfographyView.xib; sourceTree = ""; }; 4DB113D823054A4100D0C671 /* InfographyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfographyView.swift; sourceTree = ""; }; @@ -528,6 +530,7 @@ 4DF760C122A561FF004B0EF1 /* ColumnRepresentable.swift */, 4DF760BE22A560AA004B0EF1 /* FileWriter.swift */, 4D26A95323156F6F001C98D2 /* Game.swift */, + 4D5425C923190EA900B16ECF /* TableSize.swift */, ); path = utils; sourceTree = ""; @@ -805,6 +808,7 @@ 4D26A94D23152316001C98D2 /* FestivalStats.swift in Sources */, 4DF78DD622F9CE7E00C02F73 /* TitleLabel.swift in Sources */, 4DF7615122A7AECA004B0EF1 /* TournamentRepresentable.swift in Sources */, + 4D5425CA23190EA900B16ECF /* TableSize.swift in Sources */, 4DF7608622A3FB96004B0EF1 /* MasterViewController.swift in Sources */, 4DF7608422A3FB96004B0EF1 /* AppDelegate.swift in Sources */, 4D39B6F322F8549100625E31 /* DataSourceWrapper.swift in Sources */, diff --git a/TournamentStats.xcodeproj/xcuserdata/laurent.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/TournamentStats.xcodeproj/xcuserdata/laurent.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 57a23b9..2c111f2 100644 --- a/TournamentStats.xcodeproj/xcuserdata/laurent.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/TournamentStats.xcodeproj/xcuserdata/laurent.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -18,11 +18,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "TournamentStats/report/ReportGenerator.swift" - timestampString = "588790717.262743" + timestampString = "588847576.95691" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "82" - endingLineNumber = "82" + startingLineNumber = "83" + endingLineNumber = "83" landmarkName = "generateReports()" landmarkType = "7"> diff --git a/TournamentStats/UI/reports/InfographyView.swift b/TournamentStats/UI/reports/InfographyView.swift index fc3facb..9db2d01 100644 --- a/TournamentStats/UI/reports/InfographyView.swift +++ b/TournamentStats/UI/reports/InfographyView.swift @@ -64,10 +64,12 @@ class InfographyView: UIView { @IBOutlet weak var hStack5a: UIStackView! @IBOutlet weak var label51: UILabel! + @IBOutlet weak var labelTableSize: Label! @IBOutlet weak var hStack5b: UIStackView! @IBOutlet weak var collectionView51: UICollectionView! - + @IBOutlet weak var containerTableSize: UIView! + override func awakeFromNib() { super.awakeFromNib() @@ -75,21 +77,8 @@ class InfographyView: UIView { } fileprivate func _createBackground() { - 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) - self.backgroundColor = startColor - -// let gradient: CAGradientLayer = CAGradientLayer() -// 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.bounds -// -// self.layer.insertSublayer(gradient, at: 0) - } fileprivate func _fillView() { @@ -129,7 +118,6 @@ class InfographyView: UIView { self.label21.text = "Buy-in distribution" self.label22.text = "First prizes distribution" -// self.label23.text = "Prizepool distribution".uppercased() let pieChartFrame = CGRect(x: 0, y: 0, width: 650, height: 500) let buyinDistribPie = PieChart(frame: pieChartFrame) @@ -139,10 +127,6 @@ class InfographyView: UIView { let firstPrizeDistributionPie = PieChart(frame: pieChartFrame) firstPrizeDistributionPie.data = generator.firstPrizeDistribution.pieChartData self.container22.addSubview(firstPrizeDistributionPie) - -// let prizepoolDistribPie = PieChart(frame: pieChartFrame) -// prizepoolDistribPie.data = generator.tournamentPrizepoolDistribution.pieChartData -// self.container23.addSubview(prizepoolDistribPie) ///// @@ -153,7 +137,7 @@ class InfographyView: UIView { ///// - self.label41.text = "USA vs World bracelets" + self.label41.text = "USA vs. World bracelets" self.label42.text = "Games distribution" let USABraceletsDistribPie = PieChart(frame: pieChartFrame) @@ -172,6 +156,10 @@ class InfographyView: UIView { self.collectionView51.dataSource = ds self.collectionView51.delegate = ds + self.labelTableSize.text = "Table Size Distribution" + let tableSizeDistributionPie = PieChart(frame: pieChartFrame) + tableSizeDistributionPie.data = generator.tableSizeDistribution.pieChartData + self.containerTableSize.addSubview(tableSizeDistributionPie) } } diff --git a/TournamentStats/UI/reports/InfographyView.xib b/TournamentStats/UI/reports/InfographyView.xib index 8b5d813..b196de6 100644 --- a/TournamentStats/UI/reports/InfographyView.xib +++ b/TournamentStats/UI/reports/InfographyView.xib @@ -13,11 +13,11 @@ - + - + - + - + - + - + - + @@ -96,7 +96,7 @@ - + @@ -112,7 +112,7 @@ - + @@ -120,7 +120,7 @@ - + - + @@ -156,7 +156,7 @@ - + @@ -164,7 +164,7 @@ - + @@ -176,7 +176,7 @@ - + @@ -184,7 +184,7 @@ - + @@ -196,7 +196,7 @@ - + @@ -204,7 +204,7 @@ - + - + @@ -240,15 +240,15 @@ - + - - + + + + + - + @@ -272,14 +276,6 @@ - - - - - - - - @@ -287,11 +283,23 @@ + + + + @@ -303,6 +311,7 @@ + @@ -317,6 +326,7 @@ + diff --git a/TournamentStats/report/Queries.swift b/TournamentStats/report/Queries.swift index 1d61d03..6396678 100644 --- a/TournamentStats/report/Queries.swift +++ b/TournamentStats/report/Queries.swift @@ -297,6 +297,29 @@ class Queries { return games } + static func tableSizeDistribution(realm: Realm) -> [DistributionCounter] { + + let tournaments: Results = realm.objects(Tournament.self).distinct(by: ["tableSize"]) + var slices: [DistributionCounter] = [] + var othersCount: Int = 0 + for tournament in tournaments { + let tableSizeCount = realm.objects(Tournament.self).filter("tableSize == %i", tournament.tableSize).count + if (tableSizeCount < 5) { + othersCount += tableSizeCount + } else { + let counter = DistributionCounter(name: TableSize.format(tableSize: tournament.tableSize), counter: tableSizeCount) + slices.append(counter) + } + } + let others = DistributionCounter(name: "Others", counter: othersCount) + slices.append(others) + + slices.sort { (d1, d2) -> Bool in + return d1.counter > d2.counter + } + return slices + } + static func rankingCounts(realm: Realm) -> [PlayerNotableFinishes] { let players: Results = realm.objects(Player.self) diff --git a/TournamentStats/report/ReportGenerator.swift b/TournamentStats/report/ReportGenerator.swift index 98b51d5..77d0c91 100644 --- a/TournamentStats/report/ReportGenerator.swift +++ b/TournamentStats/report/ReportGenerator.swift @@ -68,6 +68,7 @@ class ReportGenerator { var gamesDistribution: [DistributionCounter] = [] var rankings1: PlayerNotableFinishesDataSource = PlayerNotableFinishesDataSource(notableFinishes: []) var finalTables: [CumulatedResults] = [] + var tableSizeDistribution: [DistributionCounter] = [] func generateReports() { @@ -97,6 +98,8 @@ class ReportGenerator { self.rankings1 = pnds self.finalTables = pnds.finalTablesCumulated() + self.tableSizeDistribution = Queries.tableSizeDistribution(realm: realm) + let tourniesDate = realm.objects(Tournament.self).distinct(by: ["date"]) // Individual days diff --git a/TournamentStats/report/structures/FestivalStats.swift b/TournamentStats/report/structures/FestivalStats.swift index 227671e..df79b01 100644 --- a/TournamentStats/report/structures/FestivalStats.swift +++ b/TournamentStats/report/structures/FestivalStats.swift @@ -38,7 +38,7 @@ class FestivalStats : NSObject, UICollectionViewDataSource, UICollectionViewDele name = "Total Entries".uppercased() value = self.totalEntries.formatted case 3: - name = "Cumulated Buy-ins".uppercased() + name = "Cost of entering all tournaments".uppercased() value = self.cumulatedBuyins.currencyFormatted default: name = "" diff --git a/TournamentStats/report/structures/PlayerNotableFinishes.swift b/TournamentStats/report/structures/PlayerNotableFinishes.swift index 51969ae..c7bd3e6 100644 --- a/TournamentStats/report/structures/PlayerNotableFinishes.swift +++ b/TournamentStats/report/structures/PlayerNotableFinishes.swift @@ -48,7 +48,7 @@ class PlayerNotableFinishesDataSource : NSObject, UITableViewDataSource, UITable self.mostWins = nWins.filter { $0.wins.count == winsTopCount} for win in self.mostWins { - self.winsDisplay.append((win.player.formattedName, Fonts.cellTitle)) + self.winsDisplay.append((win.player.formattedName, Fonts.bold)) let sortedWins = win.wins.sorted(by: { $0.tournaments.first!.number < $1.tournaments.first!.number }) for result in sortedWins { if let tournamentName = result.tournaments.first?.formatted { @@ -68,7 +68,7 @@ class PlayerNotableFinishesDataSource : NSObject, UITableViewDataSource, UITable self.mostRunnerUps = nRunnerups.filter { $0.runnerUps.count == runnerUpsTopCount } for runnerup in self.mostRunnerUps { - self.runnerUpsDisplay.append((runnerup.player.formattedName, Fonts.cellTitle)) + self.runnerUpsDisplay.append((runnerup.player.formattedName, Fonts.bold)) let sortedRunnerUps = runnerup.runnerUps.sorted(by: { $0.tournaments.first!.number < $1.tournaments.first!.number }) for result in sortedRunnerUps { if let tournamentName = result.tournaments.first?.formatted { @@ -159,6 +159,10 @@ class PlayerNotableFinishesDataSource : NSObject, UITableViewDataSource, UITable return self.headerLabel(text: text) } + func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { + return 36.0 + } + func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { return 60.0 } diff --git a/TournamentStats/report/structures/TournamentCounter.swift b/TournamentStats/report/structures/TournamentCounter.swift index d70bd2e..1a8bbd3 100644 --- a/TournamentStats/report/structures/TournamentCounter.swift +++ b/TournamentStats/report/structures/TournamentCounter.swift @@ -18,6 +18,11 @@ class DistributionCounter : HTMLRepresentable { self.name = name } + convenience init(name: String, counter: Int) { + self.init(name: name) + self.counter = counter + } + func increment() { self.counter += 1 } diff --git a/TournamentStats/report/structures/TournamentStats.swift b/TournamentStats/report/structures/TournamentStats.swift index c295c51..00b6acb 100644 --- a/TournamentStats/report/structures/TournamentStats.swift +++ b/TournamentStats/report/structures/TournamentStats.swift @@ -163,7 +163,7 @@ class TournamentStats : NSObject, HTMLRepresentable, UITableViewDelegate, UITabl } func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { - return CGSize(width: 380.0, height: 90.0) + return CGSize(width: 650.0, height: 90.0) } } diff --git a/TournamentStats/utils/TableSize.swift b/TournamentStats/utils/TableSize.swift new file mode 100644 index 0000000..060cfbb --- /dev/null +++ b/TournamentStats/utils/TableSize.swift @@ -0,0 +1,22 @@ +// +// TableSize.swift +// TournamentStats +// +// Created by Laurent Morvillier on 30/08/2019. +// Copyright © 2019 Stax River. All rights reserved. +// + +import Foundation + +class TableSize { + + static func format(tableSize: Int) -> String { + switch tableSize { + case 2: + return "Heads-up" + default: + return "\(tableSize)-max" + } + } + +}