From 8e58237e2df07616721c9be6b756495bd40d98bb Mon Sep 17 00:00:00 2001 From: Laurent Date: Wed, 28 Aug 2019 16:30:46 +0200 Subject: [PATCH] More improvements --- TournamentStats/report/Queries.swift | 9 +++++---- .../report/structures/CumulatedResults.swift | 2 +- .../report/structures/TournamentStats.swift | 16 ++++++++-------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/TournamentStats/report/Queries.swift b/TournamentStats/report/Queries.swift index 7034fce..45d7a1b 100644 --- a/TournamentStats/report/Queries.swift +++ b/TournamentStats/report/Queries.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] } diff --git a/TournamentStats/report/structures/CumulatedResults.swift b/TournamentStats/report/structures/CumulatedResults.swift index ce5d0a3..d4655f5 100644 --- a/TournamentStats/report/structures/CumulatedResults.swift +++ b/TournamentStats/report/structures/CumulatedResults.swift @@ -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)] } diff --git a/TournamentStats/report/structures/TournamentStats.swift b/TournamentStats/report/structures/TournamentStats.swift index a2c788c..c295c51 100644 --- a/TournamentStats/report/structures/TournamentStats.swift +++ b/TournamentStats/report/structures/TournamentStats.swift @@ -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 = ""