Improved most wins, etc...

master
Laurent 6 years ago
parent 71dd1c898e
commit c8096582bc
  1. 17
      TournamentStats/AppDelegate.swift
  2. 33
      TournamentStats/Seed.swift
  3. 11
      TournamentStats/UI/reports/InfographyView.swift
  4. 62
      TournamentStats/UI/reports/InfographyView.xib
  5. 18
      TournamentStats/realm/Model.swift
  6. 3
      TournamentStats/report/Queries.swift
  7. 6
      TournamentStats/report/ReportGenerator.swift
  8. 206
      TournamentStats/report/structures/PlayerNotableFinishes.swift
  9. 6
      TournamentStats/report/structures/TournamentRepresentable.swift

@ -18,14 +18,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
for fontFamilyName in UIFont.familyNames {
print("family: \(fontFamilyName)\n")
for fontName in UIFont.fontNames(forFamilyName: fontFamilyName) {
print("font: \(fontName)")
}
}
// for fontFamilyName in UIFont.familyNames {
// print("family: \(fontFamilyName)\n")
//
// for fontName in UIFont.fontNames(forFamilyName: fontFamilyName) {
// print("font: \(fontName)")
// }
// }
// UI stuff
let splitViewController = window!.rootViewController as! UISplitViewController
@ -45,7 +44,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele
print("start report generation...")
let s = Date()
let generator = ReportGenerator()
generator.go(importData: false)
generator.go(importData: true)
let d = Date().timeIntervalSince(s)
print("reports created in \(d)s")

@ -12,12 +12,33 @@ import RealmSwift
import Realm
struct TD {
init(date: String, name: String, number: Int, buyin: Int, entries: Int, prizePool: Double, tableSize: Int) {
self.date = date
self.name = name
self.number = number
self.buyin = buyin
self.entries = entries
self.prizePool = prizePool
self.tableSize = tableSize
}
init(date: String, name: String, number: Int, buyin: Int, entries: Int, prizePool: Double) {
self.date = date
self.name = name
self.number = number
self.buyin = buyin
self.entries = entries
self.prizePool = prizePool
}
var date: String = ""
var name: String = ""
var number: Int = 0
var buyin: Int = 0
var entries: Int = 0
var prizePool: Double = 0
var tableSize: Int = 9
}
class Seed {
@ -80,7 +101,7 @@ class Seed {
TD(date: "26/06/2019", name: "No-Limit Hold'em Super Turbo Bounty", number: 56, buyin: 1500, entries: 1867, prizePool: 2520450),
TD(date: "27/06/2019", name: "Monster Stack No-Limit Hold'em", number: 50, buyin: 1500, entries: 6035, prizePool: 8147250),
TD(date: "27/06/2019", name: "Tag Team No-Limit Hold'em", number: 57, buyin: 1000, entries: 976, prizePool: 878400),
TD(date: "29/06/2019", name: "Poker Players Championship", number: 58, buyin: 50000, entries: 74, prizePool: 3552000),
TD(date: "29/06/2019", name: "Poker Players Championship", number: 58, buyin: 50000, entries: 74, prizePool: 3552000, tableSize: 6),
TD(date: "29/06/2019", name: "No-Limit Hold'em DEEPSTACK CHAMPIONSHIP", number: 59, buyin: 600, entries: 6140, prizePool: 3223500),
TD(date: "29/06/2019", name: "Pot-Limit Omaha Hi/Lo 8 or Better", number: 60, buyin: 1500, entries: 1117, prizePool: 1507950),
TD(date: "30/06/2019", name: "Razz", number: 62, buyin: 10000, entries: 116, prizePool: 1090400),
@ -127,6 +148,16 @@ class Seed {
for td in tournamentsDescriptions {
let event: Tournament = realm.create(Tournament.self)
event.name = td.name
event.tableSize = td.tableSize
if td.name.contains("6-Handed") {
event.tableSize = 6
} else if td.name.contains("8-Handed") {
event.tableSize = 8
} else if td.name.contains("Heads-Up") {
event.tableSize = 2
}
event.date = Formatter.basicDate.date(from: td.date) ?? Date()
event.number = td.number
event.buyin = td.buyin

@ -31,7 +31,8 @@ class InfographyView: UIView {
@IBOutlet weak var tableView12: TableView!
@IBOutlet weak var tableView13: TableView!
@IBOutlet weak var mostCollectionView: UICollectionView!
@IBOutlet weak var mostTableView: TableView!
@IBOutlet weak var mostTableView2: TableView!
@IBOutlet weak var hStack2a: UIStackView!
@IBOutlet weak var label21: UILabel!
@ -106,9 +107,11 @@ class InfographyView: UIView {
/////
self.mostCollectionView.register(UINib(nibName: "StatCollectionViewCell", bundle: Bundle.main), forCellWithReuseIdentifier: "Stat")
self.mostCollectionView.delegate = generator.rankings
self.mostCollectionView.dataSource = generator.rankings
self.mostTableView.delegate = generator.rankings1
self.mostTableView.dataSource = generator.rankings1
self.mostTableView2.delegate = generator.rankings2
self.mostTableView2.dataSource = generator.rankings2
/////

@ -17,7 +17,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="w79-xx-Evx">
<rect key="frame" x="100" y="44" width="1300" height="3720"/>
<rect key="frame" x="100" y="44" width="1300" height="4120"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="2019 WSOP" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="4Hu-Ou-nFd">
<rect key="frame" x="0.0" y="0.0" width="1300" height="100"/>
@ -40,7 +40,7 @@
<rect key="frame" x="0.0" y="170" width="1300" height="500"/>
<subviews>
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" contentInsetAdjustmentBehavior="always" dataMode="none" translatesAutoresizingMaskIntoConstraints="NO" id="Vh3-97-zuO">
<rect key="frame" x="0.0" y="0.0" width="575.5" height="500"/>
<rect key="frame" x="0.0" y="0.0" width="578" height="500"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<inset key="scrollIndicatorInsets" minX="0.0" minY="40" maxX="0.0" maxY="0.0"/>
<collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="10" minimumInteritemSpacing="10" sectionInsetReference="safeArea" id="O06-sl-CBC">
@ -51,11 +51,11 @@
</collectionViewFlowLayout>
</collectionView>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="grouped" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="18" sectionFooterHeight="18" translatesAutoresizingMaskIntoConstraints="NO" id="HbR-TC-HeD" customClass="TableView" customModule="TournamentStats" customModuleProvider="target">
<rect key="frame" x="591.5" y="0.0" width="576.5" height="500"/>
<rect key="frame" x="594" y="0.0" width="579" height="500"/>
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
</tableView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="IqT-2X-roS">
<rect key="frame" x="1184" y="0.0" width="116" height="500"/>
<rect key="frame" x="1189" y="0.0" width="111" height="500"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
</subviews>
@ -63,21 +63,24 @@
<constraint firstAttribute="height" constant="500" id="LQg-JD-2Lr"/>
</constraints>
</stackView>
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="none" translatesAutoresizingMaskIntoConstraints="NO" id="Abi-te-aH2">
<rect key="frame" x="0.0" y="680" width="1300" height="300"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillProportionally" spacing="100" translatesAutoresizingMaskIntoConstraints="NO" id="l2y-sT-HQT">
<rect key="frame" x="0.0" y="680" width="1300" height="700"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="uYQ-6Z-Rb4" customClass="TableView" customModule="TournamentStats" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="603.5" height="700"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</tableView>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="ubP-cm-Sbp" customClass="TableView" customModule="TournamentStats" customModuleProvider="target">
<rect key="frame" x="703.5" y="0.0" width="596.5" height="700"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</tableView>
</subviews>
<constraints>
<constraint firstAttribute="height" constant="300" id="MTT-GP-Dkf"/>
<constraint firstAttribute="height" constant="700" id="NZj-7i-hbE"/>
</constraints>
<collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="10" minimumInteritemSpacing="10" id="KiK-op-wrT">
<size key="itemSize" width="50" height="50"/>
<size key="headerReferenceSize" width="0.0" height="0.0"/>
<size key="footerReferenceSize" width="0.0" height="0.0"/>
<inset key="sectionInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/>
</collectionViewFlowLayout>
</collectionView>
</stackView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Xrv-gg-4dD" userLabel="Space">
<rect key="frame" x="0.0" y="990" width="1300" height="50"/>
<rect key="frame" x="0.0" y="1390" width="1300" height="50"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="height" constant="50" id="z1Q-lp-yMy"/>
@ -85,7 +88,7 @@
<viewLayoutGuide key="safeArea" id="x7x-j2-Rbi"/>
</view>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="50" translatesAutoresizingMaskIntoConstraints="NO" id="NbO-FE-SHj">
<rect key="frame" x="0.0" y="1050" width="1300" height="300"/>
<rect key="frame" x="0.0" y="1450" width="1300" height="300"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="grouped" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="18" sectionFooterHeight="18" translatesAutoresizingMaskIntoConstraints="NO" id="M2m-xf-le9" customClass="TableView" customModule="TournamentStats" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="625" height="300"/>
@ -101,7 +104,7 @@
</constraints>
</stackView>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillProportionally" translatesAutoresizingMaskIntoConstraints="NO" id="91U-hc-Oqn">
<rect key="frame" x="0.0" y="1360" width="1300" height="40"/>
<rect key="frame" x="0.0" y="1760" width="1300" height="40"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Hcr-dr-rUz" customClass="Label" customModule="TournamentStats" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="650" height="40"/>
@ -121,7 +124,7 @@
</constraints>
</stackView>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="16" translatesAutoresizingMaskIntoConstraints="NO" id="4u9-3E-Qwu">
<rect key="frame" x="0.0" y="1410" width="1300" height="450"/>
<rect key="frame" x="0.0" y="1810" width="1300" height="450"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Zmk-PV-di2">
<rect key="frame" x="0.0" y="0.0" width="642" height="450"/>
@ -137,7 +140,7 @@
</constraints>
</stackView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Zdb-H8-Dy2" userLabel="Space">
<rect key="frame" x="0.0" y="1870" width="1300" height="40"/>
<rect key="frame" x="0.0" y="2270" width="1300" height="40"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="height" constant="40" id="mp4-0v-Scg"/>
@ -145,7 +148,7 @@
<viewLayoutGuide key="safeArea" id="DfJ-ph-q9S"/>
</view>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="16" translatesAutoresizingMaskIntoConstraints="NO" id="ucv-f0-P2r">
<rect key="frame" x="0.0" y="1920" width="1300" height="280"/>
<rect key="frame" x="0.0" y="2320" width="1300" height="280"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="grouped" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="18" sectionFooterHeight="18" translatesAutoresizingMaskIntoConstraints="NO" id="0h6-mp-rHD" customClass="TableView" customModule="TournamentStats" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="1300" height="280"/>
@ -157,7 +160,7 @@
</constraints>
</stackView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="fZP-2C-MlN" userLabel="Space">
<rect key="frame" x="0.0" y="2210" width="1300" height="40"/>
<rect key="frame" x="0.0" y="2610" width="1300" height="40"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="height" constant="40" id="G0u-JL-8Ed"/>
@ -165,7 +168,7 @@
<viewLayoutGuide key="safeArea" id="3AK-Jb-LaH"/>
</view>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="16" translatesAutoresizingMaskIntoConstraints="NO" id="JSX-zY-CFg">
<rect key="frame" x="0.0" y="2260" width="1300" height="280"/>
<rect key="frame" x="0.0" y="2660" width="1300" height="280"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="grouped" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="18" sectionFooterHeight="18" translatesAutoresizingMaskIntoConstraints="NO" id="h84-Ta-8eQ" customClass="TableView" customModule="TournamentStats" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="1300" height="280"/>
@ -177,7 +180,7 @@
</constraints>
</stackView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Tt8-Z5-vVb" userLabel="Space">
<rect key="frame" x="0.0" y="2550" width="1300" height="40"/>
<rect key="frame" x="0.0" y="2950" width="1300" height="40"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="height" constant="40" id="vnz-WB-g1y"/>
@ -185,7 +188,7 @@
<viewLayoutGuide key="safeArea" id="HMN-3V-5QB"/>
</view>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillProportionally" translatesAutoresizingMaskIntoConstraints="NO" id="WFa-d3-zcU">
<rect key="frame" x="0.0" y="2600" width="1300" height="40"/>
<rect key="frame" x="0.0" y="3000" width="1300" height="40"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="aSt-Fm-PHF" customClass="Label" customModule="TournamentStats" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="584" height="40"/>
@ -205,7 +208,7 @@
</constraints>
</stackView>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="16" translatesAutoresizingMaskIntoConstraints="NO" id="9WN-7G-oBN">
<rect key="frame" x="0.0" y="2650" width="1300" height="500"/>
<rect key="frame" x="0.0" y="3050" width="1300" height="500"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="YMb-PS-dFz">
<rect key="frame" x="0.0" y="0.0" width="642" height="500"/>
@ -221,7 +224,7 @@
</constraints>
</stackView>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillProportionally" translatesAutoresizingMaskIntoConstraints="NO" id="myS-g5-vsP">
<rect key="frame" x="0.0" y="3160" width="1300" height="50"/>
<rect key="frame" x="0.0" y="3560" width="1300" height="50"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="mDV-nN-W7V" customClass="Label" customModule="TournamentStats" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="650" height="50"/>
@ -241,7 +244,7 @@
</constraints>
</stackView>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="16" translatesAutoresizingMaskIntoConstraints="NO" id="2iy-YX-agg">
<rect key="frame" x="0.0" y="3220" width="1300" height="500"/>
<rect key="frame" x="0.0" y="3620" width="1300" height="500"/>
<subviews>
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="none" translatesAutoresizingMaskIntoConstraints="NO" id="tVi-Bi-Ese">
<rect key="frame" x="0.0" y="0.0" width="422.5" height="500"/>
@ -298,7 +301,8 @@
<outlet property="label41" destination="aSt-Fm-PHF" id="43C-8N-8Xk"/>
<outlet property="label42" destination="wcd-nU-zRB" id="WAR-I1-Bej"/>
<outlet property="label51" destination="mDV-nN-W7V" id="QlS-da-9bL"/>
<outlet property="mostCollectionView" destination="Abi-te-aH2" id="1Hl-KG-3Ix"/>
<outlet property="mostTableView" destination="uYQ-6Z-Rb4" id="Jeb-OU-Gj8"/>
<outlet property="mostTableView2" destination="ubP-cm-Sbp" id="a9y-yZ-4EW"/>
<outlet property="tableView11" destination="HbR-TC-HeD" id="P5k-OS-JgN"/>
<outlet property="tableView12" destination="M2m-xf-le9" id="ze0-w3-ZA8"/>
<outlet property="tableView13" destination="Vdb-nD-4Cy" id="XXM-W3-Hu0"/>

@ -23,19 +23,7 @@ class Tournament : Object, Named {
@objc dynamic var number: Int = 0
@objc dynamic var buyin: Int = 0
@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
}
}
}
@objc dynamic var name: String = ""
let results = List<Result>()
@objc dynamic var prizepool: Double = 0.0
@ -50,6 +38,10 @@ class Tournament : Object, Named {
}
}
var formatted: String {
return "#\(self.number): \(self.buyin.currencyFormatted) \(self.name)"
}
}
class Player : Object, Named {

@ -316,7 +316,8 @@ class Queries {
case 2:
runnerUps.append(result)
default:
if result.rank <= result.tournaments.first?.tableSize ?? 10 {
let tableSize: Int = result.tournaments.first?.tableSize ?? 9
if result.rank <= tableSize {
finalTables.append(result)
}
}

@ -66,7 +66,8 @@ class ReportGenerator {
var tournamentPrizepoolDistribution: [DistributionCounter] = []
var firstPrizeDistribution: [DistributionCounter] = []
var gamesDistribution: [DistributionCounter] = []
var rankings: PlayerNotableFinishesDataSource = PlayerNotableFinishesDataSource(notableFinishes: [])
var rankings1: PlayerNotableFinishesDataSource = PlayerNotableFinishesDataSource(notableFinishes: [], finalTables: false)
var rankings2: PlayerNotableFinishesDataSource = PlayerNotableFinishesDataSource(notableFinishes: [], finalTables: true)
func generateReports() {
@ -91,7 +92,8 @@ class ReportGenerator {
self.tournamentPrizepoolDistribution = Queries.tournamentPrizepoolDistribution(realm: realm)
self.firstPrizeDistribution = Queries.firstPrizeDistribution(realm: realm)
self.gamesDistribution = Queries.holdemTournamentsDistribution(realm: realm)
self.rankings = PlayerNotableFinishesDataSource(notableFinishes: Queries.rankingCounts(realm: realm))
self.rankings1 = PlayerNotableFinishesDataSource(notableFinishes: Queries.rankingCounts(realm: realm), finalTables: false)
self.rankings2 = PlayerNotableFinishesDataSource(notableFinishes: Queries.rankingCounts(realm: realm), finalTables: true)
let tourniesDate = realm.objects(Tournament.self).distinct(by: ["date"])

@ -18,88 +18,168 @@ struct PlayerNotableFinishes {
}
class PlayerNotableFinishesDataSource : NSObject, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
class PlayerNotableFinishesDataSource : NSObject, UITableViewDataSource, UITableViewDelegate {
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 mostWins: [PlayerNotableFinishes] = []
var mostWinsCount: Int = 0
var mostRunnerUps: [PlayerNotableFinishes] = []
var mostRunnerUpsCount: Int = 0
var mostFinalTables: [PlayerNotableFinishes] = []
var mostFinalTablesCount: Int = 0
///////
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 winsDisplay: [(String, UIFont)] = []
var runnerUpsDisplay: [(String, UIFont)] = []
///////
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 }
let finalTables: Bool
///////
var nFinalTables = notableFinishes
nFinalTables.sort { (p1, p2) -> Bool in
return p1.finalTables.count > p2.finalTables.count
init(notableFinishes: [PlayerNotableFinishes], finalTables: Bool) {
self.notableFinishes = notableFinishes
self.finalTables = finalTables
if finalTables {
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 }
self.mostFinalTablesCount = finalTablesTopCount
} else {
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}
for win in self.mostWins {
self.winsDisplay.append((win.player.formattedName, Fonts.subTitle))
for result in win.wins {
if let tournamentName = result.tournaments.first?.formatted {
self.winsDisplay.append((" " + tournamentName, Fonts.regular))
} else {
self.winsDisplay.append(("no tournament!!!", Fonts.regular))
}
}
}
///////
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 }
for runnerup in self.mostRunnerUps {
self.runnerUpsDisplay.append((runnerup.player.formattedName, Fonts.subTitle))
for result in runnerup.runnerUps {
if let tournamentName = result.tournaments.first?.formatted {
self.runnerUpsDisplay.append((" " + tournamentName, Fonts.regular))
} else {
self.runnerUpsDisplay.append(("no tournament!!!", Fonts.regular))
}
}
}
self.mostWinsCount = winsTopCount
self.mostRunnerUpsCount = runnerUpsTopCount
}
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
// MARK - Table
func numberOfSections(in tableView: UITableView) -> Int {
return self.finalTables ? 1 : 2
}
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 = ""
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if self.finalTables {
return self.mostFinalTables.count
} else {
switch section {
case 0:
return self.winsDisplay.count
case 1:
return self.runnerUpsDisplay.count
default:
return self.mostFinalTables.count
}
}
}
cell.nameLabel.text = name.uppercased()
cell.valueLabel.text = value
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
cell.backgroundColor = UIColor.clear
cell.textLabel?.textColor = UIColor.white
let font: UIFont
let text: String
if self.finalTables {
text = self.mostFinalTables[indexPath.row].player.formattedName
font = Fonts.regular
} else {
switch indexPath.section {
case 0:
text = self.winsDisplay[indexPath.row].0
font = self.winsDisplay[indexPath.row].1
case 1:
text = self.runnerUpsDisplay[indexPath.row].0
font = self.runnerUpsDisplay[indexPath.row].1
case 2:
text = self.mostFinalTables[indexPath.row].player.formattedName
font = Fonts.regular
default:
text = "problem"
font = Fonts.regular
}
}
cell.textLabel?.text = text
cell.textLabel?.font = font
return cell
}
cell.nameLabel.textColor = UIColor.white
cell.valueLabel.textColor = UIColor.white
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let text: String
if self.finalTables {
text = "Most final tables - \(self.mostFinalTablesCount)"
} else {
switch section {
case 0:
text = "Most wins - \(self.mostWinsCount) bracelets"
case 1:
text = "Most runner-ups - \(self.mostRunnerUpsCount)"
default:
text = "Most final tables - \(self.mostFinalTablesCount)"
}
}
cell.nameLabel.font = Fonts.regular
cell.valueLabel.font = Fonts.bigNumbers
return self.headerLabel(text: text)
}
return cell
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 60.0
}
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 40.0
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: 800.0, height: 90.0)
func headerLabel(text: String) -> UILabel {
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 500.0, height: 60.0))
label.textColor = UIColor.white
label.font = Fonts.subTitle
label.text = text
return label
}
}

@ -13,11 +13,11 @@ struct TournamentRepresentable : HTMLRepresentable {
var tournament: Tournament
func columnDescriptors() -> [ColumnDescriptor] {
return [ColumnDescriptor(header: "#", number: true, widthWeight: 0.3),
ColumnDescriptor(header: "Buy-in", number: true, widthWeight: 0.5),
return [ColumnDescriptor(header: "#", number: true, widthWeight: 0.2),
ColumnDescriptor(header: "Buy-in", number: true, widthWeight: 0.4),
ColumnDescriptor(header: "Event", number: false, widthWeight: 2.6),
ColumnDescriptor(header: "Prizepool", number: true, widthWeight: 1.0),
ColumnDescriptor(header: "Entries", number: true, widthWeight: 0.6)]
ColumnDescriptor(header: "Entries", number: true, widthWeight: 0.4)]
}
func cellValues() -> [String] {

Loading…
Cancel
Save