From 69829a9f01a47abe6355aff73d346e3b3f37a091 Mon Sep 17 00:00:00 2001 From: Michael Simard Date: Fri, 22 Jan 2021 11:58:18 -0600 Subject: [PATCH] win rate, 2020 bug --- Sources/App/Controllers/StatsController.swift | 16 +++++++++++++++- Sources/App/Models/AllStats.swift | 4 ++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Sources/App/Controllers/StatsController.swift b/Sources/App/Controllers/StatsController.swift index 398fee5..dd4080a 100644 --- a/Sources/App/Controllers/StatsController.swift +++ b/Sources/App/Controllers/StatsController.swift @@ -154,7 +154,20 @@ struct StatsController: RouteCollection { let startDate = userCalendar.date(from: dateComponents) - return Match.query(on: req.db).filter(\.$date > startDate!).all().map { (matches) -> (Stats) in + + var endDateComponenents = DateComponents() + endDateComponenents.year = year + 1 + endDateComponenents.month = 1 + endDateComponenents.day = 1 + endDateComponenents.timeZone = TimeZone(abbreviation: "EST") // Japan Standard Time + endDateComponenents.hour = 8 + endDateComponenents.minute = 0 + + + let endDate = userCalendar.date(from: endDateComponenents) + + + return Match.query(on: req.db).filter(\.$date > startDate!).filter(\.$date < endDate!).all().map { (matches) -> (Stats) in return self.getStats(matches: matches) } } @@ -563,6 +576,7 @@ struct StatsController: RouteCollection { DashboardItem(title: "Overall", content: overallStats!.record, title2: "Ratio", content2: overallStats!.winLossRatio), DashboardItem(title: "2021 Overall", content: statsFor2021.record, title2: "Ratio", content2: statsFor2021.winLossRatio), DashboardItem(title: "2020 Overall", content: statsFor2020.record, title2: "Ratio", content2: statsFor2020.winLossRatio), + DashboardItem(title: "Win Rate", content: "\(overallStats!.winRate)", title2: "", content2: ""), DashboardItem(title: "Cold War Overall", content: bocwStats!.record, title2: "Ratio", content2: bocwStats!.winLossRatio), DashboardItem(title: "With Hyder", content: hyderStats[0].record, title2: "Ratio", content2: hyderStats[0].winLossRatio), DashboardItem(title: "No Hyder", content: hyderStats[1].record, title2: "Ratio", content2: hyderStats[1].winLossRatio), diff --git a/Sources/App/Models/AllStats.swift b/Sources/App/Models/AllStats.swift index 958d956..1350865 100644 --- a/Sources/App/Models/AllStats.swift +++ b/Sources/App/Models/AllStats.swift @@ -127,6 +127,10 @@ final class StatsWithMostRecentDailyRecord: Content { var totalLosses:Int var mostRecentRecord:String + + var winRate:String { + return "\((Double((Double(totalWins)/Double(totalWins + totalLosses))) * 100.0).truncate(places: 1))%" + } init( winLoss:String, totalWins:Int, totalLosses:Int, mostRecentRecord:String ) { self.winLossRatio = winLoss self.totalWins = totalWins