You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
146 lines
6.5 KiB
146 lines
6.5 KiB
//
|
|
// ReportGenerator.swift
|
|
// TournamentStats
|
|
//
|
|
// Created by Laurent Morvillier on 03/06/2019.
|
|
// Copyright © 2019 Stax River. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import RealmSwift
|
|
import Realm
|
|
|
|
class ReportGenerator {
|
|
|
|
static private let winnersDirectoryName: String = "reports/winners"
|
|
|
|
func go(importData: Bool) {
|
|
|
|
if (importData) {
|
|
|
|
let realm = try! Realm()
|
|
try! realm.write {
|
|
realm.deleteAll()
|
|
}
|
|
|
|
Seed.createTournaments()
|
|
RowImporter.start()
|
|
}
|
|
|
|
self.generate()
|
|
|
|
}
|
|
|
|
func generate() {
|
|
self.generateReports()
|
|
self.writeHTML()
|
|
}
|
|
|
|
func createDirectories() {
|
|
|
|
// Create winners directory if necessary
|
|
if let docDirectory = FileUtils.documentsDirectoryPath {
|
|
let winnersDirectory = docDirectory.appendingPathComponent(ReportGenerator.winnersDirectoryName)
|
|
var isDir: ObjCBool = true
|
|
if !FileManager.default.fileExists(atPath: winnersDirectory.absoluteString, isDirectory: &isDir) {
|
|
do {
|
|
try FileManager.default.createDirectory(at: winnersDirectory, withIntermediateDirectories: true, attributes: nil)
|
|
} catch {
|
|
print(error)
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
var festivalStats: FestivalStats = FestivalStats()
|
|
var biggestWinners: [CumulatedResults] = []
|
|
var mostWins: [CumulatedWins] = []
|
|
var mostCashes: [CumulatedResults] = []
|
|
var tournamentWinners: [TournamentWinner] = []
|
|
var tourniesByEntries: [TournamentRepresentable] = []
|
|
var tourniesByPrizepool: [TournamentRepresentable] = []
|
|
var winsByCountry: [CountryCounter] = []
|
|
var USAvsWorldWins: [CountryCounter] = []
|
|
var cashesByCountry: [CountryCounter] = []
|
|
var averageEvent: [TournamentStats] = []
|
|
var notablesMostCashes: [CumulatedResults] = []
|
|
var averageCash: [CumulatedResults] = []
|
|
var tournamentBuyinDistribution: [DistributionCounter] = []
|
|
var tournamentPrizepoolDistribution: [DistributionCounter] = []
|
|
var firstPrizeDistribution: [DistributionCounter] = []
|
|
var gamesDistribution: [DistributionCounter] = []
|
|
var rankings1: PlayerNotableFinishesDataSource = PlayerNotableFinishesDataSource(notableFinishes: [])
|
|
var finalTables: [CumulatedResults] = []
|
|
var tableSizeDistribution: [DistributionCounter] = []
|
|
|
|
func generateReports() {
|
|
|
|
self.createDirectories()
|
|
|
|
let realm = try! Realm()
|
|
|
|
self.festivalStats = Queries.festivalStats(realm: realm)
|
|
self.biggestWinners = Queries.biggestWinners(realm: realm)
|
|
self.mostWins = Queries.mostWins(realm: realm)
|
|
self.mostCashes = Queries.mostCashes(realm: realm)
|
|
self.tournamentWinners = Queries.allWinnersSortedByEvent(realm: realm)
|
|
self.tourniesByEntries = Queries.sortedEvents(realm: realm, fieldName: "entries", ascending: false)
|
|
self.tourniesByPrizepool = Queries.sortedEvents(realm: realm, fieldName: "prizepool", ascending: false)
|
|
self.winsByCountry = Queries.winsByCountry(realm: realm)
|
|
self.USAvsWorldWins = CountryCounter.aggregate(table: self.winsByCountry, param: "United States")
|
|
self.cashesByCountry = Queries.cashesByCountry(realm: realm)
|
|
self.averageEvent = Queries.averageEvent(realm: realm)
|
|
self.notablesMostCashes = Queries.mostCashes(realm: realm, notable: true)
|
|
self.averageCash = Queries.averageCash(realm: realm, minCount: 4)
|
|
self.tournamentBuyinDistribution = Queries.tournamentBuyinDistribution(realm: realm)
|
|
self.tournamentPrizepoolDistribution = Queries.tournamentPrizepoolDistribution(realm: realm)
|
|
self.firstPrizeDistribution = Queries.firstPrizeDistribution(realm: realm)
|
|
self.gamesDistribution = Queries.gamesDistribution(realm: realm)
|
|
|
|
let pnds = PlayerNotableFinishesDataSource(notableFinishes: Queries.rankingCounts(realm: realm))
|
|
self.rankings1 = pnds
|
|
self.finalTables = pnds.finalTablesCumulated()
|
|
|
|
self.tableSizeDistribution = Queries.tableSizeDistribution(realm: realm)
|
|
|
|
let tourniesDate = realm.objects(Tournament.self).distinct(by: ["date"])
|
|
|
|
// Individual days
|
|
for tourny in tourniesDate {
|
|
let date = tourny.date
|
|
let fileDate = Formatter.fileDate.string(from: date)
|
|
|
|
let dayWinners = Queries.allWinnersSortedByEvent(realm: realm, date: date)
|
|
dayWinners.writeHTML(fileName: "reports/winners/bracelets_\(fileDate).html")
|
|
|
|
let notableCashes = Queries.notableCashes(realm: realm, date: date)
|
|
notableCashes.writeHTML(fileName: "reports/winners/notables_\(fileDate).html")
|
|
}
|
|
|
|
print("total player count = \(realm.objects(Player.self).count)") // 16203, 16129
|
|
|
|
}
|
|
|
|
fileprivate func writeHTML() {
|
|
self.biggestWinners.writeHTML(fileName: "reports/earningsLeaderboard.html")
|
|
self.mostCashes.writeHTML(fileName: "reports/mostCashes.html", limit: 25)
|
|
self.tournamentWinners.writeHTML(fileName: "reports/allWinners.html", limit: nil)
|
|
self.tournamentWinners.writeHTML(fileName: "reports/allWinners_top10.html", limit: 10)
|
|
self.tourniesByEntries.writeHTML(fileName: "reports/tourniesByEntries.html", limit: nil)
|
|
self.tourniesByEntries.writeHTML(fileName: "reports/tourniesByEntries_top5.html", limit: 5)
|
|
self.tourniesByPrizepool.writeHTML(fileName: "reports/tourniesByPrizepool.html", limit: nil)
|
|
self.tourniesByPrizepool.writeHTML(fileName: "reports/tourniesByPrizepool_top5.html", limit: 5)
|
|
self.winsByCountry.writeHTML(fileName: "reports/countryWins.html")
|
|
self.cashesByCountry.writeHTML(fileName: "reports/countryCashes.html")
|
|
self.averageEvent.writeHTML(fileName: "reports/averageEvent.html")
|
|
self.notablesMostCashes.writeHTML(fileName: "reports/notablesMostCashes.html", limit: nil)
|
|
self.averageCash.writeHTML(fileName: "reports/bestAverageCashes.html", limit: 5)
|
|
self.tournamentBuyinDistribution.writeHTML(fileName: "reports/buyinDistribution.html")
|
|
self.tournamentPrizepoolDistribution.writeHTML(fileName: "reports/prizepoolDistribution.html")
|
|
self.firstPrizeDistribution.writeHTML(fileName: "reports/firstPrizeDistribution.html")
|
|
self.gamesDistribution.writeHTML(fileName: "reports/holdemDistribution.html")
|
|
|
|
}
|
|
|
|
}
|
|
|