parent
8e58237e2d
commit
71dd1c898e
@ -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") |
||||
// } |
||||
// |
||||
//} |
||||
@ -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…
Reference in new issue