diff --git a/TournamentStats.xcodeproj/project.pbxproj b/TournamentStats.xcodeproj/project.pbxproj index 4a961cd..467f5a7 100644 --- a/TournamentStats.xcodeproj/project.pbxproj +++ b/TournamentStats.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 4DA5CA1E22AD078A00AC628E /* CountryCashes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DA5CA1D22AD078A00AC628E /* CountryCashes.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 */; }; 4DF7608822A3FB96004B0EF1 /* DetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DF7608722A3FB96004B0EF1 /* DetailViewController.swift */; }; @@ -109,6 +110,7 @@ /* Begin PBXFileReference section */ 4DA5CA1D22AD078A00AC628E /* CountryCashes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CountryCashes.swift; sourceTree = ""; }; + 4DDEF11322AE4FB900F4D7C1 /* TournamentStats.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TournamentStats.swift; sourceTree = ""; }; 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 = ""; }; 4DF7608522A3FB96004B0EF1 /* MasterViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MasterViewController.swift; sourceTree = ""; }; @@ -404,6 +406,7 @@ 4DF7614E22A6CF93004B0EF1 /* PlayerResult.swift */, 4DF7615022A7AECA004B0EF1 /* TournamentRepresentable.swift */, 4DA5CA1D22AD078A00AC628E /* CountryCashes.swift */, + 4DDEF11322AE4FB900F4D7C1 /* TournamentStats.swift */, ); path = structures; sourceTree = ""; @@ -605,6 +608,7 @@ 4DF7615122A7AECA004B0EF1 /* TournamentRepresentable.swift in Sources */, 4DF7608622A3FB96004B0EF1 /* MasterViewController.swift in Sources */, 4DF7608422A3FB96004B0EF1 /* AppDelegate.swift in Sources */, + 4DDEF11422AE4FB900F4D7C1 /* TournamentStats.swift in Sources */, 4DF760A722A3FD12004B0EF1 /* Model.swift in Sources */, 4DF7614F22A6CF93004B0EF1 /* PlayerResult.swift in Sources */, 4DF7614622A59407004B0EF1 /* CumulatedResults.swift in Sources */, diff --git a/TournamentStats.xcodeproj/project.xcworkspace/xcuserdata/laurent.xcuserdatad/UserInterfaceState.xcuserstate b/TournamentStats.xcodeproj/project.xcworkspace/xcuserdata/laurent.xcuserdatad/UserInterfaceState.xcuserstate index 33b3a0a..b2786c8 100644 Binary files a/TournamentStats.xcodeproj/project.xcworkspace/xcuserdata/laurent.xcuserdatad/UserInterfaceState.xcuserstate and b/TournamentStats.xcodeproj/project.xcworkspace/xcuserdata/laurent.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/TournamentStats/report/Queries.swift b/TournamentStats/report/Queries.swift index d6ff467..02c62e1 100644 --- a/TournamentStats/report/Queries.swift +++ b/TournamentStats/report/Queries.swift @@ -116,4 +116,25 @@ class Queries { return countryCashes } + static func averageEvent(realm: Realm) -> [TournamentStats] { + + let tournaments: Results = realm.objects(Tournament.self) + let entries: Double? = tournaments.average(ofProperty: "entries") + let buyin: Double? = tournaments.average(ofProperty: "buyin") + let prizepool: Double? = tournaments.average(ofProperty: "prizepool") + +// let itmCount: Double? = tournaments.sum(ofProperty: "results.count") + + let itmCount: Double = tournaments.reduce(0.0) { $0 + Double($1.results.count) } + let avgItmCount = itmCount / 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) + return [ts] + } + + return [] + } + } diff --git a/TournamentStats/report/ReportGenerator.swift b/TournamentStats/report/ReportGenerator.swift index cdd224b..92f27f1 100644 --- a/TournamentStats/report/ReportGenerator.swift +++ b/TournamentStats/report/ReportGenerator.swift @@ -50,11 +50,8 @@ class ReportGenerator { let realm = try! Realm() - let winners = Queries.biggestWinners(realm: realm) - winners.writeHTML(fileName: "reports/earningsLeaderboard.html") - - let mostCashes = Queries.mostCashes(realm: realm) - mostCashes.writeHTML(fileName: "reports/mostCashes.html", limit: 25) + Queries.biggestWinners(realm: realm).writeHTML(fileName: "reports/earningsLeaderboard.html") + Queries.mostCashes(realm: realm).writeHTML(fileName: "reports/mostCashes.html", limit: 25) let tournamentWinners = Queries.allWinnersSortedByEvent(realm: realm) tournamentWinners.writeHTML(fileName: "reports/allWinners.html", limit: nil) @@ -81,8 +78,8 @@ class ReportGenerator { tourniesByPrizepool.writeHTML(fileName: "reports/tourniesByPrizepool.html", limit: nil) tourniesByPrizepool.writeHTML(fileName: "reports/tourniesByPrizepool_top5.html", limit: 5) - let countryCashes = Queries.cashesByCountry(realm: realm) - countryCashes.writeHTML(fileName: "reports/countryCashes.html") + Queries.cashesByCountry(realm: realm).writeHTML(fileName: "reports/countryCashes.html") + Queries.averageEvent(realm: realm).writeHTML(fileName: "reports/averageEvent.html") } diff --git a/TournamentStats/report/structures/TournamentStats.swift b/TournamentStats/report/structures/TournamentStats.swift new file mode 100644 index 0000000..06f570d --- /dev/null +++ b/TournamentStats/report/structures/TournamentStats.swift @@ -0,0 +1,42 @@ +// +// TournamentStats.swift +// TournamentStats +// +// Created by Laurent Morvillier on 10/06/2019. +// Copyright © 2019 Stax River. All rights reserved. +// + +import Foundation + +struct TournamentStats : HTMLRepresentable { + + var entries: Double + var buyin: Double + var prizepool: Double + var itmValue: Double + + static func htmlHeaders() -> String { + return "" + } + + func html() -> String { + let formatter = NumberFormatter() + + var strings: [(String, String)] = [] + strings.append(("Entries", formatter.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))!)) + + var all = "" + strings.forEach { (tuple) in + let table = [tuple.0, tuple.1] + let joined = table.joined(separator: "") + all.append("") + all.append(joined) + all.append("\n") + } + return all + } + +}