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 prizepool: Double? = tournaments.average(ofProperty: "prizepool")
let itmCount: Double = tournaments.reduce(0.0) { $0 + Double($1.results.count) }
let avgItmCount = itmCount / Double(tournaments.count)
let winnerResults = tournaments.compactMap { (tournament) -> Result? in
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 {
let itm = prizepool / avgItmCount
let ts = TournamentStats(entries: entries, buyin: buyin, prizepool: prizepool, itmValue: itm)
let ts = TournamentStats(entries: entries, buyin: buyin, prizepool: prizepool, firstPrize: averageFirstPrize)
return [ts]
}

@ -47,7 +47,7 @@ class CumulatedResults : HTMLRepresentable, ColumnRepresentable {
let totalColumn = self.average ? "Average Earnings" : "Total Earnings"
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)]
}

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

Loading…
Cancel
Save