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> { 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 queue = DispatchQueue(label: "com.sledsoft.cod-tracker.queue", attributes: .concurrent)
let group = DispatchGroup() let group = DispatchGroup()
@@ -591,11 +605,40 @@ struct StatsController: RouteCollection {
group.wait() group.wait()
return OverallStats(overall: overallStats!, mwStats: mwStats!, bocwStats: bocwStats!, mostRecentRecord: "\(mostRecentStats!.totalWins) - \(mostRecentStats!.totalLosses)", statsWithHyder:hyderStats[0], statsWithoutHyder: hyderStats[1])
return OverallStats(overall: overallStats!, mwStats: mwStats!, bocwStats: bocwStats!, mostRecentRecord: "\(mostRecentStats!.totalWins) - \(mostRecentStats!.totalLosses)")
} }
// 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 { private func getRatio( num:Double, den:Double) -> String {

View File

@@ -47,13 +47,19 @@ final class OverallStats: Content {
var bocwStats:StatsWithMostRecentDailyRecord var bocwStats:StatsWithMostRecentDailyRecord
var mostRecentRecord:String var mostRecentRecord:String
init( overall:StatsWithMostRecentDailyRecord, mwStats:StatsWithMostRecentDailyRecord, bocwStats:StatsWithMostRecentDailyRecord, mostRecentRecord:String){ var statsWithHyder:Stats
var statsWithoutHyder:Stats
init( overall:StatsWithMostRecentDailyRecord, mwStats:StatsWithMostRecentDailyRecord, bocwStats:StatsWithMostRecentDailyRecord, mostRecentRecord:String, statsWithHyder:Stats, statsWithoutHyder:Stats){
self.overall = overall self.overall = overall
self.mwStats = mwStats; self.mwStats = mwStats;
self.bocwStats = bocwStats; self.bocwStats = bocwStats;
self.mostRecentRecord = mostRecentRecord self.mostRecentRecord = mostRecentRecord
self.statsWithHyder = statsWithHyder
self.statsWithoutHyder = statsWithHyder
} }
} }