map records for all game modes added
This commit is contained in:
@@ -24,8 +24,12 @@ struct StatsController: RouteCollection {
|
||||
statsRoute.get("history","page",":page", use: history)
|
||||
statsRoute.get("history", use: history)
|
||||
statsRoute.get("maps", use: mapRecords)
|
||||
statsRoute.get("maps","game",":game","competitive",":competitive",use: mapRecords)
|
||||
statsRoute.get("maps","game",":game","competitive",":competitive", "gamemode", ":gamemode",use: mapRecords)
|
||||
statsRoute.get("dashboard", use: dashboard)
|
||||
|
||||
statsRoute.get("stats","q",":query", use: history)
|
||||
|
||||
}
|
||||
|
||||
func dashboard(db: Database) throws -> EventLoopFuture<DashboardStats> {
|
||||
@@ -40,7 +44,7 @@ struct StatsController: RouteCollection {
|
||||
|
||||
|
||||
// return statistics.map { statistics in
|
||||
return DashboardStats(dashboardItems: statistics.map({ statisticItem in
|
||||
return DashboardStats(dashboardItems: (statistics.map({ statisticItem in
|
||||
|
||||
|
||||
let title = statisticItem.title
|
||||
@@ -148,8 +152,9 @@ struct StatsController: RouteCollection {
|
||||
} ) +
|
||||
[
|
||||
DashboardItem(codTrackerId: "adam_ruined_final_kills", title: "Final Kills Ruined by Adam", content: "\(adamAffectedMatches + 7)", title2: "", content2: "",sortOrder: 100),
|
||||
DashboardItem(codTrackerId:"total_mw_games", title: "Total MW Games", content: "\(totalMWGames)", title2: "", content2: "", sortOrder: 0)
|
||||
DashboardItem(codTrackerId:"total_mw_games", title: "Total MW Games", content: "\(totalMWGames)", title2: "", content2: "", sortOrder: -1)
|
||||
]
|
||||
).sorted{$0.sortOrder < $1.sortOrder}
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -779,7 +784,7 @@ struct StatsController: RouteCollection {
|
||||
//
|
||||
group.enter()
|
||||
queue.async {
|
||||
mapStats = self.getMapStats(matches: matches)
|
||||
mapStats = self.getMapStats(matches: matches,game: "mw", competitive: true)
|
||||
//print ("maps done \(Date().timeIntervalSince(startTime))")
|
||||
group.leave()
|
||||
|
||||
@@ -787,7 +792,7 @@ struct StatsController: RouteCollection {
|
||||
//
|
||||
group.enter()
|
||||
queue.async {
|
||||
let mapStats = self.getMapStats(matches: matches)
|
||||
let mapStats = self.getMapStats(matches: matches,game: "mw", competitive: true)
|
||||
|
||||
bestMap = self.getBestMap(records: mapStats)
|
||||
group.leave()
|
||||
@@ -795,7 +800,7 @@ struct StatsController: RouteCollection {
|
||||
|
||||
group.enter()
|
||||
queue.async {
|
||||
let mapStats = self.getMapStats(matches: matches)
|
||||
let mapStats = self.getMapStats(matches: matches,game: "mw", competitive: true)
|
||||
|
||||
worstMap = self.getWorstMap(records: mapStats)
|
||||
group.leave()
|
||||
@@ -830,9 +835,20 @@ struct StatsController: RouteCollection {
|
||||
func mapRecords(req: Request) throws -> EventLoopFuture<[MapRecord]> {
|
||||
|
||||
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 mapStats = self.getMapStats(matches: matches)
|
||||
let sortedMaps = self.mapsSortedByBest(records: mapStats)
|
||||
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)
|
||||
@@ -847,8 +863,7 @@ struct StatsController: RouteCollection {
|
||||
loss = loss + Double(record.stats.totalLosses)
|
||||
|
||||
}
|
||||
let ratio = wins / loss
|
||||
return records
|
||||
return records
|
||||
}
|
||||
}
|
||||
|
||||
@@ -884,11 +899,34 @@ struct StatsController: RouteCollection {
|
||||
|
||||
|
||||
|
||||
func getMapStats(matches:[Match]) -> [Int:Stats] {
|
||||
func getMapStats(matches:[Match], game:String, competitive:Bool, gameMode:Int = -2) -> [Int:Stats] {
|
||||
var mapStats:[Int:Stats] = [Int:Stats]()
|
||||
for match in matches {
|
||||
|
||||
let filteredMatches = matches
|
||||
.filter{$0.competitive == competitive}
|
||||
.filter{$0.codGame == game}
|
||||
.filter{
|
||||
if gameMode > 0 {
|
||||
return $0.gameMode == gameMode
|
||||
}
|
||||
else if gameMode == -2 { // -2 is all for now
|
||||
return true
|
||||
}
|
||||
else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
for match in filteredMatches {
|
||||
|
||||
if competitive == true {
|
||||
if !shouldCountMatch(match: match){
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if match.codGame == "mw" {
|
||||
if let map = match.map, let mapInt = Int(map) {
|
||||
|
||||
if mapStats[mapInt] == nil {
|
||||
@@ -903,10 +941,9 @@ struct StatsController: RouteCollection {
|
||||
mapStats[mapInt]?.totalLosses += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return mapStats
|
||||
|
||||
}
|
||||
|
||||
func statsWithPlayer(db: Database, playerId:Int) -> EventLoopFuture<Stats> {
|
||||
|
||||
Reference in New Issue
Block a user