hyder stats
This commit is contained in:
@@ -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 {
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user