Many improvements

master
Laurent 6 years ago
parent c8096582bc
commit 5b202bbbff
  1. 2
      TournamentStats/AppDelegate.swift
  2. 26
      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. 97
      TournamentStats/report/structures/CumulatedResults.swift
  9. 171
      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...")
let s = Date()
let generator = ReportGenerator()
generator.go(importData: true)
generator.go(importData: false)
let d = Date().timeIntervalSince(s)
print("reports created in \(d)s")

@ -11,14 +11,22 @@ import UIKit
class Fonts {
static let monospaced: UIFont = UIFont(name: "Menlo-Regular", size: 18.0)! // UIFont.systemFont(ofSize: 18.0)
static let bigNumbers: UIFont = UIFont(name: "Menlo-Regular", size: 48.0)!
static let regular: UIFont = UIFont(name: "Menlo-Regular", size: 18.0)! // UIFont.systemFont(ofSize: 18.0)
static let bold: UIFont = UIFont(name: "Menlo-Bold", size: 18.0)! // UIFont.systemFont(ofSize: 18.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 pieChartEntries: UIFont = UIFont(name: "Menlo-Bold", size: 28.0)! //UIFont.boldSystemFont(ofSize: 28)
static let chartLegend: UIFont = UIFont(name: "Menlo-Regular", size: 18.0)! // UIFont.systemFont(ofSize: 18.0)
fileprivate enum FontName : String {
case regular = "Menlo-Regular"
case bold = "Menlo-Bold"
}
static let monospaced: UIFont = UIFont(name: FontName.regular.rawValue, size: 18.0)!
static let bigNumbers: UIFont = UIFont(name: FontName.regular.rawValue, size: 48.0)!
static let regular: UIFont = UIFont(name: FontName.regular.rawValue, size: 18.0)!
static let bold: UIFont = UIFont(name: FontName.bold.rawValue, size: 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() {
let gradient: CAGradientLayer = CAGradientLayer()
let startColor = UIColor(red: 23/255, green: 72/255, blue: 61/255, alpha: 1)
let endColor = UIColor(red: 47/255, green: 149/255, blue: 126/255, alpha: 1)
// let endColor = UIColor(red: 47/255, green: 149/255, blue: 126/255, alpha: 1)
gradient.colors = [startColor.cgColor, endColor.cgColor]
gradient.locations = [0.2 , 1.0]
gradient.startPoint = CGPoint(x: 0.0, y: 0.0)
gradient.endPoint = CGPoint(x: 1.0, y: 1.0)
gradient.frame = self.bounds
self.backgroundColor = startColor
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.dataSource = generator.rankings1
self.mostTableView2.delegate = generator.rankings2
self.mostTableView2.dataSource = generator.rankings2
self.mostTableView2.setHeader(header: "Most final tables")
self.mostTableView2.setData(data: generator.finalTables, maxRows: 10)
/////
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.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.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.label42.text = "Hold'em vs not Hold'em"
self.label42.text = "Games distribution"
let USABraceletsDistribPie = PieChart(frame: pieChartFrame)
USABraceletsDistribPie.data = generator.USAvsWorldWins.pieChartData

@ -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="4120"/>
<rect key="frame" x="100" y="44" width="1300" height="4080"/>
<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"/>
@ -63,24 +63,32 @@
<constraint firstAttribute="height" constant="500" id="LQg-JD-2Lr"/>
</constraints>
</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">
<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>
<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"/>
</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 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="560"/>
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
</tableView>
</subviews>
<constraints>
<constraint firstAttribute="height" constant="700" id="NZj-7i-hbE"/>
<constraint firstAttribute="height" constant="560" id="NZj-7i-hbE"/>
</constraints>
</stackView>
<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"/>
<constraints>
<constraint firstAttribute="height" constant="50" id="z1Q-lp-yMy"/>
@ -88,7 +96,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="1450" width="1300" height="300"/>
<rect key="frame" x="0.0" y="1370" 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"/>
@ -103,28 +111,36 @@
<constraint firstAttribute="height" constant="300" id="N0D-Z0-uH0"/>
</constraints>
</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">
<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>
<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"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</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">
<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"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstAttribute="height" constant="40" id="RgL-e2-Q4s"/>
<constraint firstAttribute="height" constant="30" id="RgL-e2-Q4s"/>
</constraints>
</stackView>
<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>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Zmk-PV-di2">
<rect key="frame" x="0.0" y="0.0" width="642" height="450"/>
@ -140,7 +156,7 @@
</constraints>
</stackView>
<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"/>
<constraints>
<constraint firstAttribute="height" constant="40" id="mp4-0v-Scg"/>
@ -148,7 +164,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="2320" width="1300" height="280"/>
<rect key="frame" x="0.0" y="2280" 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"/>
@ -160,7 +176,7 @@
</constraints>
</stackView>
<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"/>
<constraints>
<constraint firstAttribute="height" constant="40" id="G0u-JL-8Ed"/>
@ -168,7 +184,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="2660" width="1300" height="280"/>
<rect key="frame" x="0.0" y="2620" 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"/>
@ -180,24 +196,24 @@
</constraints>
</stackView>
<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"/>
<constraints>
<constraint firstAttribute="height" constant="40" id="vnz-WB-g1y"/>
</constraints>
<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="3000" width="1300" height="40"/>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" translatesAutoresizingMaskIntoConstraints="NO" id="WFa-d3-zcU">
<rect key="frame" x="0.0" y="2960" 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"/>
<rect key="frame" x="0.0" y="0.0" width="650" height="40"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</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">
<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"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
@ -208,7 +224,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="3050" width="1300" height="500"/>
<rect key="frame" x="0.0" y="3010" 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"/>
@ -223,16 +239,16 @@
<constraint firstAttribute="height" constant="500" id="TTR-HJ-gPu"/>
</constraints>
</stackView>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillProportionally" translatesAutoresizingMaskIntoConstraints="NO" id="myS-g5-vsP">
<rect key="frame" x="0.0" y="3560" width="1300" height="50"/>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" translatesAutoresizingMaskIntoConstraints="NO" id="myS-g5-vsP">
<rect key="frame" x="0.0" y="3520" 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">
<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"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</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"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
@ -244,7 +260,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="3620" width="1300" height="500"/>
<rect key="frame" x="0.0" y="3580" 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"/>

@ -39,7 +39,7 @@ class Tournament : Object, Named {
}
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] = []
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
@ -62,7 +62,7 @@ class Queries {
var crArray: [CumulatedResults] = []
for player in players {
crArray.append(CumulatedResults(player: player))
crArray.append(CumulatedResults(player: player, options: [.countSorted]))
}
return crArray.sorted(by: { (cr1, cr2) -> Bool in
@ -210,10 +210,10 @@ class Queries {
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 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]
tournaments.forEach { tournament in
@ -235,9 +235,9 @@ class Queries {
let tournaments: Results<Tournament> = realm.objects(Tournament.self)
let low = DistributionCounter(name: "Low (<$1M)")
let medium = DistributionCounter(name: "Medium ($1M - $5M)")
let high = DistributionCounter(name: "High (> 5M)")
let low = DistributionCounter(name: "<$1M)")
let medium = DistributionCounter(name: "$1M - $5M")
let high = DistributionCounter(name: ">5M")
let counters: [DistributionCounter] = [low, medium, high]
tournaments.forEach { tournament in
@ -257,9 +257,9 @@ class Queries {
let winnerResults = realm.objects(Result.self).filter("rank == 1")
let low = DistributionCounter(name: "Low (<$250K)")
let medium = DistributionCounter(name: "Medium ($250K - $1M)")
let high = DistributionCounter(name: "High (> $1M)")
let low = DistributionCounter(name: "<$250K")
let medium = DistributionCounter(name: "$250K - $1M")
let high = DistributionCounter(name: ">$1M")
let counters: [DistributionCounter] = [low, medium, high]
winnerResults.forEach { result in
@ -275,20 +275,20 @@ class Queries {
return counters
}
static func holdemTournamentsDistribution(realm: Realm) -> [DistributionCounter] {
static func gamesDistribution(realm: Realm) -> [DistributionCounter] {
let tournaments: Results<Tournament> = realm.objects(Tournament.self)
let holdem = DistributionCounter(name: Game.holdem.rawValue)
let omaha = DistributionCounter(name: Game.omaha.rawValue)
let noLimitHoldem = DistributionCounter(name: Game.holdem.rawValue)
let potLimitOmaha = DistributionCounter(name: Game.omaha.rawValue)
let not = DistributionCounter(name: "Others")
let games: [DistributionCounter] = [holdem, omaha, not]
let games: [DistributionCounter] = [noLimitHoldem, potLimitOmaha, not]
tournaments.forEach { tournament in
if tournament.name.contains(Game.holdem.rawValue) {
holdem.increment()
noLimitHoldem.increment()
} else if tournament.name.contains(Game.omaha.rawValue) {
omaha.increment()
potLimitOmaha.increment()
} else {
not.increment()
}
@ -316,10 +316,11 @@ class Queries {
case 2:
runnerUps.append(result)
default:
let tableSize: Int = result.tournaments.first?.tableSize ?? 9
if result.rank <= tableSize {
finalTables.append(result)
}
break
}
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 firstPrizeDistribution: [DistributionCounter] = []
var gamesDistribution: [DistributionCounter] = []
var rankings1: PlayerNotableFinishesDataSource = PlayerNotableFinishesDataSource(notableFinishes: [], finalTables: false)
var rankings2: PlayerNotableFinishesDataSource = PlayerNotableFinishesDataSource(notableFinishes: [], finalTables: true)
var rankings1: PlayerNotableFinishesDataSource = PlayerNotableFinishesDataSource(notableFinishes: [])
var finalTables: [CumulatedResults] = []
func generateReports() {
@ -87,13 +87,15 @@ class ReportGenerator {
self.cashesByCountry = Queries.cashesByCountry(realm: realm)
self.averageEvent = Queries.averageEvent(realm: realm)
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.tournamentPrizepoolDistribution = Queries.tournamentPrizepoolDistribution(realm: realm)
self.firstPrizeDistribution = Queries.firstPrizeDistribution(realm: realm)
self.gamesDistribution = Queries.holdemTournamentsDistribution(realm: realm)
self.rankings1 = PlayerNotableFinishesDataSource(notableFinishes: Queries.rankingCounts(realm: realm), finalTables: false)
self.rankings2 = PlayerNotableFinishesDataSource(notableFinishes: Queries.rankingCounts(realm: realm), finalTables: true)
self.gamesDistribution = Queries.gamesDistribution(realm: realm)
let pnds = PlayerNotableFinishesDataSource(notableFinishes: Queries.rankingCounts(realm: realm))
self.rankings1 = pnds
self.finalTables = pnds.finalTablesCumulated()
let tourniesDate = realm.objects(Tournament.self).distinct(by: ["date"])

@ -10,8 +10,16 @@ import Foundation
class CumulatedResults : HTMLRepresentable, ColumnRepresentable {
enum Options {
case average
case countSorted
case finalTables
}
let player: Player
let average: Bool
var options: [Options] = []
// var average: Bool = false
var finalTables: Bool = false
var total: Double = 0.0
var numberOfCashes: Int = 0
@ -19,22 +27,33 @@ class CumulatedResults : HTMLRepresentable, ColumnRepresentable {
var winsCount: Int = 0
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.average = average
self.options = options
// self.average = average
for result in player.results {
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)
}
}
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.numberOfCashes += 1
self.results.append(result)
@ -45,10 +64,19 @@ class CumulatedResults : HTMLRepresentable, ColumnRepresentable {
func columnDescriptors() -> [ColumnDescriptor] {
let totalColumn = self.average ? "Average Earnings" : "Total Earnings"
return [ColumnDescriptor(header: "Name", number: false, widthWeight: 2.0),
ColumnDescriptor(header: totalColumn, number: true, widthWeight: 1.3),
ColumnDescriptor(header: "Cashes", number: true, widthWeight: 0.8)]
let totalColumn = self.options.contains(.finalTables) ? "FT Earnings" : self.options.contains(.average) ? "Average Earnings" : "Total Earnings"
let countable = self.finalTables ? "Count" : "Cashes"
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] {
@ -56,27 +84,32 @@ class CumulatedResults : HTMLRepresentable, ColumnRepresentable {
if self.mainEventFinalist {
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 {
// var strings: [String] = []
// strings.append("Name")
//// strings.append("Places (Year)")
// strings.append("Total Earnings")
// strings.append("Cashes")
// let all = strings.joined(separator: "</td><td>")
// return "<tr class=\"table-header\"><td>\(all)</td></tr>"
// }
//
// func html() -> String {
// var strings: [String] = []
// strings.append(self.player.formattedName)
//// strings.append(self.results.map { "\($0.rank.rankFormatted) (\($0.tournaments.first?.date.year ?? ""))" }.joined(separator: ", "))
// strings.append(self.total.currencyFormatted)
// strings.append("\(self.numberOfCashes)")
// let all = strings.joined(separator: "</td><td>")
// return "<tr><td>\(all)</td></tr>"
// }
// func htmlHeaders() -> String {
// var strings: [String] = []
// strings.append("Name")
//// strings.append("Places (Year)")
// strings.append("Total Earnings")
// strings.append("Cashes")
// let all = strings.joined(separator: "</td><td>")
// return "<tr class=\"table-header\"><td>\(all)</td></tr>"
// }
//
// func html() -> String {
// var strings: [String] = []
// strings.append(self.player.formattedName)
//// strings.append(self.results.map { "\($0.rank.rankFormatted) (\($0.tournaments.first?.date.year ?? ""))" }.joined(separator: ", "))
// strings.append(self.total.currencyFormatted)
// strings.append("\(self.numberOfCashes)")
// let all = strings.joined(separator: "</td><td>")
// return "<tr><td>\(all)</td></tr>"
// }
}

@ -26,93 +26,94 @@ class PlayerNotableFinishesDataSource : NSObject, UITableViewDataSource, UITable
var mostRunnerUps: [PlayerNotableFinishes] = []
var mostRunnerUpsCount: Int = 0
var mostFinalTables: [PlayerNotableFinishes] = []
var mostFinalTablesCount: Int = 0
// var mostFinalTablesCount: Int = 0
var winsDisplay: [(String, UIFont)] = []
var runnerUpsDisplay: [(String, UIFont)] = []
let finalTables: Bool
init(notableFinishes: [PlayerNotableFinishes], finalTables: Bool) {
init(notableFinishes: [PlayerNotableFinishes]) {
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 nFinalTables = notableFinishes
nFinalTables.sort { (p1, p2) -> Bool in
return p1.finalTables.count > p2.finalTables.count
}
self.mostFinalTables = nFinalTables
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 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.cellTitle))
let sortedWins = win.wins.sorted(by: { $0.tournaments.first!.number < $1.tournaments.first!.number })
for result in sortedWins {
if let tournamentName = result.tournaments.first?.formatted {
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))
}
///////
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.cellTitle))
let sortedRunnerUps = runnerup.runnerUps.sorted(by: { $0.tournaments.first!.number < $1.tournaments.first!.number })
for result in sortedRunnerUps {
if let tournamentName = result.tournaments.first?.formatted {
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
func numberOfSections(in tableView: UITableView) -> Int {
return self.finalTables ? 1 : 2
return 2
}
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
} 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 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
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
}
default:
text = "problem"
font = Fonts.regular
}
cell.textLabel?.text = text
cell.textLabel?.font = font
return cell
@ -150,17 +147,13 @@ class PlayerNotableFinishesDataSource : NSObject, UITableViewDataSource, UITable
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)"
}
switch section {
case 0:
text = "Most bracelets"
case 1:
text = "Most runner-ups"
default:
text = "Most final tables"
}
return self.headerLabel(text: text)

@ -12,18 +12,18 @@ import Charts
extension 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 {
return UIColor(red: 125/255, green: 155/255, blue: 255/255, alpha: 1)
static var paBlue: UIColor {
return UIColor(red: 0/255, green: 188/255, blue: 198/255, alpha: 1)
}
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: "")
dataSet.entryLabelFont = 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()
return PieChartData(dataSet: dataSet)
}

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

Loading…
Cancel
Save