diff --git a/TournamentStats.xcodeproj/project.pbxproj b/TournamentStats.xcodeproj/project.pbxproj index 4a18947..3ade8be 100644 --- a/TournamentStats.xcodeproj/project.pbxproj +++ b/TournamentStats.xcodeproj/project.pbxproj @@ -11,6 +11,9 @@ 4D0F103722C4C08F005F797A /* ChipCount.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D0F103622C4C08F005F797A /* ChipCount.swift */; }; 4D0F103922C4C1C4005F797A /* ChipCountParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D0F103822C4C1C4005F797A /* ChipCountParser.swift */; }; 4D18861122C36D8F0020C4CD /* TournamentCounter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D18861022C36D8F0020C4CD /* TournamentCounter.swift */; }; + 4D26A94D23152316001C98D2 /* FestivalStats.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D26A94C23152316001C98D2 /* FestivalStats.swift */; }; + 4D26A94F23152A1C001C98D2 /* StatCollectionViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4D26A94E23152A1C001C98D2 /* StatCollectionViewCell.xib */; }; + 4D26A95123152A6B001C98D2 /* StatCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D26A95023152A6B001C98D2 /* StatCollectionViewCell.swift */; }; 4D2F1C4422CC92D1007C639E /* event81 in Resources */ = {isa = PBXBuildFile; fileRef = 4D2F1C2C22CC92CE007C639E /* event81 */; }; 4D2F1C4522CC92D1007C639E /* event80 in Resources */ = {isa = PBXBuildFile; fileRef = 4D2F1C2D22CC92CE007C639E /* event80 */; }; 4D2F1C4622CC92D1007C639E /* event76 in Resources */ = {isa = PBXBuildFile; fileRef = 4D2F1C2E22CC92CE007C639E /* event76 */; }; @@ -157,6 +160,9 @@ 4D0F103622C4C08F005F797A /* ChipCount.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChipCount.swift; sourceTree = ""; }; 4D0F103822C4C1C4005F797A /* ChipCountParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChipCountParser.swift; sourceTree = ""; }; 4D18861022C36D8F0020C4CD /* TournamentCounter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TournamentCounter.swift; sourceTree = ""; }; + 4D26A94C23152316001C98D2 /* FestivalStats.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FestivalStats.swift; sourceTree = ""; }; + 4D26A94E23152A1C001C98D2 /* StatCollectionViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = StatCollectionViewCell.xib; sourceTree = ""; }; + 4D26A95023152A6B001C98D2 /* StatCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatCollectionViewCell.swift; sourceTree = ""; }; 4D2F1C2C22CC92CE007C639E /* event81 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = event81; sourceTree = ""; }; 4D2F1C2D22CC92CE007C639E /* event80 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = event80; sourceTree = ""; }; 4D2F1C2E22CC92CE007C639E /* event76 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = event76; sourceTree = ""; }; @@ -319,6 +325,8 @@ 4D39B6F022F829A500625E31 /* InfographyViewController.swift */, 4DB113D62305480600D0C671 /* InfographyView.xib */, 4DB113D823054A4100D0C671 /* InfographyView.swift */, + 4D26A95023152A6B001C98D2 /* StatCollectionViewCell.swift */, + 4D26A94E23152A1C001C98D2 /* StatCollectionViewCell.xib */, ); path = reports; sourceTree = ""; @@ -535,15 +543,16 @@ 4DF7614B22A6677A004B0EF1 /* structures */ = { isa = PBXGroup; children = ( - 4D39B6FB22F8686300625E31 /* CumulatedWins.swift */, + 4D0F103622C4C08F005F797A /* ChipCount.swift */, + 4DA5CA1D22AD078A00AC628E /* CountryCounter.swift */, 4DF7614522A59407004B0EF1 /* CumulatedResults.swift */, - 4DF7614922A66675004B0EF1 /* TournamentWinner.swift */, + 4D39B6FB22F8686300625E31 /* CumulatedWins.swift */, + 4D26A94C23152316001C98D2 /* FestivalStats.swift */, 4DF7614E22A6CF93004B0EF1 /* PlayerResult.swift */, + 4D18861022C36D8F0020C4CD /* TournamentCounter.swift */, 4DF7615022A7AECA004B0EF1 /* TournamentRepresentable.swift */, - 4DA5CA1D22AD078A00AC628E /* CountryCounter.swift */, 4DDEF11322AE4FB900F4D7C1 /* TournamentStats.swift */, - 4D18861022C36D8F0020C4CD /* TournamentCounter.swift */, - 4D0F103622C4C08F005F797A /* ChipCount.swift */, + 4DF7614922A66675004B0EF1 /* TournamentWinner.swift */, ); path = structures; sourceTree = ""; @@ -720,6 +729,7 @@ 4DF7613A22A56797004B0EF1 /* event17 in Resources */, 4DF7612022A56797004B0EF1 /* event31 in Resources */, 4DF7614122A56797004B0EF1 /* event52 in Resources */, + 4D26A94F23152A1C001C98D2 /* StatCollectionViewCell.xib in Resources */, 4D2F1C4F22CC92D1007C639E /* event79 in Resources */, 4DF7613D22A56797004B0EF1 /* event56 in Resources */, 4DF7612422A56797004B0EF1 /* event43 in Resources */, @@ -779,6 +789,7 @@ files = ( 4DF7614822A59660004B0EF1 /* ReportGenerator.swift in Sources */, 4DB113D923054A4100D0C671 /* InfographyView.swift in Sources */, + 4D26A95123152A6B001C98D2 /* StatCollectionViewCell.swift in Sources */, 4DF78DD422F9C85C00C02F73 /* UIColor+Extensions.swift in Sources */, 4DF760C222A561FF004B0EF1 /* ColumnRepresentable.swift in Sources */, 4DF760B022A47C74004B0EF1 /* RowImporter.swift in Sources */, @@ -788,6 +799,7 @@ 4DF760B322A47CAE004B0EF1 /* Realm+Extensions.swift in Sources */, 4DF7608822A3FB96004B0EF1 /* DetailViewController.swift in Sources */, 4DF78DD122F9AADF00C02F73 /* TableView.swift in Sources */, + 4D26A94D23152316001C98D2 /* FestivalStats.swift in Sources */, 4DF78DD622F9CE7E00C02F73 /* TitleLabel.swift in Sources */, 4DF7615122A7AECA004B0EF1 /* TournamentRepresentable.swift in Sources */, 4DF7608622A3FB96004B0EF1 /* MasterViewController.swift in Sources */, diff --git a/TournamentStats/UI/reports/InfographyView.swift b/TournamentStats/UI/reports/InfographyView.swift index d5b127b..50ab845 100644 --- a/TournamentStats/UI/reports/InfographyView.swift +++ b/TournamentStats/UI/reports/InfographyView.swift @@ -19,6 +19,8 @@ class InfographyView: UIView { @IBOutlet weak var infographyTitle: UILabel! + @IBOutlet weak var collectionView: UICollectionView! + @IBOutlet weak var hStack1a: UIStackView! @IBOutlet weak var label11: UILabel! @IBOutlet weak var label12: UILabel! @@ -97,6 +99,10 @@ class InfographyView: UIView { self.infographyTitle.textColor = UIColor.white self.infographyTitle.font = Fonts.mainTitle + self.collectionView.register(UINib(nibName: "StatCollectionViewCell", bundle: Bundle.main), forCellWithReuseIdentifier: "Stat") + self.collectionView.delegate = generator.festivalStats + self.collectionView.dataSource = generator.festivalStats + ///// self.label11.text = "Biggest Winners".uppercased() @@ -131,13 +137,13 @@ class InfographyView: UIView { self.label31.text = "Events by prizepool".uppercased() self.label32.text = "Events by entries".uppercased() - self.tableView31.setData(data: generator.tourniesByPrizepool) - self.tableView32.setData(data: generator.tourniesByEntries) + self.tableView31.setData(data: generator.tourniesByPrizepool, maxRows: 5) + self.tableView32.setData(data: generator.tourniesByEntries, maxRows: 5) ///// self.label41.text = "USA vs World bracelets".uppercased() - self.label42.text = "Holdem vs exotic games".uppercased() + self.label42.text = "Hold'em vs not hold'em".uppercased() let USABraceletsDistribPie = PieChart(frame: pieChartFrame) USABraceletsDistribPie.data = generator.USAvsWorldWins.pieChartData diff --git a/TournamentStats/UI/reports/InfographyView.xib b/TournamentStats/UI/reports/InfographyView.xib index deb036f..23cf802 100644 --- a/TournamentStats/UI/reports/InfographyView.xib +++ b/TournamentStats/UI/reports/InfographyView.xib @@ -17,7 +17,7 @@ - + + + + + + + + + + + + + + - + - + @@ -75,7 +88,7 @@ - + - + @@ -121,7 +134,7 @@ - + - + @@ -157,7 +170,7 @@ - + - + @@ -193,7 +206,7 @@ - + - + @@ -240,6 +253,7 @@ + @@ -274,7 +288,7 @@ - + diff --git a/TournamentStats/UI/reports/StatCollectionViewCell.swift b/TournamentStats/UI/reports/StatCollectionViewCell.swift new file mode 100644 index 0000000..fca4bc4 --- /dev/null +++ b/TournamentStats/UI/reports/StatCollectionViewCell.swift @@ -0,0 +1,17 @@ +// +// StatCollectionViewCell.swift +// TournamentStats +// +// Created by Laurent Morvillier on 27/08/2019. +// Copyright © 2019 Stax River. All rights reserved. +// + +import Foundation +import UIKit + +class StatCollectionViewCell: UICollectionViewCell { + + @IBOutlet weak var nameLabel: UILabel! + @IBOutlet weak var valueLabel: UILabel! + +} diff --git a/TournamentStats/UI/reports/StatCollectionViewCell.xib b/TournamentStats/UI/reports/StatCollectionViewCell.xib new file mode 100644 index 0000000..27adcbb --- /dev/null +++ b/TournamentStats/UI/reports/StatCollectionViewCell.xib @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/TournamentStats/core/Formatters.swift b/TournamentStats/core/Formatters.swift index e691f87..1355bbc 100644 --- a/TournamentStats/core/Formatters.swift +++ b/TournamentStats/core/Formatters.swift @@ -44,6 +44,17 @@ extension Locale { class Formatter { + static var standard: NumberFormatter { + let c = NumberFormatter() + c.locale = Locale(identifier: "en_US") + c.usesGroupingSeparator = true + c.groupingSeparator = "," + c.decimalSeparator = "." + c.maximumFractionDigits = 0 + c.numberStyle = .decimal + return c + } + static var currency: NumberFormatter { let c = NumberFormatter() c.locale = Locale(identifier: "en_US") @@ -123,6 +134,10 @@ extension Int { extension Double { + var formatted: String { + return Formatter.standard.string(from: NSNumber(value: self)) ?? "" + } + var currencyFormatted: String { return Formatter.currency.string(from: NSNumber(value: self)) ?? "" } diff --git a/TournamentStats/report/Queries.swift b/TournamentStats/report/Queries.swift index 58d039f..e0f974d 100644 --- a/TournamentStats/report/Queries.swift +++ b/TournamentStats/report/Queries.swift @@ -12,6 +12,19 @@ import Realm class Queries { + static func festivalStats(realm: Realm) -> FestivalStats { + + let tournaments = realm.objects(Tournament.self) + + let stats = FestivalStats() + stats.cumulatedBuyins = tournaments.sum(ofProperty: "buyin") + stats.totalEntries = tournaments.sum(ofProperty: "entries") + stats.totalPrizePool = tournaments.sum(ofProperty: "prizepool") + stats.eventsCount = tournaments.count + + return stats + } + static func biggestWinners(realm: Realm) -> [CumulatedResults] { let players = realm.objects(Player.self) diff --git a/TournamentStats/report/ReportGenerator.swift b/TournamentStats/report/ReportGenerator.swift index 0b8f986..160ceb2 100644 --- a/TournamentStats/report/ReportGenerator.swift +++ b/TournamentStats/report/ReportGenerator.swift @@ -49,6 +49,7 @@ class ReportGenerator { } + var festivalStats: FestivalStats = FestivalStats() var biggestWinners: [CumulatedResults] = [] var mostWins: [CumulatedWins] = [] var mostCashes: [CumulatedResults] = [] @@ -72,6 +73,7 @@ class ReportGenerator { let realm = try! Realm() + self.festivalStats = Queries.festivalStats(realm: realm) self.biggestWinners = Queries.biggestWinners(realm: realm) self.mostWins = Queries.mostWins(realm: realm) self.mostCashes = Queries.mostCashes(realm: realm) diff --git a/TournamentStats/report/structures/CumulatedResults.swift b/TournamentStats/report/structures/CumulatedResults.swift index f4d825d..9b6dab5 100644 --- a/TournamentStats/report/structures/CumulatedResults.swift +++ b/TournamentStats/report/structures/CumulatedResults.swift @@ -15,12 +15,16 @@ class CumulatedResults : HTMLRepresentable, ColumnRepresentable { var numberOfCashes: Int = 0 var results: [Result] = [] var winsCount: Int = 0 + var mainEventFinalist: Bool = false init(player: Player, average: Bool = false) { self.player = player for result in player.results { self.add(result: result) + if result.tournaments.first?.number == 73 && result.rank < 10 { + self.mainEventFinalist = true + } } if average { self.total = self.total / Double(self.numberOfCashes) @@ -43,7 +47,11 @@ class CumulatedResults : HTMLRepresentable, ColumnRepresentable { } func cellValues() -> [String] { - return [self.player.formattedName, self.total.currencyFormatted, "\(self.numberOfCashes)"] + var name = self.player.formattedName + if self.mainEventFinalist { + name += " *" + } + return [name, self.total.currencyFormatted, "\(self.numberOfCashes)"] } // static func htmlHeaders() -> String { diff --git a/TournamentStats/report/structures/FestivalStats.swift b/TournamentStats/report/structures/FestivalStats.swift new file mode 100644 index 0000000..1033ae8 --- /dev/null +++ b/TournamentStats/report/structures/FestivalStats.swift @@ -0,0 +1,64 @@ +// +// FestivalStats.swift +// TournamentStats +// +// Created by Laurent Morvillier on 27/08/2019. +// Copyright © 2019 Stax River. All rights reserved. +// + +import Foundation +import UIKit + +class FestivalStats : NSObject, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout { + + var eventsCount: Int = 0 + var totalPrizePool: Double = 0.0 + var totalEntries: Double = 0.0 + var cumulatedBuyins: Double = 0.0 + + // MARK: - UICollectionViewDataSource + + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + return 4 + } + + 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 = "Total Events" + value = "\(eventsCount)" + case 1: + name = "Total Prizepool".uppercased() + value = self.totalPrizePool.currencyFormatted + case 2: + name = "Total Entries".uppercased() + value = self.totalEntries.formatted + case 3: + name = "Cumulated Buy-ins".uppercased() + value = self.cumulatedBuyins.currencyFormatted + 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 = UIFont.systemFont(ofSize: 20.0) + cell.valueLabel.font = UIFont.systemFont(ofSize: 56.0, weight: .thin) + + return cell + } + + + func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { + return CGSize(width: 360.0, height: 100.0) + } + +}