From 54f30cb52758a0ab6fd3f517cb2baa77a90b6c2a Mon Sep 17 00:00:00 2001 From: Laurent Date: Thu, 27 Jun 2019 12:12:56 +0200 Subject: [PATCH] updated data + added a chip count % calculator --- TournamentStats.xcodeproj/project.pbxproj | 38 +- .../xcdebugger/Breakpoints_v2.xcbkptlist | 16 + TournamentStats/Base.lproj/Main.storyboard | 15 +- TournamentStats/ChipCountParser.swift | 95 + TournamentStats/Events/chipcount | 79 + TournamentStats/Events/event2 copie 13 | 217 - TournamentStats/Events/event2 copie 14 | 217 - TournamentStats/Events/event50 | 6335 +++++++++++++++++ TournamentStats/Events/event57 | 2262 ++++++ TournamentStats/Seed.swift | 5 +- TournamentStats/UI/MasterViewController.swift | 45 +- TournamentStats/realm/Model.swift | 2 +- .../report/structures/ChipCount.swift | 28 + 13 files changed, 8864 insertions(+), 490 deletions(-) create mode 100644 TournamentStats/ChipCountParser.swift create mode 100644 TournamentStats/Events/chipcount delete mode 100644 TournamentStats/Events/event2 copie 13 delete mode 100644 TournamentStats/Events/event2 copie 14 create mode 100644 TournamentStats/Events/event50 create mode 100644 TournamentStats/Events/event57 create mode 100644 TournamentStats/report/structures/ChipCount.swift diff --git a/TournamentStats.xcodeproj/project.pbxproj b/TournamentStats.xcodeproj/project.pbxproj index 460d850..94734a5 100644 --- a/TournamentStats.xcodeproj/project.pbxproj +++ b/TournamentStats.xcodeproj/project.pbxproj @@ -7,6 +7,9 @@ objects = { /* Begin PBXBuildFile section */ + 4D0F103522C4C04F005F797A /* chipcount in Resources */ = {isa = PBXBuildFile; fileRef = 4D0F103422C4C04F005F797A /* chipcount */; }; + 4D0F103722C4C08F005F797A /* ChipCount.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D0F103622C4C08F005F797A /* ChipCount.swift */; }; + 4D0F103922C4C1C4005F797A /* ChipCountParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D0F103822C4C1C4005F797A /* ChipCountParser.swift */; }; 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 */; }; @@ -34,10 +37,10 @@ 4DF7610822A56797004B0EF1 /* event3 copie 10 in Resources */ = {isa = PBXBuildFile; fileRef = 4DF760CC22A56793004B0EF1 /* event3 copie 10 */; }; 4DF7610922A56797004B0EF1 /* event28 in Resources */ = {isa = PBXBuildFile; fileRef = 4DF760CD22A56793004B0EF1 /* event28 */; }; 4DF7610A22A56797004B0EF1 /* event32 in Resources */ = {isa = PBXBuildFile; fileRef = 4DF760CE22A56793004B0EF1 /* event32 */; }; - 4DF7610B22A56797004B0EF1 /* event2 copie 13 in Resources */ = {isa = PBXBuildFile; fileRef = 4DF760CF22A56793004B0EF1 /* event2 copie 13 */; }; + 4DF7610B22A56797004B0EF1 /* event50 in Resources */ = {isa = PBXBuildFile; fileRef = 4DF760CF22A56793004B0EF1 /* event50 */; }; 4DF7610C22A56797004B0EF1 /* event7 in Resources */ = {isa = PBXBuildFile; fileRef = 4DF760D022A56793004B0EF1 /* event7 */; }; 4DF7610D22A56797004B0EF1 /* event55 in Resources */ = {isa = PBXBuildFile; fileRef = 4DF760D122A56793004B0EF1 /* event55 */; }; - 4DF7610E22A56797004B0EF1 /* event2 copie 14 in Resources */ = {isa = PBXBuildFile; fileRef = 4DF760D222A56793004B0EF1 /* event2 copie 14 */; }; + 4DF7610E22A56797004B0EF1 /* event57 in Resources */ = {isa = PBXBuildFile; fileRef = 4DF760D222A56793004B0EF1 /* event57 */; }; 4DF7610F22A56797004B0EF1 /* event2 copie 15 in Resources */ = {isa = PBXBuildFile; fileRef = 4DF760D322A56793004B0EF1 /* event2 copie 15 */; }; 4DF7611022A56797004B0EF1 /* event9 in Resources */ = {isa = PBXBuildFile; fileRef = 4DF760D422A56793004B0EF1 /* event9 */; }; 4DF7611122A56797004B0EF1 /* event3 copie 12 in Resources */ = {isa = PBXBuildFile; fileRef = 4DF760D522A56794004B0EF1 /* event3 copie 12 */; }; @@ -113,6 +116,9 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 4D0F103422C4C04F005F797A /* chipcount */ = {isa = PBXFileReference; lastKnownFileType = text; path = chipcount; sourceTree = ""; }; + 4D0F103622C4C08F005F797A /* ChipCount.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChipCount.swift; sourceTree = ""; }; + 4D0F103822C4C1C4005F797A /* ChipCountParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChipCountParser.swift; sourceTree = ""; }; 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 = ""; }; @@ -144,10 +150,10 @@ 4DF760CC22A56793004B0EF1 /* event3 copie 10 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "event3 copie 10"; sourceTree = ""; }; 4DF760CD22A56793004B0EF1 /* event28 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = event28; sourceTree = ""; }; 4DF760CE22A56793004B0EF1 /* event32 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = event32; sourceTree = ""; }; - 4DF760CF22A56793004B0EF1 /* event2 copie 13 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "event2 copie 13"; sourceTree = ""; }; + 4DF760CF22A56793004B0EF1 /* event50 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = event50; sourceTree = ""; }; 4DF760D022A56793004B0EF1 /* event7 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = event7; sourceTree = ""; }; 4DF760D122A56793004B0EF1 /* event55 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = event55; sourceTree = ""; }; - 4DF760D222A56793004B0EF1 /* event2 copie 14 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "event2 copie 14"; sourceTree = ""; }; + 4DF760D222A56793004B0EF1 /* event57 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = event57; sourceTree = ""; }; 4DF760D322A56793004B0EF1 /* event2 copie 15 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "event2 copie 15"; sourceTree = ""; }; 4DF760D422A56793004B0EF1 /* event9 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = event9; sourceTree = ""; }; 4DF760D522A56794004B0EF1 /* event3 copie 12 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "event3 copie 12"; sourceTree = ""; }; @@ -261,6 +267,7 @@ 4DF760C322A56207004B0EF1 /* utils */, 4DF7614422A593FC004B0EF1 /* report */, 4DF760AF22A47C74004B0EF1 /* Importer.swift */, + 4D0F103822C4C1C4005F797A /* ChipCountParser.swift */, 4DF760C822A56497004B0EF1 /* Seed.swift */, 4DF7614C22A6CC0D004B0EF1 /* NotablePlayers.swift */, 4DF760C022A561A8004B0EF1 /* UI */, @@ -310,15 +317,9 @@ 4DF760B622A47F72004B0EF1 /* Events */ = { isa = PBXGroup; children = ( + 4D0F103422C4C04F005F797A /* chipcount */, 4DF760C422A56451004B0EF1 /* event1 */, 4DF760B422A47F6D004B0EF1 /* event2 */, - 4DF760D122A56793004B0EF1 /* event55 */, - 4DF7610522A56797004B0EF1 /* event52 */, - 4DF760F422A56795004B0EF1 /* event53 */, - 4DF760EC22A56795004B0EF1 /* event54 */, - 4DF7610122A56796004B0EF1 /* event56 */, - 4DF760CF22A56793004B0EF1 /* event2 copie 13 */, - 4DF760D222A56793004B0EF1 /* event2 copie 14 */, 4DF760D322A56793004B0EF1 /* event2 copie 15 */, 4DF760B722A5234D004B0EF1 /* event3 */, 4DF7610622A56797004B0EF1 /* event3 copie 5 */, @@ -376,7 +377,14 @@ 4DF760E122A56794004B0EF1 /* event47 */, 4DF760DC22A56794004B0EF1 /* event48 */, 4DF760F622A56796004B0EF1 /* event49 */, + 4DF760CF22A56793004B0EF1 /* event50 */, 4DF760E222A56794004B0EF1 /* event51 */, + 4DF7610522A56797004B0EF1 /* event52 */, + 4DF760F422A56795004B0EF1 /* event53 */, + 4DF760EC22A56795004B0EF1 /* event54 */, + 4DF760D122A56793004B0EF1 /* event55 */, + 4DF7610122A56796004B0EF1 /* event56 */, + 4DF760D222A56793004B0EF1 /* event57 */, ); path = Events; sourceTree = ""; @@ -419,6 +427,7 @@ 4DA5CA1D22AD078A00AC628E /* CountryCounter.swift */, 4DDEF11322AE4FB900F4D7C1 /* TournamentStats.swift */, 4D18861022C36D8F0020C4CD /* TournamentCounter.swift */, + 4D0F103622C4C08F005F797A /* ChipCount.swift */, ); path = structures; sourceTree = ""; @@ -532,7 +541,7 @@ 4DF7610C22A56797004B0EF1 /* event7 in Resources */, FFE9052C22BB7313006FEFA4 /* event34 in Resources */, 4DF7613122A56797004B0EF1 /* event20 in Resources */, - 4DF7610E22A56797004B0EF1 /* event2 copie 14 in Resources */, + 4DF7610E22A56797004B0EF1 /* event57 in Resources */, 4DF7611622A56797004B0EF1 /* event16 in Resources */, 4DF7611C22A56797004B0EF1 /* event3 copie 7 in Resources */, 4DF7611022A56797004B0EF1 /* event9 in Resources */, @@ -556,7 +565,8 @@ 4DF7613922A56797004B0EF1 /* event35 in Resources */, 4DF7611522A56797004B0EF1 /* event30 in Resources */, 4DF7611422A56797004B0EF1 /* event10 in Resources */, - 4DF7610B22A56797004B0EF1 /* event2 copie 13 in Resources */, + 4D0F103522C4C04F005F797A /* chipcount in Resources */, + 4DF7610B22A56797004B0EF1 /* event50 in Resources */, 4DF7612E22A56797004B0EF1 /* event12 in Resources */, 4DF7612222A56797004B0EF1 /* event38 in Resources */, 4DF7611122A56797004B0EF1 /* event3 copie 12 in Resources */, @@ -618,6 +628,7 @@ 4DF760C222A561FF004B0EF1 /* CSVUtils.swift in Sources */, 4DF760B022A47C74004B0EF1 /* Importer.swift in Sources */, 4DF7614A22A66675004B0EF1 /* TournamentWinner.swift in Sources */, + 4D0F103722C4C08F005F797A /* ChipCount.swift in Sources */, 4DF760B322A47CAE004B0EF1 /* Realm+Extensions.swift in Sources */, 4DF7608822A3FB96004B0EF1 /* DetailViewController.swift in Sources */, 4DF7615122A7AECA004B0EF1 /* TournamentRepresentable.swift in Sources */, @@ -627,6 +638,7 @@ 4DF760A722A3FD12004B0EF1 /* Model.swift in Sources */, 4DF7614F22A6CF93004B0EF1 /* PlayerResult.swift in Sources */, 4DF7614622A59407004B0EF1 /* CumulatedResults.swift in Sources */, + 4D0F103922C4C1C4005F797A /* ChipCountParser.swift in Sources */, 4DF760BF22A560AA004B0EF1 /* FileWriter.swift in Sources */, 4DA5CA1E22AD078A00AC628E /* CountryCounter.swift in Sources */, 4D18861122C36D8F0020C4CD /* TournamentCounter.swift in Sources */, diff --git a/TournamentStats.xcodeproj/xcuserdata/laurent.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/TournamentStats.xcodeproj/xcuserdata/laurent.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index d1be75d..c76a749 100644 --- a/TournamentStats.xcodeproj/xcuserdata/laurent.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/TournamentStats.xcodeproj/xcuserdata/laurent.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -11,5 +11,21 @@ continueAfterRunningActions = "No"> + + + + diff --git a/TournamentStats/Base.lproj/Main.storyboard b/TournamentStats/Base.lproj/Main.storyboard index 2631ec1..d9e1a32 100644 --- a/TournamentStats/Base.lproj/Main.storyboard +++ b/TournamentStats/Base.lproj/Main.storyboard @@ -83,20 +83,27 @@ - + - diff --git a/TournamentStats/ChipCountParser.swift b/TournamentStats/ChipCountParser.swift new file mode 100644 index 0000000..f6bf97c --- /dev/null +++ b/TournamentStats/ChipCountParser.swift @@ -0,0 +1,95 @@ +// +// ChipCountParser.swift +// TournamentStats +// +// Created by Laurent Morvillier on 27/06/2019. +// Copyright © 2019 Stax River. All rights reserved. +// + +import Foundation +import RealmSwift +import Realm + +enum ChipCountColumns : CaseIterable { + case rank + case player + case chipcount + case trend + case city + case state +} + +class ChipCountParser { + + static func start() -> ChipCountManager { + + let realm = try! Realm() + + var ccm = ChipCountManager(chipCounts: [], totalChips: 0.0) + + try! realm.write { + + let resourceName = "chipcount" + let path: String? = Bundle.main.path(forResource: resourceName, ofType: "") + if let path = path { + do { + let data = try String(contentsOfFile: path, encoding: .utf8) + ccm = ChipCountParser.parse(realm: realm, data: data) + } catch { + print(error) + } + } else { + print("could not find path for chipcount") + } + + + } + return ccm + } + + static func parse(realm: Realm, data: String) -> ChipCountManager { + + // cleanup raw data + let rawRows = data.split(separator: "\n") + var rows = rawRows.map { String($0) } + rows = rows.filter { !$0.isEmpty } + + let columns = ChipCountColumns.allCases + let numberOfColumns = columns.count + + let formatter = Formatter.importData + + var playerName: String = "" + var totalChips: Double = 0.0 + var ccs: [ChipCount] = [] + + for i in 0.. Int { - return reports.count + return self.ccManager.chipCounts.count } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) - let object = reports[indexPath.row] as! NSDate - cell.textLabel!.text = object.description + let chipCount = self.ccManager.chipCounts[indexPath.row] + cell.textLabel!.text = chipCount.player + cell.detailTextLabel?.text = chipCount.percentage(totalChips: self.ccManager.totalChips) return cell } - override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { - // Return false if you do not want the specified item to be editable. - return true - } - - override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { - if editingStyle == .delete { - reports.remove(at: indexPath.row) - tableView.deleteRows(at: [indexPath], with: .fade) - } else if editingStyle == .insert { - // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view. - } - } - - } diff --git a/TournamentStats/realm/Model.swift b/TournamentStats/realm/Model.swift index 825ceaf..35312e5 100644 --- a/TournamentStats/realm/Model.swift +++ b/TournamentStats/realm/Model.swift @@ -32,7 +32,7 @@ class Tournament : Object, Named { var rows: [Columns] { switch self.number { - case 1, 10, 32, 39, 47, 55, 53: return [.rank, .player, .earnings, .city, .state, .country] + case 1, 10, 32, 39, 47, 55, 53, 57: return [.rank, .player, .earnings, .city, .state, .country] default: return Tournament.defaultColumns } } diff --git a/TournamentStats/report/structures/ChipCount.swift b/TournamentStats/report/structures/ChipCount.swift new file mode 100644 index 0000000..8be2440 --- /dev/null +++ b/TournamentStats/report/structures/ChipCount.swift @@ -0,0 +1,28 @@ +// +// ChipCount.swift +// TournamentStats +// +// Created by Laurent Morvillier on 27/06/2019. +// Copyright © 2019 Stax River. All rights reserved. +// + +import Foundation + +struct ChipCountManager { + + var chipCounts: [ChipCount] + var totalChips: Double + +} + +struct ChipCount { + + var player: String + var chips: Double + + func percentage(totalChips: Double) -> String { + let percentage = self.chips / totalChips * 100 + return "\(percentage)%" + } + +}