diff --git a/Sources/App/Controllers/StatsController.swift b/Sources/App/Controllers/StatsController.swift index a33ea7c..5cc0dc0 100644 --- a/Sources/App/Controllers/StatsController.swift +++ b/Sources/App/Controllers/StatsController.swift @@ -548,7 +548,21 @@ struct StatsController: RouteCollection { func overall(req: Request) throws -> EventLoopFuture { - 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 { + 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 { + 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 { diff --git a/Sources/App/Models/AllStats.swift b/Sources/App/Models/AllStats.swift index 12305fa..f266bdd 100644 --- a/Sources/App/Models/AllStats.swift +++ b/Sources/App/Models/AllStats.swift @@ -47,13 +47,19 @@ final class OverallStats: Content { var bocwStats:StatsWithMostRecentDailyRecord 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.mwStats = mwStats; self.bocwStats = bocwStats; self.mostRecentRecord = mostRecentRecord - + + self.statsWithHyder = statsWithHyder + self.statsWithoutHyder = statsWithHyder } }