diff --git a/TournamentStats.xcodeproj/project.pbxproj b/TournamentStats.xcodeproj/project.pbxproj index 0450b7a..6691865 100644 --- a/TournamentStats.xcodeproj/project.pbxproj +++ b/TournamentStats.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 4D18861122C36D8F0020C4CD /* TournamentCounter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D18861022C36D8F0020C4CD /* TournamentCounter.swift */; }; 4DA5CA1E22AD078A00AC628E /* CountryCounter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DA5CA1D22AD078A00AC628E /* CountryCounter.swift */; }; 4DDEF11422AE4FB900F4D7C1 /* TournamentStats.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DDEF11322AE4FB900F4D7C1 /* TournamentStats.swift */; }; 4DF7608422A3FB96004B0EF1 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DF7608322A3FB96004B0EF1 /* AppDelegate.swift */; }; @@ -112,6 +113,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 4D18861022C36D8F0020C4CD /* TournamentCounter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TournamentCounter.swift; sourceTree = ""; }; 4DA5CA1D22AD078A00AC628E /* CountryCounter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CountryCounter.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; }; @@ -416,6 +418,7 @@ 4DF7615022A7AECA004B0EF1 /* TournamentRepresentable.swift */, 4DA5CA1D22AD078A00AC628E /* CountryCounter.swift */, 4DDEF11322AE4FB900F4D7C1 /* TournamentStats.swift */, + 4D18861022C36D8F0020C4CD /* TournamentCounter.swift */, ); path = structures; sourceTree = ""; @@ -626,6 +629,7 @@ 4DF7614622A59407004B0EF1 /* CumulatedResults.swift in Sources */, 4DF760BF22A560AA004B0EF1 /* FileWriter.swift in Sources */, 4DA5CA1E22AD078A00AC628E /* CountryCounter.swift in Sources */, + 4D18861122C36D8F0020C4CD /* TournamentCounter.swift in Sources */, 4DF760BC22A5270E004B0EF1 /* Queries.swift in Sources */, 4DF760BA22A524F4004B0EF1 /* Formatters.swift in Sources */, 4DF7614D22A6CC0D004B0EF1 /* NotablePlayers.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 ebd302f..5687a06 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 cbf07aa..4c5319e 100644 --- a/TournamentStats/report/Queries.swift +++ b/TournamentStats/report/Queries.swift @@ -59,7 +59,7 @@ class Queries { return cr1.numberOfCashes > cr2.numberOfCashes }) } - + static func allWinnersSortedByEvent(realm: Realm, date: Date? = nil) -> [TournamentWinner] { let winners: Results @@ -68,7 +68,7 @@ class Queries { } else { winners = realm.objects(Result.self).filter("rank == 1") } - + var tws: [TournamentWinner] = [] for w in winners { @@ -103,7 +103,7 @@ class Queries { return prs } - + static func sortedEvents(realm: Realm, fieldName: String, ascending: Bool) -> [TournamentRepresentable] { let tournies = realm.objects(Tournament.self).sorted(byKeyPath: fieldName, ascending: ascending) var trs: [TournamentRepresentable] = [] @@ -176,4 +176,70 @@ class Queries { return [] } + static func tournamentBuyinDistribution(realm: Realm) -> [DistributionCounter] { + + let tournaments: Results = realm.objects(Tournament.self) + + let low = DistributionCounter(name: "Low (<$2,000)") + let medium = DistributionCounter(name: "Medium ($2,000 - $5,000)") + let high = DistributionCounter(name: "High (> $5,000)") + let counters: [DistributionCounter] = [low, medium, high] + + tournaments.forEach { tournament in + switch tournament.buyin { + case 0..<2000: + low.increment() + case 2000...5000: + medium.increment() + default: + high.increment() + } + } + return counters + } + + static func tournamentPrizepoolDistribution(realm: Realm) -> [DistributionCounter] { + + let tournaments: Results = realm.objects(Tournament.self) + + let low = DistributionCounter(name: "Low (<$1M)") + let medium = DistributionCounter(name: "Medium ($1M - $5M)") + let high = DistributionCounter(name: "High (> 5M)") + let counters: [DistributionCounter] = [low, medium, high] + + tournaments.forEach { tournament in + switch tournament.prizepool { + case 0.0..<1000000.0: + low.increment() + case 1000000.0...5000000.0: + medium.increment() + default: + high.increment() + } + } + return counters + } + + static func firstPrizeDistribution(realm: Realm) -> [DistributionCounter] { + + let winnerResults = realm.objects(Result.self).filter("rank == 1") + + let low = DistributionCounter(name: "Low (<$250K)") + let medium = DistributionCounter(name: "Medium ($250K - $1M)") + let high = DistributionCounter(name: "High (> $1M)") + let counters: [DistributionCounter] = [low, medium, high] + + winnerResults.forEach { result in + switch result.earnings { + case 0.0..<250000.0: + low.increment() + case 250000.0...1000000.0: + medium.increment() + default: + high.increment() + } + } + return counters + } + } diff --git a/TournamentStats/report/ReportGenerator.swift b/TournamentStats/report/ReportGenerator.swift index 4c4f0c2..f7ff705 100644 --- a/TournamentStats/report/ReportGenerator.swift +++ b/TournamentStats/report/ReportGenerator.swift @@ -83,7 +83,12 @@ class ReportGenerator { Queries.averageEvent(realm: realm).writeHTML(fileName: "reports/averageEvent.html") Queries.mostCashes(realm: realm, notable: true).writeHTML(fileName: "reports/notablesMostCashes.html", limit: nil) Queries.averageCash(realm: realm).writeHTML(fileName: "reports/bestAverageCashes.html", limit: 5) + Queries.tournamentBuyinDistribution(realm: realm).writeHTML(fileName: "reports/buyinDistribution.html") + Queries.tournamentPrizepoolDistribution(realm: realm).writeHTML(fileName: "reports/prizepoolDistribution.html") + Queries.firstPrizeDistribution(realm: realm).writeHTML(fileName: "reports/firstPrizeDistribution.html") + + } } diff --git a/TournamentStats/report/structures/TournamentCounter.swift b/TournamentStats/report/structures/TournamentCounter.swift new file mode 100644 index 0000000..a31fcf3 --- /dev/null +++ b/TournamentStats/report/structures/TournamentCounter.swift @@ -0,0 +1,41 @@ +// +// TournamentCounter.swift +// TournamentStats +// +// Created by Laurent Morvillier on 26/06/2019. +// Copyright © 2019 Stax River. All rights reserved. +// + +import Foundation + +class DistributionCounter : HTMLRepresentable { + + var name: String + var counter: Int = 0 + + init(name: String) { + self.name = name + } + + func increment() { + self.counter += 1 + } + + static func htmlHeaders() -> String { + var strings: [String] = [] + strings.append("Tournament") + strings.append("Counter") + let all = strings.joined(separator: "") + return "\(all)" + } + + func html() -> String { + + var strings: [String] = [] + strings.append(self.name) + strings.append("\(self.counter)") + let all = strings.joined(separator: "") + return "\(all)" + } + +}