changed x to just be incrmeenetal, added a label
This commit is contained in:
@@ -90,8 +90,7 @@ struct StatsController: RouteCollection {
|
|||||||
|
|
||||||
return combined.map { (winCount, lossCount) -> (Stats) in
|
return combined.map { (winCount, lossCount) -> (Stats) in
|
||||||
|
|
||||||
let ratio:Double = (Double(winCount) / Double(lossCount)).truncate(places: 2)
|
return Stats.init(winLoss: self.getRatio(num: Double(winCount), den: Double(lossCount)), totalWins: winCount, totalLosses: lossCount)
|
||||||
return Stats.init(winLoss: String(ratio), totalWins: winCount, totalLosses: lossCount)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,6 +199,12 @@ struct StatsController: RouteCollection {
|
|||||||
return calendar.date(from: components)!
|
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] = []
|
var stats:[MonthStats] = []
|
||||||
let monthstats = getMonthStats(previousMonths[0..<previousMonths.count], allMonthlyStats:&stats, eventLoop: req.eventLoop)
|
let monthstats = getMonthStats(previousMonths[0..<previousMonths.count], allMonthlyStats:&stats, eventLoop: req.eventLoop)
|
||||||
let cumulativeRatios = getCumulativeWinLossRatios(req: req)
|
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
|
let highestWinLossRatio = cumulativeRatios.reduce("0") { (highestRatio, dataPoint) -> String in
|
||||||
if dataPoint.y > Double(highestRatio)!{
|
if dataPoint.y > Double(highestRatio)!{
|
||||||
return String(dataPoint.y)
|
return String(dataPoint.y)
|
||||||
@@ -247,7 +252,7 @@ struct StatsController: RouteCollection {
|
|||||||
return highestRatio
|
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 {
|
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
|
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)")
|
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)))
|
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)
|
return getRatios(remaining, allDailyStats:&allDailyStats, cumulativeWinLossRatios:&cumulativeWinLossRatios, eventLoop: eventLoop)
|
||||||
|
|||||||
@@ -14,10 +14,12 @@ import Vapor
|
|||||||
struct DataPoint : Content {
|
struct DataPoint : Content {
|
||||||
var x:Double
|
var x:Double
|
||||||
var y:Double
|
var y:Double
|
||||||
|
var label:String
|
||||||
|
|
||||||
init(x:Double, y:Double) {
|
init(x:Double, y:Double, label:String) {
|
||||||
self.x = x
|
self.x = x
|
||||||
self.y = y
|
self.y = y
|
||||||
|
self.label = label
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,13 +29,14 @@ final class AllStats: Content {
|
|||||||
var byMonth: [MonthStats]
|
var byMonth: [MonthStats]
|
||||||
var highestWinLossRatio:String
|
var highestWinLossRatio:String
|
||||||
var dataPoints:[DataPoint]
|
var dataPoints:[DataPoint]
|
||||||
|
var mostRecentRecord:String
|
||||||
|
|
||||||
|
init( overall:Stats, byMonth:[MonthStats], highestWinLossRatio:String, dataPoints:[DataPoint], mostRecentRecord:String) {
|
||||||
init( overall:Stats, byMonth:[MonthStats], highestWinLossRatio:String, dataPoints:[DataPoint]) {
|
|
||||||
self.overall = overall
|
self.overall = overall
|
||||||
self.byMonth = byMonth
|
self.byMonth = byMonth
|
||||||
self.highestWinLossRatio = highestWinLossRatio
|
self.highestWinLossRatio = highestWinLossRatio
|
||||||
self.dataPoints = dataPoints
|
self.dataPoints = dataPoints
|
||||||
|
self.mostRecentRecord = mostRecentRecord
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user