changed x to just be incrmeenetal, added a label

This commit is contained in:
Michael Simard
2020-06-20 13:17:26 -05:00
parent 00ddf6167c
commit 4964b44f1d
2 changed files with 28 additions and 11 deletions

View File

@@ -90,8 +90,7 @@ struct StatsController: RouteCollection {
return combined.map { (winCount, lossCount) -> (Stats) in
let ratio:Double = (Double(winCount) / Double(lossCount)).truncate(places: 2)
return Stats.init(winLoss: String(ratio), totalWins: winCount, totalLosses: lossCount)
return Stats.init(winLoss: self.getRatio(num: Double(winCount), den: Double(lossCount)), totalWins: winCount, totalLosses: lossCount)
}
}
@@ -200,6 +199,12 @@ struct StatsController: RouteCollection {
return calendar.date(from: components)!
}
func mostRecentDailyStats (req:Request) -> EventLoopFuture<Stats>{
let daysPlayed = getDaysPlayed()
return getStatsForDay(year: daysPlayed.last?.year ?? 0, month: daysPlayed.last?.month ?? 0, day: daysPlayed.last?.day ?? 0, req: req)
}
@@ -232,14 +237,14 @@ struct StatsController: RouteCollection {
}
}
var stats:[MonthStats] = []
let monthstats = getMonthStats(previousMonths[0..<previousMonths.count], allMonthlyStats:&stats, eventLoop: req.eventLoop)
let cumulativeRatios = getCumulativeWinLossRatios(req: req)
let mostRecentDayStats = mostRecentDailyStats(req: req)
return try overall(req: req).and(monthstats).and(cumulativeRatios).map { arg -> AllStats in
return try overall(req: req).and(monthstats).and(cumulativeRatios).and(mostRecentDayStats).map { arg -> AllStats in
let ((overall, monthlyStats), cumulativeRatios) = arg
let (((overall, monthlyStats), cumulativeRatios), mostRecentDayStats) = arg
let highestWinLossRatio = cumulativeRatios.reduce("0") { (highestRatio, dataPoint) -> String in
if dataPoint.y > Double(highestRatio)!{
return String(dataPoint.y)
@@ -247,7 +252,7 @@ struct StatsController: RouteCollection {
return highestRatio
}
return AllStats.init(overall: overall, byMonth: monthlyStats, highestWinLossRatio: highestWinLossRatio, dataPoints: cumulativeRatios )
return AllStats.init(overall: overall, byMonth: monthlyStats, highestWinLossRatio: highestWinLossRatio, dataPoints: cumulativeRatios, mostRecentRecord: "\(mostRecentDayStats.totalWins) - \(mostRecentDayStats.totalLosses)")
}
}
@@ -277,7 +282,15 @@ struct StatsController: RouteCollection {
private func getRatio( num:Double, den:Double) -> String {
return String((Double(num) / Double(den)).truncate(places: 2))
var returnString = ""
let deno = (den != 0) ? den : 1
returnString = String((Double(num) / Double(deno)).truncate(places: 2))
if den == 0 {
returnString = returnString + "+"
}
return returnString
}
@@ -363,7 +376,8 @@ struct StatsController: RouteCollection {
let date = self.createDate(day: first.day, month: first.month, year: first.year, hour: first.hour + 6, minute:first.minute) // 6 hours to make sure we pick a time that isnt on borders of us time zones
print ("p \(date.timeIntervalSince1970)")
cumulativeWinLossRatios.append(DataPoint(x:date.timeIntervalSince1970*1000 , y: (totalWins/totalLosses).truncate(places: 2)))
let x = Double(cumulativeWinLossRatios.count)
cumulativeWinLossRatios.append(DataPoint(x:x , y: (totalWins/totalLosses).truncate(places: 2), label:"\(date.timeIntervalSince1970*1000)"))
}
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)