More improvements

master
Laurent 6 years ago
parent 3e3651827c
commit 8e58237e2d
  1. 9
      TournamentStats/report/Queries.swift
  2. 2
      TournamentStats/report/structures/CumulatedResults.swift
  3. 16
      TournamentStats/report/structures/TournamentStats.swift

@ -193,12 +193,13 @@ class Queries {
let buyin: Double? = tournaments.average(ofProperty: "buyin") let buyin: Double? = tournaments.average(ofProperty: "buyin")
let prizepool: Double? = tournaments.average(ofProperty: "prizepool") let prizepool: Double? = tournaments.average(ofProperty: "prizepool")
let itmCount: Double = tournaments.reduce(0.0) { $0 + Double($1.results.count) } let winnerResults = tournaments.compactMap { (tournament) -> Result? in
let avgItmCount = itmCount / Double(tournaments.count) return tournament.results.first { $0.rank == 1 }
}
let averageFirstPrize = winnerResults.reduce(0.0) { $0 + Double($1.earnings) } / Double(tournaments.count)
if let entries = entries, let buyin = buyin, let prizepool = prizepool { if let entries = entries, let buyin = buyin, let prizepool = prizepool {
let itm = prizepool / avgItmCount let ts = TournamentStats(entries: entries, buyin: buyin, prizepool: prizepool, firstPrize: averageFirstPrize)
let ts = TournamentStats(entries: entries, buyin: buyin, prizepool: prizepool, itmValue: itm)
return [ts] return [ts]
} }

@ -47,7 +47,7 @@ class CumulatedResults : HTMLRepresentable, ColumnRepresentable {
let totalColumn = self.average ? "Average Earnings" : "Total Earnings" let totalColumn = self.average ? "Average Earnings" : "Total Earnings"
return [ColumnDescriptor(header: "Name", number: false, widthWeight: 2.0), return [ColumnDescriptor(header: "Name", number: false, widthWeight: 2.0),
ColumnDescriptor(header: totalColumn, number: true, widthWeight: 1.2), ColumnDescriptor(header: totalColumn, number: true, widthWeight: 1.3),
ColumnDescriptor(header: "Cashes", number: true, widthWeight: 0.8)] ColumnDescriptor(header: "Cashes", number: true, widthWeight: 0.8)]
} }

@ -14,14 +14,14 @@ class TournamentStats : NSObject, HTMLRepresentable, UITableViewDelegate, UITabl
var entries: Double var entries: Double
var buyin: Double var buyin: Double
var prizepool: Double var prizepool: Double
var itmValue: Double var firstPrize: Double
init(entries: Double, buyin: Double, prizepool: Double, itmValue: Double) { init(entries: Double, buyin: Double, prizepool: Double, firstPrize: Double) {
self.entries = entries self.entries = entries
self.buyin = buyin self.buyin = buyin
self.prizepool = prizepool self.prizepool = prizepool
self.itmValue = itmValue self.firstPrize = firstPrize
super.init() super.init()
@ -45,7 +45,7 @@ class TournamentStats : NSObject, HTMLRepresentable, UITableViewDelegate, UITabl
strings.append(("Entries", NumberFormatter().string(from: NSNumber(value: self.entries))!)) strings.append(("Entries", NumberFormatter().string(from: NSNumber(value: self.entries))!))
strings.append(("Buy-in", Formatter.currency.string(from: NSNumber(value: self.buyin))!)) strings.append(("Buy-in", Formatter.currency.string(from: NSNumber(value: self.buyin))!))
strings.append(("Prizepool", Formatter.currency.string(from: NSNumber(value: self.prizepool))!)) strings.append(("Prizepool", Formatter.currency.string(from: NSNumber(value: self.prizepool))!))
strings.append(("Earnings", Formatter.currency.string(from: NSNumber(value: self.itmValue))!)) strings.append(("Earnings", Formatter.currency.string(from: NSNumber(value: self.firstPrize))!))
var all = "" var all = ""
strings.forEach { (tuple) in strings.forEach { (tuple) in
@ -78,7 +78,7 @@ class TournamentStats : NSObject, HTMLRepresentable, UITableViewDelegate, UITabl
case 2: case 2:
cells = ("Prizepool", Formatter.currency.string(from: NSNumber(value: self.prizepool))!) cells = ("Prizepool", Formatter.currency.string(from: NSNumber(value: self.prizepool))!)
default: default:
cells = ("Earnings", Formatter.currency.string(from: NSNumber(value: self.itmValue))!) cells = ("Earnings", Formatter.currency.string(from: NSNumber(value: self.firstPrize))!)
} }
var leftAnchor = cell.contentView.leftAnchor var leftAnchor = cell.contentView.leftAnchor
@ -125,7 +125,7 @@ class TournamentStats : NSObject, HTMLRepresentable, UITableViewDelegate, UITabl
// MARK: - UICollectionViewDataSource // MARK: - UICollectionViewDataSource
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 3 return 4
} }
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
@ -144,8 +144,8 @@ class TournamentStats : NSObject, HTMLRepresentable, UITableViewDelegate, UITabl
name = "Prizepool".uppercased() name = "Prizepool".uppercased()
value = Formatter.currency.string(from: NSNumber(value: self.prizepool))! value = Formatter.currency.string(from: NSNumber(value: self.prizepool))!
case 3: case 3:
name = "Earnings".uppercased() name = "First prize".uppercased()
value = Formatter.currency.string(from: NSNumber(value: self.itmValue))! value = Formatter.currency.string(from: NSNumber(value: self.firstPrize))!
default: default:
name = "" name = ""
value = "" value = ""

Loading…
Cancel
Save