diff --git a/Sources/App/Controllers/StatsController.swift b/Sources/App/Controllers/StatsController.swift index 949688e..0ccb99b 100644 --- a/Sources/App/Controllers/StatsController.swift +++ b/Sources/App/Controllers/StatsController.swift @@ -337,7 +337,9 @@ struct StatsController: RouteCollection { var cumulativeWinLossRatios = cumulativeWinLossRatios if !(stats.totalWins == 0 && stats.totalLosses == 0) { - cumulativeWinLossRatios.append(DataPoint(x: "\(Utilities.monthToString(month: first.month)) \(first.day) \(first.year)", y: (totalWins/totalLosses).truncate(places: 2))) + + let date = self.createDate(day: first.day, month: first.month, year: first.year) + cumulativeWinLossRatios.append(DataPoint(x:date.timeIntervalSince1970 , y: (totalWins/totalLosses).truncate(places: 2))) } allDailyStats.append(DailyStats(day: first.day, month: first.month, year: first.year, stats: stats, cumulativeRatio: self.getRatio(num: totalWins, den: totalLosses))) return getRatios(remaining, allDailyStats:&allDailyStats, cumulativeWinLossRatios:&cumulativeWinLossRatios, eventLoop: eventLoop) @@ -371,6 +373,19 @@ struct StatsController: RouteCollection { return calendar.date(from: components)! } + private func createDate(day:Int, month:Int, year:Int) -> Date { + let calendar = Calendar.current + + var components = DateComponents() + components.day = day + components.month = month + components.year = year + components.hour = 0 + components.minute = 0 + + return calendar.date(from: components)! + } + } diff --git a/Sources/App/Models/AllStats.swift b/Sources/App/Models/AllStats.swift index c0d9b46..a9836b0 100644 --- a/Sources/App/Models/AllStats.swift +++ b/Sources/App/Models/AllStats.swift @@ -12,10 +12,10 @@ import Fluent import Vapor struct DataPoint : Content { - var x:String + var x:Double var y:Double - init(x:String, y:Double) { + init(x:Double, y:Double) { self.x = x self.y = y }