map, player, game, gamemode data now database driven
This commit is contained in:
@@ -28,7 +28,6 @@ struct StatsController: RouteCollection {
|
||||
statsRoute.get("maps","game",":game","competitive",":competitive", "gamemode", ":gamemode",use: mapRecords)
|
||||
statsRoute.get("dashboard", use: dashboard)
|
||||
statsRoute.get("recalculate", use: recalc)
|
||||
|
||||
statsRoute.get("stats","q",":query", use: history)
|
||||
}
|
||||
|
||||
@@ -236,11 +235,7 @@ struct StatsController: RouteCollection {
|
||||
}
|
||||
|
||||
func getStatsWithMostRecentDailyRecord(sortedMatches:[Match], game:String? = nil) -> StatsWithMostRecentDailyRecord {
|
||||
|
||||
|
||||
let startTime = Date()
|
||||
//print ("MRR START \(Date().timeIntervalSince(startTime))")
|
||||
|
||||
|
||||
let stats = getCountedMatches(matches: sortedMatches)
|
||||
//print ("MRR STATS \(Date().timeIntervalSince(startTime))")
|
||||
|
||||
@@ -256,9 +251,7 @@ struct StatsController: RouteCollection {
|
||||
|
||||
|
||||
func mostRecentDailyStats (matches:[Match], game:String? = nil) -> Stats{
|
||||
|
||||
let startTime = Date()
|
||||
|
||||
|
||||
let daysPlayed = getDaysPlayed(sortedMatches: matches)
|
||||
let lastDayPlayed = daysPlayed.last
|
||||
|
||||
@@ -359,10 +352,7 @@ struct StatsController: RouteCollection {
|
||||
|
||||
private func getDaysPlayed(sortedMatches:[Match]) -> [CODDate] {
|
||||
|
||||
let startTime = Date()
|
||||
|
||||
//print ("MDP Sort \(Date().timeIntervalSince(startTime))")
|
||||
|
||||
|
||||
let dates = sortedMatches.suffix(30).map { (match) -> CODDate in
|
||||
return CODDate(month: match.date.month, year: match.date.year, day: match.date.day, hour: match.date.hour, minute: match.date.minute)
|
||||
}
|
||||
@@ -618,11 +608,7 @@ struct StatsController: RouteCollection {
|
||||
return self.getStatsForDay(year: days.first?.year ?? 0, month: days.first?.month ?? 0, day: days.first?.day ?? 0, req: req)
|
||||
}
|
||||
}
|
||||
|
||||
// func cachedStats(db: Database) -> EventLoopFuture<[String:Stats]> {
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
func recalc(req:Request) -> EventLoopFuture<[String:Stats]> {
|
||||
return forceCalculatedStats(db: req.db)
|
||||
}
|
||||
@@ -754,9 +740,12 @@ struct StatsController: RouteCollection {
|
||||
|
||||
let matches = Match.query(on: db).sort( \.$date).all()
|
||||
|
||||
return matches.and(dashboardStats).map { arg -> (OverallStats) in
|
||||
let mapConfigs = mapConfigs(db: db)
|
||||
|
||||
|
||||
return matches.and(dashboardStats).and(mapConfigs).map { arg -> (OverallStats) in
|
||||
|
||||
let (matches, dashboardStats) = arg
|
||||
let ((matches, dashboardStats),mapConfigs) = arg
|
||||
|
||||
|
||||
let queue = DispatchQueue(label: "com.sledsoft.cod-tracker.queue", attributes: .concurrent)
|
||||
@@ -797,8 +786,8 @@ struct StatsController: RouteCollection {
|
||||
|
||||
(dashboardStats.dashboardItems +
|
||||
[
|
||||
DashboardItem(codTrackerId:"best_map_overall", title: "Best Map", content: MapData.allMaps[bestMap!]?.name ?? "error", title2: "Ratio", content2: "\(mapStats![bestMap!]!.winLossRatio) \(mapStats![bestMap!]!.record)", sortOrder: 12),
|
||||
DashboardItem(codTrackerId:"worst_map_overall", title: "Worst Map", content: MapData.allMaps[worstMap!]?.name ?? "error", title2: "Ratio", content2: "\(mapStats![worstMap!]!.winLossRatio) \(mapStats![worstMap!]!.record)",sortOrder: 13),
|
||||
DashboardItem(codTrackerId:"best_map_overall", title: "Best Map", content: mapConfigs.first{$0.mapId == bestMap}?.name ?? "error", title2: "Ratio", content2: "\(mapStats![bestMap!]!.winLossRatio) \(mapStats![bestMap!]!.record)", sortOrder: 12),
|
||||
DashboardItem(codTrackerId:"worst_map_overall", title: "Worst Map", content: mapConfigs.first{$0.mapId == worstMap}?.name ?? "error", title2: "Ratio", content2: "\(mapStats![worstMap!]!.winLossRatio) \(mapStats![worstMap!]!.record)",sortOrder: 13),
|
||||
|
||||
]).sorted{
|
||||
$0.sortOrder < $1.sortOrder
|
||||
@@ -815,11 +804,25 @@ struct StatsController: RouteCollection {
|
||||
|
||||
}
|
||||
|
||||
func mapConfigs(db: Database) -> EventLoopFuture<[MapConfig]> {
|
||||
|
||||
return Map.query(on: db).all().map { map in
|
||||
return map.map { m in
|
||||
return m.mapConfig
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
func mapRecords(req: Request) throws -> EventLoopFuture<[MapRecord]> {
|
||||
|
||||
return Match.query(on: req.db).all().map { (matches) -> [MapRecord] in
|
||||
|
||||
let matches = Match.query(on: req.db).all()
|
||||
let mapConfigs = mapConfigs(db: req.db)
|
||||
|
||||
return matches.and(mapConfigs).map { matches, mapConfigs in
|
||||
|
||||
let mapStats:[Int:Stats]
|
||||
|
||||
if let game = req.parameters.get("game", as: String.self),
|
||||
@@ -833,10 +836,11 @@ struct StatsController: RouteCollection {
|
||||
mapStats = self.getMapStats(matches: matches,game: "mw", competitive: true)
|
||||
}
|
||||
|
||||
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)
|
||||
return MapRecord(map: mapConfigs.first{$0.mapId == mapId}!, stats: mapStats[mapId]!, ratio:mapStats[mapId]!.winLossRatio)
|
||||
}
|
||||
|
||||
var wins:Double = 0
|
||||
@@ -849,7 +853,48 @@ struct StatsController: RouteCollection {
|
||||
|
||||
}
|
||||
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 ] {
|
||||
|
||||
Reference in New Issue
Block a user