|
|
|
|
@@ -35,11 +35,18 @@ struct StatsController: RouteCollection {
|
|
|
|
|
func dashboard(db: Database) throws -> EventLoopFuture<DashboardStats> {
|
|
|
|
|
let statistics = WinLossRecords.query(on: db).all()
|
|
|
|
|
let adamAffectedMatches = Match.query(on: db).filter(\.$finalKillRuinedPlayerId == 6).count()
|
|
|
|
|
let totalMWGames = Match.query(on: db).filter(\.$codGame == "mw").count()
|
|
|
|
|
// let totalMWGames = Match.query(on: db).filter(\.$codGame == "mw").count()
|
|
|
|
|
|
|
|
|
|
return (statistics.and(adamAffectedMatches).and(totalMWGames)).map { arg -> (DashboardStats) in
|
|
|
|
|
|
|
|
|
|
let (((statistics, adamAffectedMatches), totalMWGames)) = arg
|
|
|
|
|
let colourSchemeConfigs = ColourScheme.query(on: db).all().map { colourScheme in
|
|
|
|
|
return colourScheme.map { cs in
|
|
|
|
|
return cs.colorSchemeConfig
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (statistics.and(adamAffectedMatches).and(colourSchemeConfigs)).map { arg -> (DashboardStats) in
|
|
|
|
|
|
|
|
|
|
let (((statistics, adamAffectedMatches),colors)) = arg
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// return statistics.map { statistics in
|
|
|
|
|
@@ -51,6 +58,7 @@ struct StatsController: RouteCollection {
|
|
|
|
|
var content1 = ""
|
|
|
|
|
var content2 = ""
|
|
|
|
|
var sortOrder = 0
|
|
|
|
|
var backgroundColor = "484848"
|
|
|
|
|
|
|
|
|
|
if statisticItem.codTrackerId == "no_hyder_overall"{
|
|
|
|
|
title2 = "Ratio"
|
|
|
|
|
@@ -64,14 +72,15 @@ struct StatsController: RouteCollection {
|
|
|
|
|
content1 = "\(statisticItem.wins)-\(statisticItem.losses)"
|
|
|
|
|
content2 = Utils.getRatio(wins: statisticItem.wins, losses: statisticItem.losses)
|
|
|
|
|
sortOrder = 20
|
|
|
|
|
|
|
|
|
|
backgroundColor = colors.first(where: {$0.gameId == "mw"})?.tileColour ?? backgroundColor
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if statisticItem.codTrackerId == "mw_six_players"{
|
|
|
|
|
title2 = "Ratio"
|
|
|
|
|
content1 = "\(statisticItem.wins)-\(statisticItem.losses)"
|
|
|
|
|
content2 = Utils.getRatio(wins: statisticItem.wins, losses: statisticItem.losses)
|
|
|
|
|
sortOrder = 60
|
|
|
|
|
|
|
|
|
|
backgroundColor = colors.first(where: {$0.gameId == "mw"})?.tileColour ?? backgroundColor
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if statisticItem.codTrackerId == "2021_overall"{
|
|
|
|
|
@@ -86,6 +95,7 @@ struct StatsController: RouteCollection {
|
|
|
|
|
content1 = "\(statisticItem.wins)-\(statisticItem.losses)"
|
|
|
|
|
content2 = Utils.getRatio(wins: statisticItem.wins, losses: statisticItem.losses)
|
|
|
|
|
sortOrder = 30
|
|
|
|
|
backgroundColor = colors.first(where: {$0.gameId == "bocw"})?.tileColour ?? backgroundColor
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if statisticItem.codTrackerId == "with_hyder_overall"{
|
|
|
|
|
@@ -99,6 +109,7 @@ struct StatsController: RouteCollection {
|
|
|
|
|
content1 = "\(statisticItem.wins)-\(statisticItem.losses)"
|
|
|
|
|
content2 = Utils.getRatio(wins: statisticItem.wins, losses: statisticItem.losses)
|
|
|
|
|
sortOrder = 70
|
|
|
|
|
backgroundColor = colors.first(where: {$0.gameId == "mw"})?.tileColour ?? backgroundColor
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if statisticItem.codTrackerId == "casual_overall"{
|
|
|
|
|
@@ -134,21 +145,60 @@ struct StatsController: RouteCollection {
|
|
|
|
|
content1 = "\(statisticItem.wins)-\(statisticItem.losses)"
|
|
|
|
|
content2 = Utils.getRatio(wins: statisticItem.wins, losses: statisticItem.losses)
|
|
|
|
|
sortOrder = 41
|
|
|
|
|
backgroundColor = colors.first(where: {$0.gameId == "bocw"})?.tileColour ?? backgroundColor
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if statisticItem.codTrackerId == "vg_casual"{
|
|
|
|
|
title2 = "Ratio"
|
|
|
|
|
content1 = "\(statisticItem.wins)-\(statisticItem.losses)"
|
|
|
|
|
content2 = Utils.getRatio(wins: statisticItem.wins, losses: statisticItem.losses)
|
|
|
|
|
sortOrder = -80
|
|
|
|
|
backgroundColor = colors.first(where: {$0.gameId == "vg"})?.tileColour ?? backgroundColor
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if statisticItem.codTrackerId == "bocw_casual"{
|
|
|
|
|
title2 = "Ratio"
|
|
|
|
|
content1 = "\(statisticItem.wins)-\(statisticItem.losses)"
|
|
|
|
|
content2 = Utils.getRatio(wins: statisticItem.wins, losses: statisticItem.losses)
|
|
|
|
|
sortOrder = -79
|
|
|
|
|
backgroundColor = colors.first(where: {$0.gameId == "bocw"})?.tileColour ?? backgroundColor
|
|
|
|
|
}
|
|
|
|
|
else if statisticItem.codTrackerId == "vg_competitive"{
|
|
|
|
|
title2 = "Ratio"
|
|
|
|
|
content1 = "\(statisticItem.wins)-\(statisticItem.losses)"
|
|
|
|
|
content2 = Utils.getRatio(wins: statisticItem.wins, losses: statisticItem.losses)
|
|
|
|
|
sortOrder = -81
|
|
|
|
|
backgroundColor = colors.first(where: {$0.gameId == "vg"})?.tileColour ?? backgroundColor
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if statisticItem.codTrackerId == "mw2_casual"{
|
|
|
|
|
title2 = "Ratio"
|
|
|
|
|
content1 = "\(statisticItem.wins)-\(statisticItem.losses)"
|
|
|
|
|
content2 = Utils.getRatio(wins: statisticItem.wins, losses: statisticItem.losses)
|
|
|
|
|
sortOrder = -82
|
|
|
|
|
backgroundColor = colors.first(where: {$0.gameId == "mw2"})?.tileColour ?? backgroundColor
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if statisticItem.codTrackerId == "mw2_competitive"{
|
|
|
|
|
title2 = "Ratio"
|
|
|
|
|
content1 = "\(statisticItem.wins)-\(statisticItem.losses)"
|
|
|
|
|
content2 = Utils.getRatio(wins: statisticItem.wins, losses: statisticItem.losses)
|
|
|
|
|
sortOrder = -83
|
|
|
|
|
backgroundColor = colors.first(where: {$0.gameId == "mw2"})?.tileColour ?? backgroundColor
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
DashboardItem(codTrackerId:statisticItem.codTrackerId, title: title, content: content1, title2: title2, content2: content2, sortOrder: sortOrder, backgroundColor: statisticItem.codTrackerId == "bocw_nuketown_halloween" ? "FFA500" : "004999")
|
|
|
|
|
return DashboardItem(codTrackerId:statisticItem.codTrackerId, title: title, content: content1, title2: title2, content2: content2, sortOrder: sortOrder, backgroundColor:backgroundColor)
|
|
|
|
|
} ) +
|
|
|
|
|
[
|
|
|
|
|
DashboardItem(codTrackerId: "adam_ruined_final_kills", title: "Final Kills Ruined by Adam", content: "\(adamAffectedMatches + 7)", title2: "", content2: "",sortOrder: 1000),
|
|
|
|
|
DashboardItem(codTrackerId:"total_mw_games", title: "Total MW Games", content: "\(totalMWGames)", title2: "", content2: "", sortOrder: -10),
|
|
|
|
|
DashboardItem(codTrackerId: "adam_ruined_final_kills", title: "Final Kills Ruined by Adam", content: "\(adamAffectedMatches + 7)", title2: "", content2: "",sortOrder: 1000, backgroundColor: "484848"),
|
|
|
|
|
|
|
|
|
|
]
|
|
|
|
|
).sorted{$0.sortOrder < $1.sortOrder}
|
|
|
|
|
)
|
|
|
|
|
@@ -474,6 +524,11 @@ struct StatsController: RouteCollection {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func getCasualStatsForGame( db: Database, gameId:String, afterDate:Date = Date(timeIntervalSince1970: 0)) -> EventLoopFuture<Stats>{
|
|
|
|
|
return Match.query(on: db).filter(\.$competitive == false).filter(\.$codGame == gameId).filter(\.$date > afterDate ).all().map { matches in
|
|
|
|
|
return Stats(totalWins: matches.filter{$0.win == true}.count, totalLosses: matches.filter{$0.win == false}.count)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -629,12 +684,16 @@ struct StatsController: RouteCollection {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let casualOverall = getCasualStats(db: db)
|
|
|
|
|
let bocwCasual = getCasualStatsForGame(db: db, gameId: "bocw")
|
|
|
|
|
let mw2Casual = getCasualStatsForGame(db: db, gameId: "mw2", afterDate: Date(timeIntervalSince1970: 1635823473))
|
|
|
|
|
let vgCasual = getCasualStatsForGame(db: db, gameId: "vg", afterDate: Date(timeIntervalSince1970: 1635823473)) //nov 21 to exlude beta time in sept
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let matches = Match.query(on: db).sort( \.$date).all()
|
|
|
|
|
|
|
|
|
|
return matches.and(hyderStats).and(statsFor2020).and(statsFor2021).and(casualOverall).map { arg -> ([String:Stats]) in
|
|
|
|
|
return matches.and(hyderStats).and(statsFor2020).and(statsFor2021).and(casualOverall).and(bocwCasual).and(vgCasual).and(mw2Casual).map { arg -> ([String:Stats]) in
|
|
|
|
|
|
|
|
|
|
let ((((matches, hyderStats), statsFor2020), statsFor2021), casualOverall) = arg
|
|
|
|
|
let (((((((matches, hyderStats), statsFor2020), statsFor2021), casualOverall), bocwCasual), vgCasual),mw2Casual) = arg
|
|
|
|
|
|
|
|
|
|
//print ("got matches \(Date().timeIntervalSince(startTime))")
|
|
|
|
|
|
|
|
|
|
@@ -650,11 +709,15 @@ struct StatsController: RouteCollection {
|
|
|
|
|
var mwFivePlayers:Stats?
|
|
|
|
|
var overallFourPlayers:Stats?
|
|
|
|
|
var blackOpsColdWarNuketownHalloween:Stats?
|
|
|
|
|
var vgCompetitive:StatsWithMostRecentDailyRecord?
|
|
|
|
|
var mw2Cometitive:StatsWithMostRecentDailyRecord?
|
|
|
|
|
|
|
|
|
|
// var mapStats:[Int:Stats]?
|
|
|
|
|
// var worstMap:Int?
|
|
|
|
|
// var bestMap:Int?
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// var mapStats:[Int:Stats]?
|
|
|
|
|
// var worstMap:Int?
|
|
|
|
|
// var bestMap:Int?
|
|
|
|
|
//
|
|
|
|
|
group.enter()
|
|
|
|
|
queue.async {
|
|
|
|
|
overallStats = self.getStatsWithMostRecentDailyRecord(sortedMatches: matches)
|
|
|
|
|
@@ -709,6 +772,28 @@ struct StatsController: RouteCollection {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
group.enter()
|
|
|
|
|
queue.async {
|
|
|
|
|
|
|
|
|
|
vgCompetitive = self.getStatsWithMostRecentDailyRecord(sortedMatches: matches.filter({ (match) -> Bool in
|
|
|
|
|
return match.codGame == "vg" && self.shouldCountMatch(match: match )
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
group.leave()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
group.enter()
|
|
|
|
|
queue.async {
|
|
|
|
|
|
|
|
|
|
mw2Cometitive = self.getStatsWithMostRecentDailyRecord(sortedMatches: matches.filter({ (match) -> Bool in
|
|
|
|
|
return match.codGame == "mw2" && self.shouldCountMatch(match: match )
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
group.leave()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
group.wait()
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
@@ -724,8 +809,11 @@ struct StatsController: RouteCollection {
|
|
|
|
|
"mw_five_players":Stats(totalWins: mwFivePlayers!.totalWins, totalLosses: mwFivePlayers!.totalLosses),
|
|
|
|
|
"overall":Stats(totalWins: overallStats!.totalWins, totalLosses: overallStats!.totalLosses),
|
|
|
|
|
"casual_overall":Stats(totalWins: casualOverall.totalWins, totalLosses: casualOverall.totalLosses),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"bocw_casual":Stats(totalWins: bocwCasual.totalWins, totalLosses: bocwCasual.totalLosses),
|
|
|
|
|
"vg_casual":Stats(totalWins: vgCasual.totalWins, totalLosses: vgCasual.totalLosses),
|
|
|
|
|
"vg_competitive":Stats(totalWins: vgCompetitive!.totalWins, totalLosses: vgCompetitive!.totalLosses),
|
|
|
|
|
"mw2_casual":Stats(totalWins: mw2Casual.totalWins, totalLosses: mw2Casual.totalLosses),
|
|
|
|
|
"mw2_competitive":Stats(totalWins: mw2Cometitive!.totalWins, totalLosses: mw2Cometitive!.totalLosses),
|
|
|
|
|
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
@@ -755,7 +843,7 @@ struct StatsController: RouteCollection {
|
|
|
|
|
var worstMap:Int?
|
|
|
|
|
var bestMap:Int?
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
group.enter()
|
|
|
|
|
queue.async {
|
|
|
|
|
mapStats = self.getMapStats(matches: matches,game: "mw", competitive: true)
|
|
|
|
|
@@ -763,7 +851,7 @@ struct StatsController: RouteCollection {
|
|
|
|
|
group.leave()
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
group.enter()
|
|
|
|
|
queue.async {
|
|
|
|
|
let mapStats = self.getMapStats(matches: matches,game: "mw", competitive: true)
|
|
|
|
|
@@ -859,42 +947,42 @@ struct StatsController: RouteCollection {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// return Match.query(on: req.db).all().map { (matches) -> [MapRecord] in
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// let mapStats:[Int:Stats]
|
|
|
|
|
//
|
|
|
|
|
// if let game = req.parameters.get("game", as: String.self),
|
|
|
|
|
// let competitive = req.parameters.get("competitive", as:Bool.self) {
|
|
|
|
|
//
|
|
|
|
|
// let gameMode = req.parameters.get("gamemode", as:Int.self) ?? -2
|
|
|
|
|
// mapStats = self.getMapStats(matches: matches,game: game, competitive: competitive, gameMode: gameMode)
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
// else {
|
|
|
|
|
// mapStats = self.getMapStats(matches: matches,game: "mw", competitive: true)
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// let sortedMaps = self.mapsSortedByBest(records: mapStats)
|
|
|
|
|
//
|
|
|
|
|
// let records = sortedMaps.map { (mapId) -> MapRecord in
|
|
|
|
|
// return MapRecord(map: MapData.allMaps[mapId]!, stats: mapStats[mapId]!, ratio:mapStats[mapId]!.winLossRatio)
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// var wins:Double = 0
|
|
|
|
|
// var loss:Double = 0
|
|
|
|
|
//
|
|
|
|
|
// for record in records {
|
|
|
|
|
// //print("\(record.map.name) \(record.stats.record) \(record.ratio)")
|
|
|
|
|
// wins = wins + Double(record.stats.totalWins)
|
|
|
|
|
// loss = loss + Double(record.stats.totalLosses)
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
// return records
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// return Match.query(on: req.db).all().map { (matches) -> [MapRecord] in
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// let mapStats:[Int:Stats]
|
|
|
|
|
//
|
|
|
|
|
// if let game = req.parameters.get("game", as: String.self),
|
|
|
|
|
// let competitive = req.parameters.get("competitive", as:Bool.self) {
|
|
|
|
|
//
|
|
|
|
|
// let gameMode = req.parameters.get("gamemode", as:Int.self) ?? -2
|
|
|
|
|
// mapStats = self.getMapStats(matches: matches,game: game, competitive: competitive, gameMode: gameMode)
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
// else {
|
|
|
|
|
// mapStats = self.getMapStats(matches: matches,game: "mw", competitive: true)
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// let sortedMaps = self.mapsSortedByBest(records: mapStats)
|
|
|
|
|
//
|
|
|
|
|
// let records = sortedMaps.map { (mapId) -> MapRecord in
|
|
|
|
|
// return MapRecord(map: MapData.allMaps[mapId]!, stats: mapStats[mapId]!, ratio:mapStats[mapId]!.winLossRatio)
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// var wins:Double = 0
|
|
|
|
|
// var loss:Double = 0
|
|
|
|
|
//
|
|
|
|
|
// for record in records {
|
|
|
|
|
// //print("\(record.map.name) \(record.stats.record) \(record.ratio)")
|
|
|
|
|
// wins = wins + Double(record.stats.totalWins)
|
|
|
|
|
// loss = loss + Double(record.stats.totalLosses)
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
// return records
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func mapsSortedByBest (records :[ Int:Stats] ) -> [ Int ] {
|
|
|
|
|
|