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","page",":page", use: history)
|
||||||
statsRoute.get("history", use: history)
|
statsRoute.get("history", use: history)
|
||||||
statsRoute.get("maps", use: mapRecords)
|
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("dashboard", use: dashboard)
|
||||||
|
|
||||||
|
statsRoute.get("stats","q",":query", use: history)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func dashboard(db: Database) throws -> EventLoopFuture<DashboardStats> {
|
func dashboard(db: Database) throws -> EventLoopFuture<DashboardStats> {
|
||||||
@@ -40,7 +44,7 @@ struct StatsController: RouteCollection {
|
|||||||
|
|
||||||
|
|
||||||
// return statistics.map { statistics in
|
// return statistics.map { statistics in
|
||||||
return DashboardStats(dashboardItems: statistics.map({ statisticItem in
|
return DashboardStats(dashboardItems: (statistics.map({ statisticItem in
|
||||||
|
|
||||||
|
|
||||||
let title = statisticItem.title
|
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: "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()
|
group.enter()
|
||||||
queue.async {
|
queue.async {
|
||||||
mapStats = self.getMapStats(matches: matches)
|
mapStats = self.getMapStats(matches: matches,game: "mw", competitive: true)
|
||||||
//print ("maps done \(Date().timeIntervalSince(startTime))")
|
//print ("maps done \(Date().timeIntervalSince(startTime))")
|
||||||
group.leave()
|
group.leave()
|
||||||
|
|
||||||
@@ -787,7 +792,7 @@ struct StatsController: RouteCollection {
|
|||||||
//
|
//
|
||||||
group.enter()
|
group.enter()
|
||||||
queue.async {
|
queue.async {
|
||||||
let mapStats = self.getMapStats(matches: matches)
|
let mapStats = self.getMapStats(matches: matches,game: "mw", competitive: true)
|
||||||
|
|
||||||
bestMap = self.getBestMap(records: mapStats)
|
bestMap = self.getBestMap(records: mapStats)
|
||||||
group.leave()
|
group.leave()
|
||||||
@@ -795,7 +800,7 @@ struct StatsController: RouteCollection {
|
|||||||
|
|
||||||
group.enter()
|
group.enter()
|
||||||
queue.async {
|
queue.async {
|
||||||
let mapStats = self.getMapStats(matches: matches)
|
let mapStats = self.getMapStats(matches: matches,game: "mw", competitive: true)
|
||||||
|
|
||||||
worstMap = self.getWorstMap(records: mapStats)
|
worstMap = self.getWorstMap(records: mapStats)
|
||||||
group.leave()
|
group.leave()
|
||||||
@@ -830,8 +835,19 @@ struct StatsController: RouteCollection {
|
|||||||
func mapRecords(req: Request) throws -> EventLoopFuture<[MapRecord]> {
|
func mapRecords(req: Request) throws -> EventLoopFuture<[MapRecord]> {
|
||||||
|
|
||||||
return Match.query(on: req.db).all().map { (matches) -> [MapRecord] in
|
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
|
let records = sortedMaps.map { (mapId) -> MapRecord in
|
||||||
@@ -847,7 +863,6 @@ struct StatsController: RouteCollection {
|
|||||||
loss = loss + Double(record.stats.totalLosses)
|
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]()
|
var mapStats:[Int:Stats] = [Int:Stats]()
|
||||||
for match in matches {
|
|
||||||
|
|
||||||
if match.codGame == "mw" {
|
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 let map = match.map, let mapInt = Int(map) {
|
if let map = match.map, let mapInt = Int(map) {
|
||||||
|
|
||||||
if mapStats[mapInt] == nil {
|
if mapStats[mapInt] == nil {
|
||||||
@@ -903,10 +941,9 @@ struct StatsController: RouteCollection {
|
|||||||
mapStats[mapInt]?.totalLosses += 1
|
mapStats[mapInt]?.totalLosses += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return mapStats
|
return mapStats
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func statsWithPlayer(db: Database, playerId:Int) -> EventLoopFuture<Stats> {
|
func statsWithPlayer(db: Database, playerId:Int) -> EventLoopFuture<Stats> {
|
||||||
|
|||||||
Reference in New Issue
Block a user