Many improvements

master
Laurent 6 years ago
parent c8096582bc
commit 5b202bbbff
  1. 2
      TournamentStats/AppDelegate.swift
  2. 24
      TournamentStats/UI/Fonts.swift
  3. 31
      TournamentStats/UI/reports/InfographyView.swift
  4. 74
      TournamentStats/UI/reports/InfographyView.xib
  5. 2
      TournamentStats/realm/Model.swift
  6. 45
      TournamentStats/report/Queries.swift
  7. 14
      TournamentStats/report/ReportGenerator.swift
  8. 103
      TournamentStats/report/structures/CumulatedResults.swift
  9. 177
      TournamentStats/report/structures/PlayerNotableFinishes.swift
  10. 12
      TournamentStats/utils/ColumnRepresentable.swift
  11. 2
      TournamentStats/utils/Game.swift

@ -44,7 +44,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele
print("start report generation...") print("start report generation...")
let s = Date() let s = Date()
let generator = ReportGenerator() let generator = ReportGenerator()
generator.go(importData: true) generator.go(importData: false)
let d = Date().timeIntervalSince(s) let d = Date().timeIntervalSince(s)
print("reports created in \(d)s") print("reports created in \(d)s")

@ -11,14 +11,22 @@ import UIKit
class Fonts { class Fonts {
static let monospaced: UIFont = UIFont(name: "Menlo-Regular", size: 18.0)! // UIFont.systemFont(ofSize: 18.0) fileprivate enum FontName : String {
static let bigNumbers: UIFont = UIFont(name: "Menlo-Regular", size: 48.0)! case regular = "Menlo-Regular"
case bold = "Menlo-Bold"
}
static let regular: UIFont = UIFont(name: "Menlo-Regular", size: 18.0)! // UIFont.systemFont(ofSize: 18.0) static let monospaced: UIFont = UIFont(name: FontName.regular.rawValue, size: 18.0)!
static let bold: UIFont = UIFont(name: "Menlo-Bold", size: 18.0)! // UIFont.systemFont(ofSize: 18.0) static let bigNumbers: UIFont = UIFont(name: FontName.regular.rawValue, size: 48.0)!
static let mainTitle: UIFont = UIFont(name: "Menlo-Regular", size: 72.0)! //UIFont.systemFont(ofSize: 72.0)
static let subTitle: UIFont = UIFont(name: "Menlo-Regular", size: 28.0)! //UIFont.systemFont(ofSize: 24.0) static let regular: UIFont = UIFont(name: FontName.regular.rawValue, size: 18.0)!
static let pieChartEntries: UIFont = UIFont(name: "Menlo-Bold", size: 28.0)! //UIFont.boldSystemFont(ofSize: 28) static let bold: UIFont = UIFont(name: FontName.bold.rawValue, size: 18.0)!
static let chartLegend: UIFont = UIFont(name: "Menlo-Regular", size: 18.0)! // UIFont.systemFont(ofSize: 18.0)
static let mainTitle: UIFont = UIFont(name: FontName.regular.rawValue, size: 72.0)!
static let subTitle: UIFont = UIFont(name: FontName.regular.rawValue, size: 28.0)!
static let cellTitle: UIFont = UIFont(name: FontName.regular.rawValue, size: 20.0)!
static let pieChartEntries: UIFont = UIFont(name: FontName.bold.rawValue, size: 28.0)!
static let chartLegend: UIFont = UIFont(name: FontName.regular.rawValue, size: 18.0)! //
} }

@ -76,18 +76,19 @@ class InfographyView: UIView {
fileprivate func _createBackground() { fileprivate func _createBackground() {
let gradient: CAGradientLayer = CAGradientLayer()
let startColor = UIColor(red: 23/255, green: 72/255, blue: 61/255, alpha: 1) 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) // let endColor = UIColor(red: 47/255, green: 149/255, blue: 126/255, alpha: 1)
gradient.colors = [startColor.cgColor, endColor.cgColor] self.backgroundColor = startColor
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) // 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)
} }
@ -110,19 +111,19 @@ class InfographyView: UIView {
self.mostTableView.delegate = generator.rankings1 self.mostTableView.delegate = generator.rankings1
self.mostTableView.dataSource = generator.rankings1 self.mostTableView.dataSource = generator.rankings1
self.mostTableView2.delegate = generator.rankings2 self.mostTableView2.setHeader(header: "Most final tables")
self.mostTableView2.dataSource = generator.rankings2 self.mostTableView2.setData(data: generator.finalTables, maxRows: 10)
///// /////
self.tableView11.setData(data: generator.biggestWinners) self.tableView11.setData(data: generator.biggestWinners)
self.tableView11.setHeader(header: "Biggest Winners") self.tableView11.setHeader(header: "Biggest winners")
self.tableView11.setFooter(footer: "* denotes a Main Event finalist") self.tableView11.setFooter(footer: "* denotes a Main Event finalist")
self.tableView12.setData(data: generator.mostCashes, maxRows: 5) self.tableView12.setData(data: generator.mostCashes, maxRows: 5)
self.tableView12.setHeader(header: "Most Cashes") self.tableView12.setHeader(header: "Most cashes")
self.tableView13.setData(data: generator.averageCash, maxRows: 5) self.tableView13.setData(data: generator.averageCash, maxRows: 5)
self.tableView13.setHeader(header: "Best average cash (7+)") self.tableView13.setHeader(header: "Best average cash (8+)")
///// /////
@ -153,7 +154,7 @@ class InfographyView: UIView {
///// /////
self.label41.text = "USA vs World bracelets" self.label41.text = "USA vs World bracelets"
self.label42.text = "Hold'em vs not Hold'em" self.label42.text = "Games distribution"
let USABraceletsDistribPie = PieChart(frame: pieChartFrame) let USABraceletsDistribPie = PieChart(frame: pieChartFrame)
USABraceletsDistribPie.data = generator.USAvsWorldWins.pieChartData USABraceletsDistribPie.data = generator.USAvsWorldWins.pieChartData

@ -17,7 +17,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="w79-xx-Evx"> <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="4120"/> <rect key="frame" x="100" y="44" width="1300" height="4080"/>
<subviews> <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"> <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"/> <rect key="frame" x="0.0" y="0.0" width="1300" height="100"/>
@ -63,24 +63,32 @@
<constraint firstAttribute="height" constant="500" id="LQg-JD-2Lr"/> <constraint firstAttribute="height" constant="500" id="LQg-JD-2Lr"/>
</constraints> </constraints>
</stackView> </stackView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="39t-LC-qXh" userLabel="Space">
<rect key="frame" x="0.0" y="680" width="1300" height="50"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="height" constant="50" id="w2j-e8-Hfu"/>
</constraints>
<viewLayoutGuide key="safeArea" id="xzI-Ex-mMX"/>
</view>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillProportionally" spacing="100" translatesAutoresizingMaskIntoConstraints="NO" id="l2y-sT-HQT"> <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"/> <rect key="frame" x="0.0" y="740" width="1300" height="560"/>
<subviews> <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"> <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"/> <rect key="frame" x="0.0" y="0.0" width="603.5" height="560"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</tableView> </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"> <tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="grouped" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="18" sectionFooterHeight="18" 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"/> <rect key="frame" x="703.5" y="0.0" width="596.5" height="560"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> <color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
</tableView> </tableView>
</subviews> </subviews>
<constraints> <constraints>
<constraint firstAttribute="height" constant="700" id="NZj-7i-hbE"/> <constraint firstAttribute="height" constant="560" id="NZj-7i-hbE"/>
</constraints> </constraints>
</stackView> </stackView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Xrv-gg-4dD" userLabel="Space"> <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Xrv-gg-4dD" userLabel="Space">
<rect key="frame" x="0.0" y="1390" width="1300" height="50"/> <rect key="frame" x="0.0" y="1310" width="1300" height="50"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints> <constraints>
<constraint firstAttribute="height" constant="50" id="z1Q-lp-yMy"/> <constraint firstAttribute="height" constant="50" id="z1Q-lp-yMy"/>
@ -88,7 +96,7 @@
<viewLayoutGuide key="safeArea" id="x7x-j2-Rbi"/> <viewLayoutGuide key="safeArea" id="x7x-j2-Rbi"/>
</view> </view>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="50" translatesAutoresizingMaskIntoConstraints="NO" id="NbO-FE-SHj"> <stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="50" translatesAutoresizingMaskIntoConstraints="NO" id="NbO-FE-SHj">
<rect key="frame" x="0.0" y="1450" width="1300" height="300"/> <rect key="frame" x="0.0" y="1370" width="1300" height="300"/>
<subviews> <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"> <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"/> <rect key="frame" x="0.0" y="0.0" width="625" height="300"/>
@ -103,28 +111,36 @@
<constraint firstAttribute="height" constant="300" id="N0D-Z0-uH0"/> <constraint firstAttribute="height" constant="300" id="N0D-Z0-uH0"/>
</constraints> </constraints>
</stackView> </stackView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="gTW-Xs-enM" userLabel="Space">
<rect key="frame" x="0.0" y="1680" width="1300" height="40"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="height" constant="40" id="DCa-vu-Hao"/>
</constraints>
<viewLayoutGuide key="safeArea" id="PMJ-8b-M0C"/>
</view>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillProportionally" translatesAutoresizingMaskIntoConstraints="NO" id="91U-hc-Oqn"> <stackView opaque="NO" contentMode="scaleToFill" distribution="fillProportionally" translatesAutoresizingMaskIntoConstraints="NO" id="91U-hc-Oqn">
<rect key="frame" x="0.0" y="1760" width="1300" height="40"/> <rect key="frame" x="0.0" y="1730" width="1300" height="30"/>
<subviews> <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"> <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"/> <rect key="frame" x="0.0" y="0.0" width="650" height="30"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/> <fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/> <nil key="textColor"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
</label> </label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="2yf-Z5-Tpy" customClass="Label" customModule="TournamentStats" customModuleProvider="target"> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="2yf-Z5-Tpy" customClass="Label" customModule="TournamentStats" customModuleProvider="target">
<rect key="frame" x="650" y="0.0" width="650" height="40"/> <rect key="frame" x="650" y="0.0" width="650" height="30"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/> <fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/> <nil key="textColor"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
</label> </label>
</subviews> </subviews>
<constraints> <constraints>
<constraint firstAttribute="height" constant="40" id="RgL-e2-Q4s"/> <constraint firstAttribute="height" constant="30" id="RgL-e2-Q4s"/>
</constraints> </constraints>
</stackView> </stackView>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="16" translatesAutoresizingMaskIntoConstraints="NO" id="4u9-3E-Qwu"> <stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="16" translatesAutoresizingMaskIntoConstraints="NO" id="4u9-3E-Qwu">
<rect key="frame" x="0.0" y="1810" width="1300" height="450"/> <rect key="frame" x="0.0" y="1770" width="1300" height="450"/>
<subviews> <subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Zmk-PV-di2"> <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Zmk-PV-di2">
<rect key="frame" x="0.0" y="0.0" width="642" height="450"/> <rect key="frame" x="0.0" y="0.0" width="642" height="450"/>
@ -140,7 +156,7 @@
</constraints> </constraints>
</stackView> </stackView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Zdb-H8-Dy2" userLabel="Space"> <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Zdb-H8-Dy2" userLabel="Space">
<rect key="frame" x="0.0" y="2270" width="1300" height="40"/> <rect key="frame" x="0.0" y="2230" width="1300" height="40"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints> <constraints>
<constraint firstAttribute="height" constant="40" id="mp4-0v-Scg"/> <constraint firstAttribute="height" constant="40" id="mp4-0v-Scg"/>
@ -148,7 +164,7 @@
<viewLayoutGuide key="safeArea" id="DfJ-ph-q9S"/> <viewLayoutGuide key="safeArea" id="DfJ-ph-q9S"/>
</view> </view>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="16" translatesAutoresizingMaskIntoConstraints="NO" id="ucv-f0-P2r"> <stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="16" translatesAutoresizingMaskIntoConstraints="NO" id="ucv-f0-P2r">
<rect key="frame" x="0.0" y="2320" width="1300" height="280"/> <rect key="frame" x="0.0" y="2280" width="1300" height="280"/>
<subviews> <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"> <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"/> <rect key="frame" x="0.0" y="0.0" width="1300" height="280"/>
@ -160,7 +176,7 @@
</constraints> </constraints>
</stackView> </stackView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="fZP-2C-MlN" userLabel="Space"> <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="fZP-2C-MlN" userLabel="Space">
<rect key="frame" x="0.0" y="2610" width="1300" height="40"/> <rect key="frame" x="0.0" y="2570" width="1300" height="40"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints> <constraints>
<constraint firstAttribute="height" constant="40" id="G0u-JL-8Ed"/> <constraint firstAttribute="height" constant="40" id="G0u-JL-8Ed"/>
@ -168,7 +184,7 @@
<viewLayoutGuide key="safeArea" id="3AK-Jb-LaH"/> <viewLayoutGuide key="safeArea" id="3AK-Jb-LaH"/>
</view> </view>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="16" translatesAutoresizingMaskIntoConstraints="NO" id="JSX-zY-CFg"> <stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="16" translatesAutoresizingMaskIntoConstraints="NO" id="JSX-zY-CFg">
<rect key="frame" x="0.0" y="2660" width="1300" height="280"/> <rect key="frame" x="0.0" y="2620" width="1300" height="280"/>
<subviews> <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"> <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"/> <rect key="frame" x="0.0" y="0.0" width="1300" height="280"/>
@ -180,24 +196,24 @@
</constraints> </constraints>
</stackView> </stackView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Tt8-Z5-vVb" userLabel="Space"> <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Tt8-Z5-vVb" userLabel="Space">
<rect key="frame" x="0.0" y="2950" width="1300" height="40"/> <rect key="frame" x="0.0" y="2910" width="1300" height="40"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints> <constraints>
<constraint firstAttribute="height" constant="40" id="vnz-WB-g1y"/> <constraint firstAttribute="height" constant="40" id="vnz-WB-g1y"/>
</constraints> </constraints>
<viewLayoutGuide key="safeArea" id="HMN-3V-5QB"/> <viewLayoutGuide key="safeArea" id="HMN-3V-5QB"/>
</view> </view>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillProportionally" translatesAutoresizingMaskIntoConstraints="NO" id="WFa-d3-zcU"> <stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" translatesAutoresizingMaskIntoConstraints="NO" id="WFa-d3-zcU">
<rect key="frame" x="0.0" y="3000" width="1300" height="40"/> <rect key="frame" x="0.0" y="2960" width="1300" height="40"/>
<subviews> <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"> <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"/> <rect key="frame" x="0.0" y="0.0" width="650" height="40"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/> <fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/> <nil key="textColor"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
</label> </label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="wcd-nU-zRB" customClass="Label" customModule="TournamentStats" customModuleProvider="target"> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="wcd-nU-zRB" customClass="Label" customModule="TournamentStats" customModuleProvider="target">
<rect key="frame" x="584" y="0.0" width="716" height="40"/> <rect key="frame" x="650" y="0.0" width="650" height="40"/>
<fontDescription key="fontDescription" name="Menlo-Regular" family="Menlo" pointSize="17"/> <fontDescription key="fontDescription" name="Menlo-Regular" family="Menlo" pointSize="17"/>
<nil key="textColor"/> <nil key="textColor"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
@ -208,7 +224,7 @@
</constraints> </constraints>
</stackView> </stackView>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="16" translatesAutoresizingMaskIntoConstraints="NO" id="9WN-7G-oBN"> <stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="16" translatesAutoresizingMaskIntoConstraints="NO" id="9WN-7G-oBN">
<rect key="frame" x="0.0" y="3050" width="1300" height="500"/> <rect key="frame" x="0.0" y="3010" width="1300" height="500"/>
<subviews> <subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="YMb-PS-dFz"> <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="YMb-PS-dFz">
<rect key="frame" x="0.0" y="0.0" width="642" height="500"/> <rect key="frame" x="0.0" y="0.0" width="642" height="500"/>
@ -223,16 +239,16 @@
<constraint firstAttribute="height" constant="500" id="TTR-HJ-gPu"/> <constraint firstAttribute="height" constant="500" id="TTR-HJ-gPu"/>
</constraints> </constraints>
</stackView> </stackView>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillProportionally" translatesAutoresizingMaskIntoConstraints="NO" id="myS-g5-vsP"> <stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" translatesAutoresizingMaskIntoConstraints="NO" id="myS-g5-vsP">
<rect key="frame" x="0.0" y="3560" width="1300" height="50"/> <rect key="frame" x="0.0" y="3520" width="1300" height="50"/>
<subviews> <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"> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" 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"/> <rect key="frame" x="0.0" y="0.0" width="650" height="50"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/> <fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/> <nil key="textColor"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
</label> </label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="7xF-BM-RBb" customClass="Label" customModule="TournamentStats" customModuleProvider="target"> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="7xF-BM-RBb" customClass="Label" customModule="TournamentStats" customModuleProvider="target">
<rect key="frame" x="650" y="0.0" width="650" height="50"/> <rect key="frame" x="650" y="0.0" width="650" height="50"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/> <fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/> <nil key="textColor"/>
@ -244,7 +260,7 @@
</constraints> </constraints>
</stackView> </stackView>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="16" translatesAutoresizingMaskIntoConstraints="NO" id="2iy-YX-agg"> <stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="16" translatesAutoresizingMaskIntoConstraints="NO" id="2iy-YX-agg">
<rect key="frame" x="0.0" y="3620" width="1300" height="500"/> <rect key="frame" x="0.0" y="3580" width="1300" height="500"/>
<subviews> <subviews>
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="none" translatesAutoresizingMaskIntoConstraints="NO" id="tVi-Bi-Ese"> <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"/> <rect key="frame" x="0.0" y="0.0" width="422.5" height="500"/>

@ -39,7 +39,7 @@ class Tournament : Object, Named {
} }
var formatted: String { var formatted: String {
return "#\(self.number): \(self.buyin.currencyFormatted) \(self.name)" return "#\(self.number) \(self.buyin.currencyFormatted) \(self.name)"
} }
} }

@ -39,13 +39,13 @@ class Queries {
}) })
} }
static func averageCash(realm: Realm) -> [CumulatedResults] { static func averageCash(realm: Realm, minCount: Int) -> [CumulatedResults] {
let players = realm.objects(Player.self).filter(NSPredicate(format: "results.@count > 6")) let players = realm.objects(Player.self).filter(NSPredicate(format: "results.@count >= %i", minCount))
var crArray: [CumulatedResults] = [] var crArray: [CumulatedResults] = []
for player in players { for player in players {
crArray.append(CumulatedResults(player: player, average: true)) crArray.append(CumulatedResults(player: player, options: [.average]))
} }
return crArray.sorted(by: { (cr1, cr2) -> Bool in return crArray.sorted(by: { (cr1, cr2) -> Bool in
@ -62,7 +62,7 @@ class Queries {
var crArray: [CumulatedResults] = [] var crArray: [CumulatedResults] = []
for player in players { for player in players {
crArray.append(CumulatedResults(player: player)) crArray.append(CumulatedResults(player: player, options: [.countSorted]))
} }
return crArray.sorted(by: { (cr1, cr2) -> Bool in return crArray.sorted(by: { (cr1, cr2) -> Bool in
@ -210,10 +210,10 @@ class Queries {
let tournaments: Results<Tournament> = realm.objects(Tournament.self) let tournaments: Results<Tournament> = realm.objects(Tournament.self)
let verylow = DistributionCounter(name: "< $1,000") let verylow = DistributionCounter(name: "<$1,000")
let low = DistributionCounter(name: "$1,000 - $1,999") let low = DistributionCounter(name: "$1,000 - $1,999")
let medium = DistributionCounter(name: "$2,000 - $5,000") let medium = DistributionCounter(name: "$2,000 - $5,000")
let high = DistributionCounter(name: "> $5,000") let high = DistributionCounter(name: ">$5,000")
let counters: [DistributionCounter] = [verylow, low, medium, high] let counters: [DistributionCounter] = [verylow, low, medium, high]
tournaments.forEach { tournament in tournaments.forEach { tournament in
@ -235,9 +235,9 @@ class Queries {
let tournaments: Results<Tournament> = realm.objects(Tournament.self) let tournaments: Results<Tournament> = realm.objects(Tournament.self)
let low = DistributionCounter(name: "Low (<$1M)") let low = DistributionCounter(name: "<$1M)")
let medium = DistributionCounter(name: "Medium ($1M - $5M)") let medium = DistributionCounter(name: "$1M - $5M")
let high = DistributionCounter(name: "High (> 5M)") let high = DistributionCounter(name: ">5M")
let counters: [DistributionCounter] = [low, medium, high] let counters: [DistributionCounter] = [low, medium, high]
tournaments.forEach { tournament in tournaments.forEach { tournament in
@ -257,9 +257,9 @@ class Queries {
let winnerResults = realm.objects(Result.self).filter("rank == 1") let winnerResults = realm.objects(Result.self).filter("rank == 1")
let low = DistributionCounter(name: "Low (<$250K)") let low = DistributionCounter(name: "<$250K")
let medium = DistributionCounter(name: "Medium ($250K - $1M)") let medium = DistributionCounter(name: "$250K - $1M")
let high = DistributionCounter(name: "High (> $1M)") let high = DistributionCounter(name: ">$1M")
let counters: [DistributionCounter] = [low, medium, high] let counters: [DistributionCounter] = [low, medium, high]
winnerResults.forEach { result in winnerResults.forEach { result in
@ -275,20 +275,20 @@ class Queries {
return counters return counters
} }
static func holdemTournamentsDistribution(realm: Realm) -> [DistributionCounter] { static func gamesDistribution(realm: Realm) -> [DistributionCounter] {
let tournaments: Results<Tournament> = realm.objects(Tournament.self) let tournaments: Results<Tournament> = realm.objects(Tournament.self)
let holdem = DistributionCounter(name: Game.holdem.rawValue) let noLimitHoldem = DistributionCounter(name: Game.holdem.rawValue)
let omaha = DistributionCounter(name: Game.omaha.rawValue) let potLimitOmaha = DistributionCounter(name: Game.omaha.rawValue)
let not = DistributionCounter(name: "Others") let not = DistributionCounter(name: "Others")
let games: [DistributionCounter] = [holdem, omaha, not] let games: [DistributionCounter] = [noLimitHoldem, potLimitOmaha, not]
tournaments.forEach { tournament in tournaments.forEach { tournament in
if tournament.name.contains(Game.holdem.rawValue) { if tournament.name.contains(Game.holdem.rawValue) {
holdem.increment() noLimitHoldem.increment()
} else if tournament.name.contains(Game.omaha.rawValue) { } else if tournament.name.contains(Game.omaha.rawValue) {
omaha.increment() potLimitOmaha.increment()
} else { } else {
not.increment() not.increment()
} }
@ -316,10 +316,11 @@ class Queries {
case 2: case 2:
runnerUps.append(result) runnerUps.append(result)
default: default:
let tableSize: Int = result.tournaments.first?.tableSize ?? 9 break
if result.rank <= tableSize { }
finalTables.append(result) let tableSize: Int = result.tournaments.first?.tableSize ?? 9
} if result.rank <= tableSize {
finalTables.append(result)
} }
} }

@ -66,8 +66,8 @@ class ReportGenerator {
var tournamentPrizepoolDistribution: [DistributionCounter] = [] var tournamentPrizepoolDistribution: [DistributionCounter] = []
var firstPrizeDistribution: [DistributionCounter] = [] var firstPrizeDistribution: [DistributionCounter] = []
var gamesDistribution: [DistributionCounter] = [] var gamesDistribution: [DistributionCounter] = []
var rankings1: PlayerNotableFinishesDataSource = PlayerNotableFinishesDataSource(notableFinishes: [], finalTables: false) var rankings1: PlayerNotableFinishesDataSource = PlayerNotableFinishesDataSource(notableFinishes: [])
var rankings2: PlayerNotableFinishesDataSource = PlayerNotableFinishesDataSource(notableFinishes: [], finalTables: true) var finalTables: [CumulatedResults] = []
func generateReports() { func generateReports() {
@ -87,13 +87,15 @@ class ReportGenerator {
self.cashesByCountry = Queries.cashesByCountry(realm: realm) self.cashesByCountry = Queries.cashesByCountry(realm: realm)
self.averageEvent = Queries.averageEvent(realm: realm) self.averageEvent = Queries.averageEvent(realm: realm)
self.notablesMostCashes = Queries.mostCashes(realm: realm, notable: true) self.notablesMostCashes = Queries.mostCashes(realm: realm, notable: true)
self.averageCash = Queries.averageCash(realm: realm) self.averageCash = Queries.averageCash(realm: realm, minCount: 8)
self.tournamentBuyinDistribution = Queries.tournamentBuyinDistribution(realm: realm) self.tournamentBuyinDistribution = Queries.tournamentBuyinDistribution(realm: realm)
self.tournamentPrizepoolDistribution = Queries.tournamentPrizepoolDistribution(realm: realm) self.tournamentPrizepoolDistribution = Queries.tournamentPrizepoolDistribution(realm: realm)
self.firstPrizeDistribution = Queries.firstPrizeDistribution(realm: realm) self.firstPrizeDistribution = Queries.firstPrizeDistribution(realm: realm)
self.gamesDistribution = Queries.holdemTournamentsDistribution(realm: realm) self.gamesDistribution = Queries.gamesDistribution(realm: realm)
self.rankings1 = PlayerNotableFinishesDataSource(notableFinishes: Queries.rankingCounts(realm: realm), finalTables: false)
self.rankings2 = PlayerNotableFinishesDataSource(notableFinishes: Queries.rankingCounts(realm: realm), finalTables: true) let pnds = PlayerNotableFinishesDataSource(notableFinishes: Queries.rankingCounts(realm: realm))
self.rankings1 = pnds
self.finalTables = pnds.finalTablesCumulated()
let tourniesDate = realm.objects(Tournament.self).distinct(by: ["date"]) let tourniesDate = realm.objects(Tournament.self).distinct(by: ["date"])

@ -9,32 +9,51 @@
import Foundation import Foundation
class CumulatedResults : HTMLRepresentable, ColumnRepresentable { class CumulatedResults : HTMLRepresentable, ColumnRepresentable {
enum Options {
case average
case countSorted
case finalTables
}
let player: Player let player: Player
let average: Bool var options: [Options] = []
// var average: Bool = false
var finalTables: Bool = false
var total: Double = 0.0 var total: Double = 0.0
var numberOfCashes: Int = 0 var numberOfCashes: Int = 0
var results: [Result] = [] var results: [Result] = []
var winsCount: Int = 0 var winsCount: Int = 0
var mainEventFinalist: Bool = false var mainEventFinalist: Bool = false
init(player: Player, average: Bool = false) { init (player: Player, results: [Result], options: [Options] = []) {
self.player = player
self.options = options
self.options.append(.finalTables)
for result in results {
self.add(result: result)
}
}
init(player: Player, options: [Options] = []) {
self.player = player self.player = player
self.average = average self.options = options
// self.average = average
for result in player.results { for result in player.results {
self.add(result: result) self.add(result: result)
if result.tournaments.first?.number == 73 && result.rank < 10 {
self.mainEventFinalist = true
}
} }
if average { if self.options.contains(.average) {
self.total = self.total / Double(self.numberOfCashes) self.total = self.total / Double(self.numberOfCashes)
} }
} }
func add(result: Result) { private func add(result: Result) {
if result.tournaments.first?.number == 73 && result.rank < 10 {
self.mainEventFinalist = true
}
self.total += result.earnings self.total += result.earnings
self.numberOfCashes += 1 self.numberOfCashes += 1
self.results.append(result) self.results.append(result)
@ -45,38 +64,52 @@ class CumulatedResults : HTMLRepresentable, ColumnRepresentable {
func columnDescriptors() -> [ColumnDescriptor] { func columnDescriptors() -> [ColumnDescriptor] {
let totalColumn = self.average ? "Average Earnings" : "Total Earnings" let totalColumn = self.options.contains(.finalTables) ? "FT Earnings" : self.options.contains(.average) ? "Average Earnings" : "Total Earnings"
return [ColumnDescriptor(header: "Name", number: false, widthWeight: 2.0), let countable = self.finalTables ? "Count" : "Cashes"
ColumnDescriptor(header: totalColumn, number: true, widthWeight: 1.3),
ColumnDescriptor(header: "Cashes", number: true, widthWeight: 0.8)] if self.options.contains(.countSorted) {
return [ColumnDescriptor(header: "Name", number: false, widthWeight: 2.0),
ColumnDescriptor(header: countable, number: true, widthWeight: 0.8),
ColumnDescriptor(header: totalColumn, number: true, widthWeight: 1.3)]
} else {
return [ColumnDescriptor(header: "Name", number: false, widthWeight: 2.0),
ColumnDescriptor(header: totalColumn, number: true, widthWeight: 1.3),
ColumnDescriptor(header: countable, number: true, widthWeight: 0.8)]
}
} }
func cellValues() -> [String] { func cellValues() -> [String] {
var name = self.player.formattedName var name = self.player.formattedName
if self.mainEventFinalist { if self.mainEventFinalist {
name += " *" name += " *"
} }
return [name, self.total.currencyFormatted, "\(self.numberOfCashes)"]
if self.options.contains(.countSorted) {
return [name, "\(self.numberOfCashes)", self.total.currencyFormatted]
} else {
return [name, self.total.currencyFormatted, "\(self.numberOfCashes)"]
}
} }
// func htmlHeaders() -> String { // func htmlHeaders() -> String {
// var strings: [String] = [] // var strings: [String] = []
// strings.append("Name") // strings.append("Name")
//// strings.append("Places (Year)") //// strings.append("Places (Year)")
// strings.append("Total Earnings") // strings.append("Total Earnings")
// strings.append("Cashes") // strings.append("Cashes")
// let all = strings.joined(separator: "</td><td>") // let all = strings.joined(separator: "</td><td>")
// return "<tr class=\"table-header\"><td>\(all)</td></tr>" // return "<tr class=\"table-header\"><td>\(all)</td></tr>"
// } // }
// //
// func html() -> String { // func html() -> String {
// var strings: [String] = [] // var strings: [String] = []
// strings.append(self.player.formattedName) // strings.append(self.player.formattedName)
//// strings.append(self.results.map { "\($0.rank.rankFormatted) (\($0.tournaments.first?.date.year ?? ""))" }.joined(separator: ", ")) //// strings.append(self.results.map { "\($0.rank.rankFormatted) (\($0.tournaments.first?.date.year ?? ""))" }.joined(separator: ", "))
// strings.append(self.total.currencyFormatted) // strings.append(self.total.currencyFormatted)
// strings.append("\(self.numberOfCashes)") // strings.append("\(self.numberOfCashes)")
// let all = strings.joined(separator: "</td><td>") // let all = strings.joined(separator: "</td><td>")
// return "<tr><td>\(all)</td></tr>" // return "<tr><td>\(all)</td></tr>"
// } // }
} }

@ -26,93 +26,94 @@ class PlayerNotableFinishesDataSource : NSObject, UITableViewDataSource, UITable
var mostRunnerUps: [PlayerNotableFinishes] = [] var mostRunnerUps: [PlayerNotableFinishes] = []
var mostRunnerUpsCount: Int = 0 var mostRunnerUpsCount: Int = 0
var mostFinalTables: [PlayerNotableFinishes] = [] var mostFinalTables: [PlayerNotableFinishes] = []
var mostFinalTablesCount: Int = 0 // var mostFinalTablesCount: Int = 0
var winsDisplay: [(String, UIFont)] = [] var winsDisplay: [(String, UIFont)] = []
var runnerUpsDisplay: [(String, UIFont)] = [] var runnerUpsDisplay: [(String, UIFont)] = []
let finalTables: Bool
init(notableFinishes: [PlayerNotableFinishes], finalTables: Bool) { init(notableFinishes: [PlayerNotableFinishes]) {
self.notableFinishes = notableFinishes self.notableFinishes = notableFinishes
self.finalTables = finalTables
if finalTables { var nFinalTables = notableFinishes
nFinalTables.sort { (p1, p2) -> Bool in
var nFinalTables = notableFinishes return p1.finalTables.count > p2.finalTables.count
nFinalTables.sort { (p1, p2) -> Bool in }
return p1.finalTables.count > p2.finalTables.count self.mostFinalTables = nFinalTables
}
let finalTablesTopCount = nFinalTables.first?.finalTables.count ?? 0 var nWins = notableFinishes
self.mostFinalTables = nFinalTables.filter { $0.finalTables.count == finalTablesTopCount } nWins.sort { (p1, p2) -> Bool in
return p1.wins.count > p2.wins.count
self.mostFinalTablesCount = finalTablesTopCount }
let winsTopCount = nWins.first?.wins.count ?? 0
} else { self.mostWins = nWins.filter { $0.wins.count == winsTopCount}
var nWins = notableFinishes for win in self.mostWins {
nWins.sort { (p1, p2) -> Bool in self.winsDisplay.append((win.player.formattedName, Fonts.cellTitle))
return p1.wins.count > p2.wins.count let sortedWins = win.wins.sorted(by: { $0.tournaments.first!.number < $1.tournaments.first!.number })
} for result in sortedWins {
let winsTopCount = nWins.first?.wins.count ?? 0 if let tournamentName = result.tournaments.first?.formatted {
self.mostWins = nWins.filter { $0.wins.count == winsTopCount} self.winsDisplay.append((" " + tournamentName, Fonts.regular))
} else {
for win in self.mostWins { self.winsDisplay.append(("no tournament!!!", Fonts.regular))
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 var nRunnerups = notableFinishes
return p1.runnerUps.count > p2.runnerUps.count 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 } 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 runnerup in self.mostRunnerUps {
for result in runnerup.runnerUps { self.runnerUpsDisplay.append((runnerup.player.formattedName, Fonts.cellTitle))
if let tournamentName = result.tournaments.first?.formatted { let sortedRunnerUps = runnerup.runnerUps.sorted(by: { $0.tournaments.first!.number < $1.tournaments.first!.number })
self.runnerUpsDisplay.append((" " + tournamentName, Fonts.regular)) for result in sortedRunnerUps {
} else { if let tournamentName = result.tournaments.first?.formatted {
self.runnerUpsDisplay.append(("no tournament!!!", Fonts.regular)) self.runnerUpsDisplay.append((" " + tournamentName, Fonts.regular))
} } else {
self.runnerUpsDisplay.append(("no tournament!!!", Fonts.regular))
} }
} }
self.mostWinsCount = winsTopCount
self.mostRunnerUpsCount = runnerUpsTopCount
} }
self.mostWinsCount = winsTopCount
self.mostRunnerUpsCount = runnerUpsTopCount
}
func finalTablesCumulated() -> [CumulatedResults] {
var cumulatedResults: [CumulatedResults] = []
for finalTablist in self.mostFinalTables {
let cr = CumulatedResults(player: finalTablist.player, results: finalTablist.finalTables)
cumulatedResults.append(cr)
}
cumulatedResults.sort(by: { (c1, c2) -> Bool in
if c1.numberOfCashes == c2.numberOfCashes {
return c1.total > c2.total
}
return c1.numberOfCashes > c2.numberOfCashes
})
return cumulatedResults
} }
// MARK - Table // MARK - Table
func numberOfSections(in tableView: UITableView) -> Int { func numberOfSections(in tableView: UITableView) -> Int {
return self.finalTables ? 1 : 2 return 2
} }
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if self.finalTables { switch section {
case 0:
return self.winsDisplay.count
case 1:
return self.runnerUpsDisplay.count
default:
return self.mostFinalTables.count return self.mostFinalTables.count
} else {
switch section {
case 0:
return self.winsDisplay.count
case 1:
return self.runnerUpsDisplay.count
default:
return self.mostFinalTables.count
}
} }
} }
@ -124,25 +125,21 @@ class PlayerNotableFinishesDataSource : NSObject, UITableViewDataSource, UITable
let font: UIFont let font: UIFont
let text: String let text: String
if self.finalTables { 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 text = self.mostFinalTables[indexPath.row].player.formattedName
font = Fonts.regular font = Fonts.regular
} else { default:
switch indexPath.section { text = "problem"
case 0: font = Fonts.regular
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?.text = text
cell.textLabel?.font = font cell.textLabel?.font = font
return cell return cell
@ -150,17 +147,13 @@ class PlayerNotableFinishesDataSource : NSObject, UITableViewDataSource, UITable
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let text: String let text: String
if self.finalTables { switch section {
text = "Most final tables - \(self.mostFinalTablesCount)" case 0:
} else { text = "Most bracelets"
switch section { case 1:
case 0: text = "Most runner-ups"
text = "Most wins - \(self.mostWinsCount) bracelets" default:
case 1: text = "Most final tables"
text = "Most runner-ups - \(self.mostRunnerUpsCount)"
default:
text = "Most final tables - \(self.mostFinalTablesCount)"
}
} }
return self.headerLabel(text: text) return self.headerLabel(text: text)

@ -12,18 +12,18 @@ import Charts
extension UIColor { extension UIColor {
static var paGreen: UIColor { static var paGreen: UIColor {
return UIColor(red: 0/255, green: 255/255, blue: 196/255, alpha: 1) return UIColor(red: 9/255, green: 203/255, blue: 157/255, alpha: 1)
} }
static var paColor1: UIColor { static var paBlue: UIColor {
return UIColor(red: 125/255, green: 155/255, blue: 255/255, alpha: 1) return UIColor(red: 0/255, green: 188/255, blue: 198/255, alpha: 1)
} }
static var paColor2: UIColor { static var paColor2: UIColor {
return UIColor(red: 255/255, green: 125/255, blue: 196/255, alpha: 1) return UIColor(red: 185/255, green: 151/255, blue: 199/255, alpha: 1)
} }
static let paColor3: UIColor = UIColor(red: 255/255, green: 155/255, blue: 50/255, alpha: 1) static let paColor3: UIColor = UIColor(red: 235/255, green: 153/255, blue: 141/255, alpha: 1)
} }
@ -78,7 +78,7 @@ extension Array where Element : ColumnRepresentable {
let dataSet = PieChartDataSet(entries: dataEntries, label: "") let dataSet = PieChartDataSet(entries: dataEntries, label: "")
dataSet.entryLabelFont = Fonts.pieChartEntries dataSet.entryLabelFont = Fonts.pieChartEntries
dataSet.valueFont = Fonts.pieChartEntries dataSet.valueFont = Fonts.pieChartEntries
dataSet.colors = [UIColor.paGreen, UIColor.paColor1, UIColor.paColor2, UIColor.paColor3] dataSet.colors = [UIColor.paGreen, UIColor.paColor2, UIColor.paColor3, UIColor.paBlue]
dataSet.valueFormatter = PercentageFormatter() dataSet.valueFormatter = PercentageFormatter()
return PieChartData(dataSet: dataSet) return PieChartData(dataSet: dataSet)
} }

@ -9,6 +9,6 @@
import Foundation import Foundation
enum Game : String { enum Game : String {
case holdem = "Hold'em" case holdem = "No-Limit Hold'em"
case omaha = "Pot-Limit Omaha" case omaha = "Pot-Limit Omaha"
} }

Loading…
Cancel
Save