best and worst stats

This commit is contained in:
Michael Simard
2021-01-10 09:44:21 -06:00
parent a3977ac3ac
commit f974477106
5 changed files with 252 additions and 67 deletions

View File

@@ -50,8 +50,9 @@ final class OverallStats: Content {
var statsWithHyder:Stats
var statsWithoutHyder:Stats
var dashboardItems:[DashboardItem] = []
init( overall:StatsWithMostRecentDailyRecord, mwStats:StatsWithMostRecentDailyRecord, bocwStats:StatsWithMostRecentDailyRecord, mostRecentRecord:String, statsWithHyder:Stats, statsWithoutHyder:Stats){
init( overall:StatsWithMostRecentDailyRecord, mwStats:StatsWithMostRecentDailyRecord, bocwStats:StatsWithMostRecentDailyRecord, mostRecentRecord:String, statsWithHyder:Stats, statsWithoutHyder:Stats, dashboardItems:[DashboardItem]){
self.overall = overall
self.mwStats = mwStats;
@@ -60,6 +61,8 @@ final class OverallStats: Content {
self.statsWithHyder = statsWithHyder
self.statsWithoutHyder = statsWithoutHyder
self.dashboardItems = dashboardItems
}
}
@@ -81,15 +84,39 @@ final class MonthStats: Content {
final class Stats: Content {
var winLossRatio:String
var winLossRatio:String {
get {
return getRatio()
}
}
var totalWins:Int
var totalLosses:Int
init( winLoss:String, totalWins:Int, totalLosses:Int) {
self.winLossRatio = winLoss
init( totalWins:Int, totalLosses:Int) {
self.totalWins = totalWins
self.totalLosses = totalLosses
}
var record:String {
return "\(totalWins)-\(totalLosses)"
}
private func getRatio() -> String {
var returnString = ""
let deno = (totalLosses != 0) ? totalLosses : 1
returnString = String(getRatioDouble())
if deno == 0 {
returnString = returnString + "+"
}
return returnString
}
func getRatioDouble() -> Double {
let deno = (totalLosses != 0) ? totalLosses : 1
return (Double(totalWins) / Double(deno)).truncate(places: 3)
}
}
final class StatsWithMostRecentDailyRecord: Content {
@@ -104,6 +131,10 @@ final class StatsWithMostRecentDailyRecord: Content {
self.totalLosses = totalLosses
self.mostRecentRecord = mostRecentRecord
}
var record:String {
return "\(totalWins)-\(totalLosses)"
}
}