Distribution reports added

master
Laurent 6 years ago
parent 5489a0df0e
commit 13607b741b
  1. 4
      TournamentStats.xcodeproj/project.pbxproj
  2. BIN
      TournamentStats.xcodeproj/project.xcworkspace/xcuserdata/laurent.xcuserdatad/UserInterfaceState.xcuserstate
  3. 72
      TournamentStats/report/Queries.swift
  4. 5
      TournamentStats/report/ReportGenerator.swift
  5. 41
      TournamentStats/report/structures/TournamentCounter.swift

@ -7,6 +7,7 @@
objects = { objects = {
/* Begin PBXBuildFile section */ /* 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 */; }; 4DA5CA1E22AD078A00AC628E /* CountryCounter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DA5CA1D22AD078A00AC628E /* CountryCounter.swift */; };
4DDEF11422AE4FB900F4D7C1 /* TournamentStats.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DDEF11322AE4FB900F4D7C1 /* TournamentStats.swift */; }; 4DDEF11422AE4FB900F4D7C1 /* TournamentStats.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DDEF11322AE4FB900F4D7C1 /* TournamentStats.swift */; };
4DF7608422A3FB96004B0EF1 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DF7608322A3FB96004B0EF1 /* AppDelegate.swift */; }; 4DF7608422A3FB96004B0EF1 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DF7608322A3FB96004B0EF1 /* AppDelegate.swift */; };
@ -112,6 +113,7 @@
/* End PBXContainerItemProxy section */ /* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
4D18861022C36D8F0020C4CD /* TournamentCounter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TournamentCounter.swift; sourceTree = "<group>"; };
4DA5CA1D22AD078A00AC628E /* CountryCounter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CountryCounter.swift; sourceTree = "<group>"; }; 4DA5CA1D22AD078A00AC628E /* CountryCounter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CountryCounter.swift; sourceTree = "<group>"; };
4DDEF11322AE4FB900F4D7C1 /* TournamentStats.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TournamentStats.swift; sourceTree = "<group>"; }; 4DDEF11322AE4FB900F4D7C1 /* TournamentStats.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TournamentStats.swift; sourceTree = "<group>"; };
4DF7608022A3FB96004B0EF1 /* TournamentStats.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TournamentStats.app; sourceTree = BUILT_PRODUCTS_DIR; }; 4DF7608022A3FB96004B0EF1 /* TournamentStats.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TournamentStats.app; sourceTree = BUILT_PRODUCTS_DIR; };
@ -416,6 +418,7 @@
4DF7615022A7AECA004B0EF1 /* TournamentRepresentable.swift */, 4DF7615022A7AECA004B0EF1 /* TournamentRepresentable.swift */,
4DA5CA1D22AD078A00AC628E /* CountryCounter.swift */, 4DA5CA1D22AD078A00AC628E /* CountryCounter.swift */,
4DDEF11322AE4FB900F4D7C1 /* TournamentStats.swift */, 4DDEF11322AE4FB900F4D7C1 /* TournamentStats.swift */,
4D18861022C36D8F0020C4CD /* TournamentCounter.swift */,
); );
path = structures; path = structures;
sourceTree = "<group>"; sourceTree = "<group>";
@ -626,6 +629,7 @@
4DF7614622A59407004B0EF1 /* CumulatedResults.swift in Sources */, 4DF7614622A59407004B0EF1 /* CumulatedResults.swift in Sources */,
4DF760BF22A560AA004B0EF1 /* FileWriter.swift in Sources */, 4DF760BF22A560AA004B0EF1 /* FileWriter.swift in Sources */,
4DA5CA1E22AD078A00AC628E /* CountryCounter.swift in Sources */, 4DA5CA1E22AD078A00AC628E /* CountryCounter.swift in Sources */,
4D18861122C36D8F0020C4CD /* TournamentCounter.swift in Sources */,
4DF760BC22A5270E004B0EF1 /* Queries.swift in Sources */, 4DF760BC22A5270E004B0EF1 /* Queries.swift in Sources */,
4DF760BA22A524F4004B0EF1 /* Formatters.swift in Sources */, 4DF760BA22A524F4004B0EF1 /* Formatters.swift in Sources */,
4DF7614D22A6CC0D004B0EF1 /* NotablePlayers.swift in Sources */, 4DF7614D22A6CC0D004B0EF1 /* NotablePlayers.swift in Sources */,

@ -59,7 +59,7 @@ class Queries {
return cr1.numberOfCashes > cr2.numberOfCashes return cr1.numberOfCashes > cr2.numberOfCashes
}) })
} }
static func allWinnersSortedByEvent(realm: Realm, date: Date? = nil) -> [TournamentWinner] { static func allWinnersSortedByEvent(realm: Realm, date: Date? = nil) -> [TournamentWinner] {
let winners: Results<Result> let winners: Results<Result>
@ -68,7 +68,7 @@ class Queries {
} else { } else {
winners = realm.objects(Result.self).filter("rank == 1") winners = realm.objects(Result.self).filter("rank == 1")
} }
var tws: [TournamentWinner] = [] var tws: [TournamentWinner] = []
for w in winners { for w in winners {
@ -103,7 +103,7 @@ class Queries {
return prs return prs
} }
static func sortedEvents(realm: Realm, fieldName: String, ascending: Bool) -> [TournamentRepresentable] { static func sortedEvents(realm: Realm, fieldName: String, ascending: Bool) -> [TournamentRepresentable] {
let tournies = realm.objects(Tournament.self).sorted(byKeyPath: fieldName, ascending: ascending) let tournies = realm.objects(Tournament.self).sorted(byKeyPath: fieldName, ascending: ascending)
var trs: [TournamentRepresentable] = [] var trs: [TournamentRepresentable] = []
@ -176,4 +176,70 @@ class Queries {
return [] return []
} }
static func tournamentBuyinDistribution(realm: Realm) -> [DistributionCounter] {
let tournaments: Results<Tournament> = 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<Tournament> = 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
}
} }

@ -83,7 +83,12 @@ class ReportGenerator {
Queries.averageEvent(realm: realm).writeHTML(fileName: "reports/averageEvent.html") Queries.averageEvent(realm: realm).writeHTML(fileName: "reports/averageEvent.html")
Queries.mostCashes(realm: realm, notable: true).writeHTML(fileName: "reports/notablesMostCashes.html", limit: nil) 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.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")
} }
} }

@ -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: "</td><td>")
return "<tr class=\"table-header\"><td>\(all)</td></tr>"
}
func html() -> String {
var strings: [String] = []
strings.append(self.name)
strings.append("\(self.counter)")
let all = strings.joined(separator: "</td><td>")
return "<tr><td>\(all)</td></tr>"
}
}
Loading…
Cancel
Save