Added most wins, runnerups and FTs

master
Laurent 6 years ago
parent 8e58237e2d
commit 71dd1c898e
  1. 8
      TournamentStats.xcodeproj/project.pbxproj
  2. 10
      TournamentStats/UI/reports/InfographyView.swift
  3. 42
      TournamentStats/UI/reports/InfographyView.xib
  4. 192
      TournamentStats/UI/reports/InfographyViewController.swift
  5. 15
      TournamentStats/realm/Model.swift
  6. 32
      TournamentStats/report/Queries.swift
  7. 8
      TournamentStats/report/ReportGenerator.swift
  8. 105
      TournamentStats/report/structures/PlayerNotableFinishes.swift

@ -40,7 +40,6 @@
4D2F1C5B22CC92D1007C639E /* event84 in Resources */ = {isa = PBXBuildFile; fileRef = 4D2F1C4322CC92D1007C639E /* event84 */; };
4D30463322F4232600DA86C4 /* event57 in Resources */ = {isa = PBXBuildFile; fileRef = 4D30463122F4232600DA86C4 /* event57 */; };
4D30463422F4232600DA86C4 /* event78 in Resources */ = {isa = PBXBuildFile; fileRef = 4D30463222F4232600DA86C4 /* event78 */; };
4D39B6F122F829A500625E31 /* InfographyViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D39B6F022F829A500625E31 /* InfographyViewController.swift */; };
4D39B6F322F8549100625E31 /* DataSourceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D39B6F222F8549100625E31 /* DataSourceWrapper.swift */; };
4D39B6F522F856EF00625E31 /* StackTableCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4D39B6F422F856EF00625E31 /* StackTableCell.xib */; };
4D39B6F722F8573900625E31 /* StackTableCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D39B6F622F8573900625E31 /* StackTableCell.swift */; };
@ -52,6 +51,7 @@
4DB113D923054A4100D0C671 /* InfographyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DB113D823054A4100D0C671 /* InfographyView.swift */; };
4DB113DB230559F600D0C671 /* Label.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DB113DA230559F600D0C671 /* Label.swift */; };
4DB113DD2305882A00D0C671 /* Fonts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DB113DC2305882A00D0C671 /* Fonts.swift */; };
4DD9C5BD2316D092003501A4 /* PlayerNotableFinishes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DD9C5BC2316D092003501A4 /* PlayerNotableFinishes.swift */; };
4DDEF11422AE4FB900F4D7C1 /* TournamentStats.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DDEF11322AE4FB900F4D7C1 /* TournamentStats.swift */; };
4DF7608422A3FB96004B0EF1 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DF7608322A3FB96004B0EF1 /* AppDelegate.swift */; };
4DF7608622A3FB96004B0EF1 /* MasterViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DF7608522A3FB96004B0EF1 /* MasterViewController.swift */; };
@ -190,7 +190,6 @@
4D2F1C4322CC92D1007C639E /* event84 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = event84; sourceTree = "<group>"; };
4D30463122F4232600DA86C4 /* event57 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = event57; sourceTree = "<group>"; };
4D30463222F4232600DA86C4 /* event78 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = event78; sourceTree = "<group>"; };
4D39B6F022F829A500625E31 /* InfographyViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfographyViewController.swift; sourceTree = "<group>"; };
4D39B6F222F8549100625E31 /* DataSourceWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataSourceWrapper.swift; sourceTree = "<group>"; };
4D39B6F422F856EF00625E31 /* StackTableCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = StackTableCell.xib; sourceTree = "<group>"; };
4D39B6F622F8573900625E31 /* StackTableCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StackTableCell.swift; sourceTree = "<group>"; };
@ -202,6 +201,7 @@
4DB113D823054A4100D0C671 /* InfographyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfographyView.swift; sourceTree = "<group>"; };
4DB113DA230559F600D0C671 /* Label.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Label.swift; sourceTree = "<group>"; };
4DB113DC2305882A00D0C671 /* Fonts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Fonts.swift; sourceTree = "<group>"; };
4DD9C5BC2316D092003501A4 /* PlayerNotableFinishes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerNotableFinishes.swift; sourceTree = "<group>"; };
4DDEF11322AE4FB900F4D7C1 /* TournamentStats.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TournamentStats.swift; sourceTree = "<group>"; };
4DF7608022A3FB96004B0EF1 /* TournamentStats.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TournamentStats.app; sourceTree = BUILT_PRODUCTS_DIR; };
4DF7608322A3FB96004B0EF1 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
@ -324,7 +324,6 @@
4D97941222F827A5004A2D7F /* reports */ = {
isa = PBXGroup;
children = (
4D39B6F022F829A500625E31 /* InfographyViewController.swift */,
4DB113D62305480600D0C671 /* InfographyView.xib */,
4DB113D823054A4100D0C671 /* InfographyView.swift */,
4D26A95023152A6B001C98D2 /* StatCollectionViewCell.swift */,
@ -556,6 +555,7 @@
4DF7615022A7AECA004B0EF1 /* TournamentRepresentable.swift */,
4DDEF11322AE4FB900F4D7C1 /* TournamentStats.swift */,
4DF7614922A66675004B0EF1 /* TournamentWinner.swift */,
4DD9C5BC2316D092003501A4 /* PlayerNotableFinishes.swift */,
);
path = structures;
sourceTree = "<group>";
@ -798,7 +798,6 @@
4DF760B022A47C74004B0EF1 /* RowImporter.swift in Sources */,
4DF7614A22A66675004B0EF1 /* TournamentWinner.swift in Sources */,
4D0F103722C4C08F005F797A /* ChipCount.swift in Sources */,
4D39B6F122F829A500625E31 /* InfographyViewController.swift in Sources */,
4DF760B322A47CAE004B0EF1 /* Realm+Extensions.swift in Sources */,
4DF7608822A3FB96004B0EF1 /* DetailViewController.swift in Sources */,
4D26A95423156F6F001C98D2 /* Game.swift in Sources */,
@ -809,6 +808,7 @@
4DF7608622A3FB96004B0EF1 /* MasterViewController.swift in Sources */,
4DF7608422A3FB96004B0EF1 /* AppDelegate.swift in Sources */,
4D39B6F322F8549100625E31 /* DataSourceWrapper.swift in Sources */,
4DD9C5BD2316D092003501A4 /* PlayerNotableFinishes.swift in Sources */,
4DDEF11422AE4FB900F4D7C1 /* TournamentStats.swift in Sources */,
4DF760A722A3FD12004B0EF1 /* Model.swift in Sources */,
4D39B6FC22F8686300625E31 /* CumulatedWins.swift in Sources */,

@ -31,6 +31,8 @@ class InfographyView: UIView {
@IBOutlet weak var tableView12: TableView!
@IBOutlet weak var tableView13: TableView!
@IBOutlet weak var mostCollectionView: UICollectionView!
@IBOutlet weak var hStack2a: UIStackView!
@IBOutlet weak var label21: UILabel!
@IBOutlet weak var label22: UILabel!
@ -104,6 +106,12 @@ 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.tableView11.setData(data: generator.biggestWinners)
self.tableView11.setHeader(header: "Biggest Winners")
self.tableView11.setFooter(footer: "* denotes a Main Event finalist")
@ -150,7 +158,7 @@ class InfographyView: UIView {
self.container41.addMaxConstraints(view: USABraceletsDistribPie)
let holdemDistributionPie = PieChart(frame: pieChartFrame)
holdemDistributionPie.data = generator.holdemTournamentsDistribution.pieChartData
holdemDistributionPie.data = generator.gamesDistribution.pieChartData
self.container42.addSubview(holdemDistributionPie)
self.container42.addMaxConstraints(view: holdemDistributionPie)

@ -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="3410"/>
<rect key="frame" x="100" y="44" width="1300" height="3720"/>
<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,8 +63,21 @@
<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"/>
<constraints>
<constraint firstAttribute="height" constant="300" id="MTT-GP-Dkf"/>
</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>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Xrv-gg-4dD" userLabel="Space">
<rect key="frame" x="0.0" y="680" width="1300" height="50"/>
<rect key="frame" x="0.0" y="990" 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"/>
@ -72,7 +85,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="740" width="1300" height="300"/>
<rect key="frame" x="0.0" y="1050" 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"/>
@ -88,7 +101,7 @@
</constraints>
</stackView>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillProportionally" translatesAutoresizingMaskIntoConstraints="NO" id="91U-hc-Oqn">
<rect key="frame" x="0.0" y="1050" width="1300" height="40"/>
<rect key="frame" x="0.0" y="1360" 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"/>
@ -108,7 +121,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="1100" width="1300" height="450"/>
<rect key="frame" x="0.0" y="1410" 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"/>
@ -124,7 +137,7 @@
</constraints>
</stackView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Zdb-H8-Dy2" userLabel="Space">
<rect key="frame" x="0.0" y="1560" width="1300" height="40"/>
<rect key="frame" x="0.0" y="1870" 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"/>
@ -132,7 +145,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="1610" width="1300" height="280"/>
<rect key="frame" x="0.0" y="1920" 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"/>
@ -144,7 +157,7 @@
</constraints>
</stackView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="fZP-2C-MlN" userLabel="Space">
<rect key="frame" x="0.0" y="1900" width="1300" height="40"/>
<rect key="frame" x="0.0" y="2210" 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"/>
@ -152,7 +165,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="1950" width="1300" height="280"/>
<rect key="frame" x="0.0" y="2260" 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"/>
@ -164,7 +177,7 @@
</constraints>
</stackView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Tt8-Z5-vVb" userLabel="Space">
<rect key="frame" x="0.0" y="2240" width="1300" height="40"/>
<rect key="frame" x="0.0" y="2550" 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"/>
@ -172,7 +185,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="2290" width="1300" height="40"/>
<rect key="frame" x="0.0" y="2600" 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"/>
@ -192,7 +205,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="2340" width="1300" height="500"/>
<rect key="frame" x="0.0" y="2650" 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"/>
@ -208,7 +221,7 @@
</constraints>
</stackView>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillProportionally" translatesAutoresizingMaskIntoConstraints="NO" id="myS-g5-vsP">
<rect key="frame" x="0.0" y="2850" width="1300" height="50"/>
<rect key="frame" x="0.0" y="3160" 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"/>
@ -228,7 +241,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="2910" width="1300" height="500"/>
<rect key="frame" x="0.0" y="3220" 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"/>
@ -285,6 +298,7 @@
<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="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"/>

@ -1,192 +0,0 @@
//
// InfographyView.swift
// TournamentStats
//
// Created by Laurent Morvillier on 05/08/2019.
// Copyright © 2019 Stax River. All rights reserved.
//
import Foundation
import UIKit
import Charts
class InfographyViewController : UIViewController {
var generator: ReportGenerator?
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
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)
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.view.bounds
self.view.layer.insertSublayer(gradient, at: 0)
}
override func viewDidLoad() {
let totalWidth: CGFloat = 1500.0
let defaultSpacing: CGFloat = 8.0
guard let generator = self.generator else {
return
}
let mainTitle = UILabel()
mainTitle.textColor = UIColor.white
mainTitle.font = UIFont.boldSystemFont(ofSize: 64.0)
mainTitle.textAlignment = .center
mainTitle.text = "2019 WSOP"
// let table1 = TableView(data: generator.biggestWinners, frame: CGRect.zero, style: .grouped)
// table1.defineConstraints(width: 500 - defaultSpacing / 3, height: 500)
//
// let table2 = TableView(data: generator.mostWins, frame: CGRect.zero, style: .grouped)
// table2.defineConstraints(width: 500 - defaultSpacing / 3, height: 500)
//
// let table3 = TableView(data: generator.averageCash, frame: CGRect.zero, style: .grouped)
// table3.defineConstraints(width: 500 - defaultSpacing / 3, height: 500)
//
// let hstack1: UIStackView = UIStackView(arrangedSubviews: [table1, table2, table3])
// hstack1.defineConstraints(width: totalWidth, height: 300.0)
// hstack1.distribution = .equalSpacing
// hstack1.spacing = 8.0
// hstack1.axis = .horizontal
// hstack1.alignment = .top
//
// /////
//
// let title1 = TitleLabel(frame: CGRect.zero, text: "Buy-in distribution")
// let title2 = TitleLabel(frame: CGRect.zero, text: "First prizes distribution")
// let title3 = TitleLabel(frame: CGRect.zero, text: "Prizepool distribution")
//
// let hstack2a: UIStackView = UIStackView(arrangedSubviews: [title1, title2, title3])
// hstack2a.defineConstraints(width: totalWidth)
// hstack2a.distribution = .fillEqually
// hstack2a.axis = .horizontal
// hstack2a.alignment = .top
//
// /////
//
// let buyinDistribPie = PieChart(frame: CGRect.zero)
// buyinDistribPie.data = generator.tournamentBuyinDistribution.pieChartData
// buyinDistribPie.defineConstraints(height: 300)
// buyinDistribPie.notifyDataSetChanged()
//
// let firstPrizeDistributionPie = PieChart(frame: CGRect.zero)
// firstPrizeDistributionPie.data = generator.firstPrizeDistribution.pieChartData
// firstPrizeDistributionPie.defineConstraints(height: 300)
//
// let prizepoolDistribPie = PieChart(frame: CGRect.zero)
// prizepoolDistribPie.data = generator.tournamentPrizepoolDistribution.pieChartData
// prizepoolDistribPie.defineConstraints(height: 400)
//
// let hstack2: UIStackView = UIStackView(arrangedSubviews: [buyinDistribPie, firstPrizeDistributionPie, prizepoolDistribPie])
// hstack2.defineConstraints(width: totalWidth, height: 350.0)
// hstack2.distribution = .fillEqually
// hstack2.axis = .horizontal
// hstack2.alignment = .top
//
//
// /////
//
// let title31 = TitleLabel(frame: CGRect.zero, text: "Events by prizepool")
// let title32 = TitleLabel(frame: CGRect.zero, text: "Events by entries")
//
// let hstack3a: UIStackView = UIStackView(arrangedSubviews: [title31, title32])
// hstack3a.defineConstraints(width: totalWidth)
// hstack3a.distribution = .fillEqually
// hstack3a.axis = .horizontal
// hstack3a.alignment = .top
//
// /////
//
// let table31 = TableView(data: generator.tourniesByPrizepool, frame: CGRect.zero, style: .grouped)
// table31.defineConstraints(width: 750, height: 500)
//
// let table32 = TableView(data: generator.tourniesByEntries, frame: CGRect.zero, style: .grouped)
// table32.defineConstraints(width: 750, height: 500)
//
// let hstack3: UIStackView = UIStackView(arrangedSubviews: [table31, table32])
// hstack3.defineConstraints(width: totalWidth, height: 300.0)
// hstack3.distribution = .equalSpacing
// hstack3.spacing = 8.0
// hstack3.axis = .horizontal
// hstack3.alignment = .top
/////
let vstack: UIStackView = UIStackView(arrangedSubviews: [mainTitle])
// let vstack: UIStackView = UIStackView(arrangedSubviews: [mainTitle, hstack1, hstack2a, hstack2, hstack3a, hstack3])
vstack.axis = .vertical
vstack.distribution = .equalCentering
vstack.alignment = .center
vstack.spacing = 10.0
self.view.addSubview(vstack)
vstack.translatesAutoresizingMaskIntoConstraints = false
vstack.leadingAnchor.constraint(equalTo: self.view.leadingAnchor, constant: 16.0).isActive = true
vstack.trailingAnchor.constraint(equalTo: self.view.trailingAnchor, constant: -16.0).isActive = true
vstack.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor, constant: 16.0).isActive = true
}
}
//class InfographyView : UIView {
//
// var references: [UITableViewDataSource] = []
//
// init(frame: CGRect, generator: ReportGenerator) {
// super.init(frame: frame)
// self.backgroundColor = UIColor.lightGray
//
// let table1 = TableView(data: generator.biggestWinners, frame: CGRect.zero, style: .grouped)
// table1.defineConstraints(width: 500, height: 500)
//
// let table2 = TableView(data: generator.mostWins, frame: CGRect.zero, style: .grouped)
// table2.defineConstraints(width: 500, height: 500)
//
// let pieChart = PieChartView(frame: CGRect.zero)
// pieChart.data = generator.tournamentBuyinDistribution.pieChartData
// pieChart.defineConstraints(width: 300, height: 300)
//
// let hstack1: UIStackView = UIStackView(arrangedSubviews: [table1, table2])
// hstack1.defineConstraints(width: 1000, height: 500)
// hstack1.distribution = .fill
// hstack1.axis = .horizontal
// hstack1.alignment = .top
// hstack1.backgroundColor = UIColor.red
//
// let hstack2: UIStackView = UIStackView(arrangedSubviews: [pieChart])
// hstack2.defineConstraints(width: 1000, height: 300)
// hstack2.distribution = .fill
// hstack2.axis = .horizontal
// hstack2.alignment = .top
// hstack2.backgroundColor = UIColor.green
//
// let vstack: UIStackView = UIStackView(arrangedSubviews: [hstack1, hstack2])
// vstack.axis = .vertical
// vstack.distribution = .fill
// vstack.alignment = .leading
// vstack.backgroundColor = UIColor.blue
// self.addSubview(vstack)
// self.addMaxConstraints(view: vstack)
//
// }
//
// required init?(coder aDecoder: NSCoder) {
// fatalError("init(coder:) has not been implemented")
// }
//
//}

@ -22,7 +22,20 @@ class Tournament : Object, Named {
@objc dynamic var date: Date = Date()
@objc dynamic var number: Int = 0
@objc dynamic var buyin: Int = 0
@objc dynamic var name: String = ""
@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
}
}
}
let results = List<Result>()
@objc dynamic var prizepool: Double = 0.0

@ -297,4 +297,36 @@ class Queries {
return games
}
static func rankingCounts(realm: Realm) -> [PlayerNotableFinishes] {
let players: Results<Player> = realm.objects(Player.self)
var notableFinishes: [PlayerNotableFinishes] = []
players.forEach { player in
var wins: [Result] = []
var runnerUps: [Result] = []
var finalTables: [Result] = []
player.results.forEach { result in
switch result.rank {
case 1:
wins.append(result)
case 2:
runnerUps.append(result)
default:
if result.rank <= result.tournaments.first?.tableSize ?? 10 {
finalTables.append(result)
}
}
}
notableFinishes.append(PlayerNotableFinishes(player: player, wins: wins, runnerUps: runnerUps, finalTables: finalTables))
}
return notableFinishes
}
}

@ -65,7 +65,8 @@ class ReportGenerator {
var tournamentBuyinDistribution: [DistributionCounter] = []
var tournamentPrizepoolDistribution: [DistributionCounter] = []
var firstPrizeDistribution: [DistributionCounter] = []
var holdemTournamentsDistribution: [DistributionCounter] = []
var gamesDistribution: [DistributionCounter] = []
var rankings: PlayerNotableFinishesDataSource = PlayerNotableFinishesDataSource(notableFinishes: [])
func generateReports() {
@ -89,7 +90,8 @@ class ReportGenerator {
self.tournamentBuyinDistribution = Queries.tournamentBuyinDistribution(realm: realm)
self.tournamentPrizepoolDistribution = Queries.tournamentPrizepoolDistribution(realm: realm)
self.firstPrizeDistribution = Queries.firstPrizeDistribution(realm: realm)
self.holdemTournamentsDistribution = Queries.holdemTournamentsDistribution(realm: realm)
self.gamesDistribution = Queries.holdemTournamentsDistribution(realm: realm)
self.rankings = PlayerNotableFinishesDataSource(notableFinishes: Queries.rankingCounts(realm: realm))
let tourniesDate = realm.objects(Tournament.self).distinct(by: ["date"])
@ -126,7 +128,7 @@ class ReportGenerator {
self.tournamentBuyinDistribution.writeHTML(fileName: "reports/buyinDistribution.html")
self.tournamentPrizepoolDistribution.writeHTML(fileName: "reports/prizepoolDistribution.html")
self.firstPrizeDistribution.writeHTML(fileName: "reports/firstPrizeDistribution.html")
self.holdemTournamentsDistribution.writeHTML(fileName: "reports/holdemDistribution.html")
self.gamesDistribution.writeHTML(fileName: "reports/holdemDistribution.html")
}

@ -0,0 +1,105 @@
//
// PlayerNotableFinishes.swift
// TournamentStats
//
// Created by Laurent Morvillier on 28/08/2019.
// Copyright © 2019 Stax River. All rights reserved.
//
import Foundation
import UIKit
struct PlayerNotableFinishes {
var player: Player
var wins: [Result] = []
var runnerUps: [Result] = []
var finalTables: [Result] = []
}
class PlayerNotableFinishesDataSource : NSObject, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
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 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 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 }
///////
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}.map { $0.player }
self.mostWinsCount = winsTopCount
self.mostRunnerUpsCount = runnerUpsTopCount
self.mostFinalTablesCount = finalTablesTopCount
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 3
}
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 = ""
}
cell.nameLabel.text = name.uppercased()
cell.valueLabel.text = value
cell.nameLabel.textColor = UIColor.white
cell.valueLabel.textColor = UIColor.white
cell.nameLabel.font = Fonts.regular
cell.valueLabel.font = Fonts.bigNumbers
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: 800.0, height: 90.0)
}
}
Loading…
Cancel
Save