changed x of data point to time interval since 1970

This commit is contained in:
Michael Simard
2020-06-16 17:49:58 -05:00
parent 72a04f8823
commit 34e4bc6060
2 changed files with 18 additions and 3 deletions

View File

@@ -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)!
}
}