hyder stats

This commit is contained in:
Michael Simard
2021-01-09 12:27:11 -06:00
parent 523b480376
commit 7807b46fcd
2 changed files with 54 additions and 5 deletions

View File

@@ -548,7 +548,21 @@ struct StatsController: RouteCollection {
func overall(req: Request) throws -> EventLoopFuture<OverallStats> {
return Match.query(on: req.db).all().map { (matches) -> OverallStats in
let statsWithHyder = statsWithPlayer(req: req, playerId: 5)
let statsWithoutHyder = statsWithoutPlayer(req: req, playerId: 5)
let hyderFuture = statsWithHyder.and(statsWithoutHyder)
let hyderStats = hyderFuture.map { (withHyder, withoutHyder) -> [Stats] in
return [withHyder, withoutHyder]
}
let matches = Match.query(on: req.db).all()
return matches.and(hyderStats).map { (matches, hyderStats) -> (OverallStats) in
let queue = DispatchQueue(label: "com.sledsoft.cod-tracker.queue", attributes: .concurrent)
let group = DispatchGroup()
@@ -591,11 +605,40 @@ struct StatsController: RouteCollection {
group.wait()
return OverallStats(overall: overallStats!, mwStats: mwStats!, bocwStats: bocwStats!, mostRecentRecord: "\(mostRecentStats!.totalWins) - \(mostRecentStats!.totalLosses)")
return OverallStats(overall: overallStats!, mwStats: mwStats!, bocwStats: bocwStats!, mostRecentRecord: "\(mostRecentStats!.totalWins) - \(mostRecentStats!.totalLosses)", statsWithHyder:hyderStats[0], statsWithoutHyder: hyderStats[1])
}
// return Match.query(on: req.db).all().map { (matches) -> OverallStats in
//
//
// }
}
func statsWithPlayer(req: Request, playerId:Int) -> EventLoopFuture<Stats> {
return Match.query(on: req.db)
.filter(\.$players ~~ "\(playerId)")
.all().map { (matches) -> (Stats) in
return getStats(matches: matches)
}
}
func statsWithoutPlayer (req: Request, playerId:Int) -> EventLoopFuture<Stats> {
return Match.query(on: req.db)
.filter(\.$players !~ "\(playerId)")
.all().map { (matches) -> (Stats) in
return getStats(matches: matches)
}
}
private func getRatio( num:Double, den:Double) -> String {