Compare commits

...

10 Commits

Author SHA1 Message Date
Michael Simard
d4a67dffe6 bug fixes 2022-11-26 16:33:30 -06:00
Michael Simard
98a68d11ab bug fixes 2022-11-26 16:32:10 -06:00
Michael Simard
8c3cd32bcf bug fixes 2022-11-26 16:31:04 -06:00
Michael Simard
be1d430755 bug fixes 2022-11-26 16:27:17 -06:00
Michael Simard
79f029b769 recalc new stats 2022-11-26 16:24:08 -06:00
Michael Simard
4630a20755 mw2 general stats 2022-11-26 15:51:50 -06:00
Michael Simard
14184ac665 update dashboard 2021-12-06 23:55:05 -06:00
Michael Simard
e2f6a1b73a nuketown halloween now cold war colour 2021-11-03 14:19:29 -05:00
Michael Simard
2054181d49 new stats 2021-11-01 22:29:07 -05:00
Michael Simard
2c5ea3a9d5 color updates, tweaks to the new dataabse driven design 2021-11-01 15:07:14 -05:00
7 changed files with 261 additions and 164 deletions

View File

@@ -13,7 +13,7 @@ import Fluent
import Vapor import Vapor
struct ColorSchemeConfig: Content { struct ColorSchemeConfig: Content {
var gameId: Int var gameId: String
var tileColour: String? var tileColour: String?
var winColour: String? var winColour: String?
var lossColour: String? var lossColour: String?

View File

@@ -17,7 +17,7 @@ struct Configuration : Content {
var gameModes:[GameModeConfig] var gameModes:[GameModeConfig]
var gameModeGroups:[GameModeGroupConfig] var gameModeGroups:[GameModeGroupConfig]
var players:[PlayerConfig] var players:[PlayerConfig]
var lossReasons:[LossReasonConfig] var lossReasons:[LossReasonConfig]
init (games:[GameConfig], gameModes:[GameModeConfig], gameModeGroups:[GameModeGroupConfig], players:[PlayerConfig], lossReasons:[LossReasonConfig]){ init (games:[GameConfig], gameModes:[GameModeConfig], gameModeGroups:[GameModeGroupConfig], players:[PlayerConfig], lossReasons:[LossReasonConfig]){

View File

@@ -18,6 +18,8 @@ struct GameConfig: Content {
var maps: [MapConfig] var maps: [MapConfig]
var enabled:Bool var enabled:Bool
var colours:ColorSchemeConfig? var colours:ColorSchemeConfig?
var shortName:String
var imageName:String
} }

View File

@@ -70,7 +70,7 @@ struct AppDataController: RouteCollection {
return GameConfig(gameId: game.gameId, name: game.name, maps: mapConfigs, enabled: game.enabled, colours: colourSchemeConfigs.first{game.gameId == "\($0.gameId)"}) return GameConfig(gameId: game.gameId, name: game.name, maps: mapConfigs, enabled: game.enabled, colours: colourSchemeConfigs.first{game.gameId == "\($0.gameId)"}, shortName: game.shortName, imageName: game.imageName)
}) })
return Configuration(games:gameConfigs, gameModes: gameModeConfigs, gameModeGroups: gameModeGroupConfigs, players: playerConfigs, lossReasons: lossReasonConfigs) return Configuration(games:gameConfigs, gameModes: gameModeConfigs, gameModeGroups: gameModeGroupConfigs, players: playerConfigs, lossReasons: lossReasonConfigs)
} }

View File

@@ -35,14 +35,21 @@ struct StatsController: RouteCollection {
func dashboard(db: Database) throws -> EventLoopFuture<DashboardStats> { func dashboard(db: Database) throws -> EventLoopFuture<DashboardStats> {
let statistics = WinLossRecords.query(on: db).all() let statistics = WinLossRecords.query(on: db).all()
let adamAffectedMatches = Match.query(on: db).filter(\.$finalKillRuinedPlayerId == 6).count() 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 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), totalMWGames)) = arg let (((statistics, adamAffectedMatches),colors)) = arg
// return statistics.map { statistics in // return statistics.map { statistics in
return DashboardStats(dashboardItems: (statistics.map({ statisticItem in return DashboardStats(dashboardItems: (statistics.map({ statisticItem in
@@ -51,6 +58,7 @@ struct StatsController: RouteCollection {
var content1 = "" var content1 = ""
var content2 = "" var content2 = ""
var sortOrder = 0 var sortOrder = 0
var backgroundColor = "484848"
if statisticItem.codTrackerId == "no_hyder_overall"{ if statisticItem.codTrackerId == "no_hyder_overall"{
title2 = "Ratio" title2 = "Ratio"
@@ -64,29 +72,31 @@ struct StatsController: RouteCollection {
content1 = "\(statisticItem.wins)-\(statisticItem.losses)" content1 = "\(statisticItem.wins)-\(statisticItem.losses)"
content2 = Utils.getRatio(wins: statisticItem.wins, losses: statisticItem.losses) content2 = Utils.getRatio(wins: statisticItem.wins, losses: statisticItem.losses)
sortOrder = 20 sortOrder = 20
backgroundColor = colors.first(where: {$0.gameId == "mw"})?.tileColour ?? backgroundColor
} }
else if statisticItem.codTrackerId == "mw_six_players"{ else if statisticItem.codTrackerId == "mw_six_players"{
title2 = "Ratio" title2 = "Ratio"
content1 = "\(statisticItem.wins)-\(statisticItem.losses)" content1 = "\(statisticItem.wins)-\(statisticItem.losses)"
content2 = Utils.getRatio(wins: statisticItem.wins, losses: statisticItem.losses) content2 = Utils.getRatio(wins: statisticItem.wins, losses: statisticItem.losses)
sortOrder = 60 sortOrder = 60
backgroundColor = colors.first(where: {$0.gameId == "mw"})?.tileColour ?? backgroundColor
} }
else if statisticItem.codTrackerId == "2021_overall"{ else if statisticItem.codTrackerId == "2021_overall"{
title2 = "Ratio" title2 = "Ratio"
content1 = "\(statisticItem.wins)-\(statisticItem.losses)" content1 = "\(statisticItem.wins)-\(statisticItem.losses)"
content2 = Utils.getRatio(wins: statisticItem.wins, losses: statisticItem.losses) content2 = Utils.getRatio(wins: statisticItem.wins, losses: statisticItem.losses)
sortOrder = 50 sortOrder = 50
} }
else if statisticItem.codTrackerId == "bocw_overall"{ else if statisticItem.codTrackerId == "bocw_overall"{
title2 = "Ratio" title2 = "Ratio"
content1 = "\(statisticItem.wins)-\(statisticItem.losses)" content1 = "\(statisticItem.wins)-\(statisticItem.losses)"
content2 = Utils.getRatio(wins: statisticItem.wins, losses: statisticItem.losses) content2 = Utils.getRatio(wins: statisticItem.wins, losses: statisticItem.losses)
sortOrder = 30 sortOrder = 30
backgroundColor = colors.first(where: {$0.gameId == "bocw"})?.tileColour ?? backgroundColor
} }
else if statisticItem.codTrackerId == "with_hyder_overall"{ else if statisticItem.codTrackerId == "with_hyder_overall"{
title2 = "Ratio" title2 = "Ratio"
@@ -99,15 +109,16 @@ struct StatsController: RouteCollection {
content1 = "\(statisticItem.wins)-\(statisticItem.losses)" content1 = "\(statisticItem.wins)-\(statisticItem.losses)"
content2 = Utils.getRatio(wins: statisticItem.wins, losses: statisticItem.losses) content2 = Utils.getRatio(wins: statisticItem.wins, losses: statisticItem.losses)
sortOrder = 70 sortOrder = 70
backgroundColor = colors.first(where: {$0.gameId == "mw"})?.tileColour ?? backgroundColor
} }
else if statisticItem.codTrackerId == "casual_overall"{ else if statisticItem.codTrackerId == "casual_overall"{
title2 = "Ratio" title2 = "Ratio"
content1 = "\(statisticItem.wins)-\(statisticItem.losses)" content1 = "\(statisticItem.wins)-\(statisticItem.losses)"
content2 = Utils.getRatio(wins: statisticItem.wins, losses: statisticItem.losses) content2 = Utils.getRatio(wins: statisticItem.wins, losses: statisticItem.losses)
sortOrder = 40 sortOrder = 40
} }
else if statisticItem.codTrackerId == "overall_four_players"{ else if statisticItem.codTrackerId == "overall_four_players"{
title2 = "Ratio" title2 = "Ratio"
@@ -128,35 +139,74 @@ struct StatsController: RouteCollection {
sortOrder = 90 sortOrder = 90
} }
else if statisticItem.codTrackerId == "bocw_nuketown_halloween"{ else if statisticItem.codTrackerId == "bocw_nuketown_halloween"{
title2 = "Ratio" title2 = "Ratio"
content1 = "\(statisticItem.wins)-\(statisticItem.losses)" content1 = "\(statisticItem.wins)-\(statisticItem.losses)"
content2 = Utils.getRatio(wins: statisticItem.wins, losses: statisticItem.losses) content2 = Utils.getRatio(wins: statisticItem.wins, losses: statisticItem.losses)
sortOrder = 41 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 { else {
} }
return return DashboardItem(codTrackerId:statisticItem.codTrackerId, title: title, content: content1, title2: title2, content2: content2, sortOrder: sortOrder, backgroundColor:backgroundColor)
DashboardItem(codTrackerId:statisticItem.codTrackerId, title: title, content: content1, title2: title2, content2: content2, sortOrder: sortOrder, backgroundColor: statisticItem.codTrackerId == "bocw_nuketown_halloween" ? "FFA500" : "004999")
} ) + } ) +
[ [
DashboardItem(codTrackerId: "adam_ruined_final_kills", title: "Final Kills Ruined by Adam", content: "\(adamAffectedMatches + 7)", title2: "", content2: "",sortOrder: 1000), DashboardItem(codTrackerId: "adam_ruined_final_kills", title: "Final Kills Ruined by Adam", content: "\(adamAffectedMatches + 7)", title2: "", content2: "",sortOrder: 1000, backgroundColor: "484848"),
DashboardItem(codTrackerId:"total_mw_games", title: "Total MW Games", content: "\(totalMWGames)", title2: "", content2: "", sortOrder: -10),
] ]
).sorted{$0.sortOrder < $1.sortOrder} ).sorted{$0.sortOrder < $1.sortOrder}
) )
} }
} }
func dashboard(req: Request) throws -> EventLoopFuture<DashboardStats> { func dashboard(req: Request) throws -> EventLoopFuture<DashboardStats> {
return try dashboard(db: req.db) return try dashboard(db: req.db)
} }
@@ -217,7 +267,7 @@ struct StatsController: RouteCollection {
} }
func getAllMatches(matches:[Match]) -> Stats{ func getAllMatches(matches:[Match]) -> Stats{
let totals = matches.reduce([0,0]) { (totals, match) -> [Int] in let totals = matches.reduce([0,0]) { (totals, match) -> [Int] in
if match.win == true { if match.win == true {
return [totals[0] + 1, totals[1]] return [totals[0] + 1, totals[1]]
@@ -235,35 +285,35 @@ struct StatsController: RouteCollection {
} }
func getStatsWithMostRecentDailyRecord(sortedMatches:[Match], game:String? = nil) -> StatsWithMostRecentDailyRecord { func getStatsWithMostRecentDailyRecord(sortedMatches:[Match], game:String? = nil) -> StatsWithMostRecentDailyRecord {
let stats = getCountedMatches(matches: sortedMatches) let stats = getCountedMatches(matches: sortedMatches)
//print ("MRR STATS \(Date().timeIntervalSince(startTime))") //print ("MRR STATS \(Date().timeIntervalSince(startTime))")
let mostRecentDailyStats = self.mostRecentDailyStats(matches: sortedMatches, game: game) let mostRecentDailyStats = self.mostRecentDailyStats(matches: sortedMatches, game: game)
//print ("MRR DAILY \(Date().timeIntervalSince(startTime))") //print ("MRR DAILY \(Date().timeIntervalSince(startTime))")
let ret = StatsWithMostRecentDailyRecord(winLoss: stats.winLossRatio, totalWins: stats.totalWins, totalLosses: stats.totalLosses, mostRecentRecord:"\(mostRecentDailyStats.totalWins)-\(mostRecentDailyStats.totalLosses)") let ret = StatsWithMostRecentDailyRecord(winLoss: stats.winLossRatio, totalWins: stats.totalWins, totalLosses: stats.totalLosses, mostRecentRecord:"\(mostRecentDailyStats.totalWins)-\(mostRecentDailyStats.totalLosses)")
return ret return ret
} }
func mostRecentDailyStats (matches:[Match], game:String? = nil) -> Stats{ func mostRecentDailyStats (matches:[Match], game:String? = nil) -> Stats{
let daysPlayed = getDaysPlayed(sortedMatches: matches) let daysPlayed = getDaysPlayed(sortedMatches: matches)
let lastDayPlayed = daysPlayed.last let lastDayPlayed = daysPlayed.last
//print ("MDD days played \(Date().timeIntervalSince(startTime))") //print ("MDD days played \(Date().timeIntervalSince(startTime))")
return getCountedMatches(matches: matches.filter({ (match) -> Bool in return getCountedMatches(matches: matches.filter({ (match) -> Bool in
var shouldInclude = var shouldInclude =
match.date.day == lastDayPlayed?.day && match.date.day == lastDayPlayed?.day &&
match.date.month == lastDayPlayed?.month && match.date.month == lastDayPlayed?.month &&
match.date.year == lastDayPlayed?.year && match.date.year == lastDayPlayed?.year &&
self.shouldCountMatch(match: match) self.shouldCountMatch(match: match)
if let game = game { if let game = game {
shouldInclude = shouldInclude && match.codGame == game shouldInclude = shouldInclude && match.codGame == game
@@ -278,7 +328,7 @@ struct StatsController: RouteCollection {
let isColdWar = match.codGame == "bocw" let isColdWar = match.codGame == "bocw"
let numberOfPlayers = self.numberOfPlayers(match: match) let numberOfPlayers = self.numberOfPlayers(match: match)
if match.competitive == false { if match.competitive == false {
return false return false
} }
@@ -295,7 +345,7 @@ struct StatsController: RouteCollection {
} }
} }
else { else {
if numberOfPlayers > 4 || numberOfPlayers == 0 { if numberOfPlayers > 4 || numberOfPlayers == 0 {
return true return true
} }
@@ -308,7 +358,7 @@ struct StatsController: RouteCollection {
} }
} }
} }
func getStatsForYear(year:Int, db: Database) -> EventLoopFuture<Stats>{ func getStatsForYear(year:Int, db: Database) -> EventLoopFuture<Stats>{
@@ -321,7 +371,7 @@ struct StatsController: RouteCollection {
dateComponents.timeZone = TimeZone(abbreviation: "EST") // Japan Standard Time dateComponents.timeZone = TimeZone(abbreviation: "EST") // Japan Standard Time
dateComponents.hour = 8 dateComponents.hour = 8
dateComponents.minute = 0 dateComponents.minute = 0
// Create date from components // Create date from components
let userCalendar = Calendar(identifier: .gregorian) // since the components above (like year 1980) are for Gregorian let userCalendar = Calendar(identifier: .gregorian) // since the components above (like year 1980) are for Gregorian
let startDate = userCalendar.date(from: dateComponents) let startDate = userCalendar.date(from: dateComponents)
@@ -335,10 +385,10 @@ struct StatsController: RouteCollection {
endDateComponenents.timeZone = TimeZone(abbreviation: "EST") // Japan Standard Time endDateComponenents.timeZone = TimeZone(abbreviation: "EST") // Japan Standard Time
endDateComponenents.hour = 8 endDateComponenents.hour = 8
endDateComponenents.minute = 0 endDateComponenents.minute = 0
let endDate = userCalendar.date(from: endDateComponenents) let endDate = userCalendar.date(from: endDateComponenents)
return Match.query(on: db).filter(\.$date > startDate!).filter(\.$date < endDate!).all().map { (matches) -> (Stats) in return Match.query(on: db).filter(\.$date > startDate!).filter(\.$date < endDate!).all().map { (matches) -> (Stats) in
return self.getCountedMatches(matches: matches) return self.getCountedMatches(matches: matches)
@@ -352,7 +402,7 @@ struct StatsController: RouteCollection {
private func getDaysPlayed(sortedMatches:[Match]) -> [CODDate] { private func getDaysPlayed(sortedMatches:[Match]) -> [CODDate] {
let dates = sortedMatches.suffix(30).map { (match) -> CODDate in 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) return CODDate(month: match.date.month, year: match.date.year, day: match.date.day, hour: match.date.hour, minute: match.date.minute)
} }
@@ -441,7 +491,7 @@ struct StatsController: RouteCollection {
return getstatsForMonth(year: 2020, month: 03, req: req) return getstatsForMonth(year: 2020, month: 03, req: req)
} }
func getstatsForMonth(year:Int, month:Int, req: Request) -> EventLoopFuture<Stats>{ func getstatsForMonth(year:Int, month:Int, req: Request) -> EventLoopFuture<Stats>{
@@ -467,14 +517,19 @@ struct StatsController: RouteCollection {
func getCasualStats( db: Database) -> EventLoopFuture<Stats>{ func getCasualStats( db: Database) -> EventLoopFuture<Stats>{
return Match.query(on: db).filter(\.$competitive == false).all().map { matches in return Match.query(on: db).filter(\.$competitive == false).all().map { matches in
return Stats(totalWins: matches.filter{$0.win == true}.count, totalLosses: matches.filter{$0.win == false}.count) return Stats(totalWins: matches.filter{$0.win == true}.count, totalLosses: matches.filter{$0.win == false}.count)
} }
} }
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)
}
}
@@ -608,18 +663,18 @@ struct StatsController: RouteCollection {
return self.getStatsForDay(year: days.first?.year ?? 0, month: days.first?.month ?? 0, day: days.first?.day ?? 0, req: req) return self.getStatsForDay(year: days.first?.year ?? 0, month: days.first?.month ?? 0, day: days.first?.day ?? 0, req: req)
} }
} }
func recalc(req:Request) -> EventLoopFuture<[String:Stats]> { func recalc(req:Request) -> EventLoopFuture<[String:Stats]> {
return forceCalculatedStats(db: req.db) return forceCalculatedStats(db: req.db)
} }
func forceCalculatedStats(db: Database) -> EventLoopFuture<[String:Stats]> { func forceCalculatedStats(db: Database) -> EventLoopFuture<[String:Stats]> {
let statsWithHyder = statsWithPlayer(db: db, playerId: 5) let statsWithHyder = statsWithPlayer(db: db, playerId: 5)
let statsWithoutHyder = statsWithoutPlayer(db: db, playerId: 5) let statsWithoutHyder = statsWithoutPlayer(db: db, playerId: 5)
let statsFor2020 = getStatsForYear(year: 2020, db: db) let statsFor2020 = getStatsForYear(year: 2020, db: db)
let statsFor2021 = getStatsForYear(year: 2021, db: db) let statsFor2021 = getStatsForYear(year: 2021, db: db)
let hyderFuture = statsWithHyder.and(statsWithoutHyder) let hyderFuture = statsWithHyder.and(statsWithoutHyder)
@@ -629,32 +684,40 @@ struct StatsController: RouteCollection {
let casualOverall = getCasualStats(db: db) 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() 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))") //print ("got matches \(Date().timeIntervalSince(startTime))")
let queue = DispatchQueue(label: "com.sledsoft.cod-tracker.queue", attributes: .concurrent) let queue = DispatchQueue(label: "com.sledsoft.cod-tracker.queue", attributes: .concurrent)
let group = DispatchGroup() let group = DispatchGroup()
var overallStats:StatsWithMostRecentDailyRecord? var overallStats:StatsWithMostRecentDailyRecord?
var mwStats:StatsWithMostRecentDailyRecord? var mwStats:StatsWithMostRecentDailyRecord?
var bocwStats:StatsWithMostRecentDailyRecord? var bocwStats:StatsWithMostRecentDailyRecord?
var mostRecentStats:Stats? var mostRecentStats:Stats?
var mwSixPlayers:Stats? var mwSixPlayers:Stats?
var mwFivePlayers:Stats? var mwFivePlayers:Stats?
var overallFourPlayers:Stats? var overallFourPlayers:Stats?
var blackOpsColdWarNuketownHalloween: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() group.enter()
queue.async { queue.async {
overallStats = self.getStatsWithMostRecentDailyRecord(sortedMatches: matches) overallStats = self.getStatsWithMostRecentDailyRecord(sortedMatches: matches)
@@ -678,7 +741,7 @@ struct StatsController: RouteCollection {
return match.codGame == "bocw" && self.shouldCountMatch(match: match ) return match.codGame == "bocw" && self.shouldCountMatch(match: match )
})) }))
group.leave() group.leave()
} }
@@ -694,7 +757,7 @@ struct StatsController: RouteCollection {
mwFivePlayers = self.getCountedMatchesByPlayerCount(matches: matches.filter{$0.codGame == "mw"}, playerCount: 5) mwFivePlayers = self.getCountedMatchesByPlayerCount(matches: matches.filter{$0.codGame == "mw"}, playerCount: 5)
group.leave() group.leave()
} }
group.enter() group.enter()
queue.async { queue.async {
@@ -707,10 +770,32 @@ struct StatsController: RouteCollection {
blackOpsColdWarNuketownHalloween = self.getRecordForMapId(matches: matches.filter{$0.codGame == "bocw"}, mapId: "69") blackOpsColdWarNuketownHalloween = self.getRecordForMapId(matches: matches.filter{$0.codGame == "bocw"}, mapId: "69")
group.leave() group.leave()
} }
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() group.wait()
return [ return [
"bocw_nuketown_halloween":Stats(totalWins: blackOpsColdWarNuketownHalloween!.totalWins, totalLosses: blackOpsColdWarNuketownHalloween!.totalLosses), "bocw_nuketown_halloween":Stats(totalWins: blackOpsColdWarNuketownHalloween!.totalWins, totalLosses: blackOpsColdWarNuketownHalloween!.totalLosses),
"mw_overall":Stats(totalWins: mwStats!.totalWins, totalLosses: mwStats!.totalLosses), "mw_overall":Stats(totalWins: mwStats!.totalWins, totalLosses: mwStats!.totalLosses),
@@ -724,30 +809,33 @@ struct StatsController: RouteCollection {
"mw_five_players":Stats(totalWins: mwFivePlayers!.totalWins, totalLosses: mwFivePlayers!.totalLosses), "mw_five_players":Stats(totalWins: mwFivePlayers!.totalWins, totalLosses: mwFivePlayers!.totalLosses),
"overall":Stats(totalWins: overallStats!.totalWins, totalLosses: overallStats!.totalLosses), "overall":Stats(totalWins: overallStats!.totalWins, totalLosses: overallStats!.totalLosses),
"casual_overall":Stats(totalWins: casualOverall.totalWins, totalLosses: casualOverall.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),
] ]
} }
} }
func overall(db: Database) throws -> EventLoopFuture<OverallStats> { func overall(db: Database) throws -> EventLoopFuture<OverallStats> {
let dashboardStats = try dashboard(db:db) let dashboardStats = try dashboard(db:db)
let matches = Match.query(on: db).sort( \.$date).all() let matches = Match.query(on: db).sort( \.$date).all()
let mapConfigs = getMapConfigs(db: db) let mapConfigs = getMapConfigs(db: db)
return matches.and(dashboardStats).and(mapConfigs).map { arg -> (OverallStats) in return matches.and(dashboardStats).and(mapConfigs).map { arg -> (OverallStats) in
let ((matches, dashboardStats),mapConfigs) = arg let ((matches, dashboardStats),mapConfigs) = arg
let queue = DispatchQueue(label: "com.sledsoft.cod-tracker.queue", attributes: .concurrent) let queue = DispatchQueue(label: "com.sledsoft.cod-tracker.queue", attributes: .concurrent)
let group = DispatchGroup() let group = DispatchGroup()
@@ -755,43 +843,43 @@ struct StatsController: RouteCollection {
var worstMap:Int? var worstMap:Int?
var bestMap:Int? var bestMap:Int?
// //
group.enter() group.enter()
queue.async { queue.async {
mapStats = self.getMapStats(matches: matches,game: "mw", competitive: true) 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()
}
//
group.enter()
queue.async {
let mapStats = self.getMapStats(matches: matches,game: "mw", competitive: true)
bestMap = self.getBestMap(records: mapStats)
group.leave()
}
group.enter()
queue.async {
let mapStats = self.getMapStats(matches: matches,game: "mw", competitive: true)
worstMap = self.getWorstMap(records: mapStats)
group.leave()
}
group.wait()
let dashboardItems:[DashboardItem] =
(dashboardStats.dashboardItems + }
[ //
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), group.enter()
queue.async {
let mapStats = self.getMapStats(matches: matches,game: "mw", competitive: true)
bestMap = self.getBestMap(records: mapStats)
group.leave()
}
group.enter()
queue.async {
let mapStats = self.getMapStats(matches: matches,game: "mw", competitive: true)
worstMap = self.getWorstMap(records: mapStats)
group.leave()
}
group.wait()
let dashboardItems:[DashboardItem] =
(dashboardStats.dashboardItems +
[
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), 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{ ]).sorted{
$0.sortOrder < $1.sortOrder $0.sortOrder < $1.sortOrder
} }
return OverallStats(dashboardItems: dashboardItems) return OverallStats(dashboardItems: dashboardItems)
} }
} }
@@ -801,7 +889,7 @@ struct StatsController: RouteCollection {
return try overall(db: req.db) return try overall(db: req.db)
} }
func getMapConfigs(db: Database) -> EventLoopFuture<[MapConfig]> { func getMapConfigs(db: Database) -> EventLoopFuture<[MapConfig]> {
@@ -817,26 +905,26 @@ struct StatsController: RouteCollection {
func mapRecords(req: Request) throws -> EventLoopFuture<[MapRecord]> { func mapRecords(req: Request) throws -> EventLoopFuture<[MapRecord]> {
let matches = Match.query(on: req.db).all() let matches = Match.query(on: req.db).all()
let mapConfigs = getMapConfigs(db: req.db) let mapConfigs = getMapConfigs(db: req.db)
return matches.and(mapConfigs).map { matches, mapConfigs in return matches.and(mapConfigs).map { matches, mapConfigs in
let mapStats:[Int:Stats] let mapStats:[Int:Stats]
if let game = req.parameters.get("game", as: String.self), if let game = req.parameters.get("game", as: String.self),
let competitive = req.parameters.get("competitive", as:Bool.self) { let competitive = req.parameters.get("competitive", as:Bool.self) {
let gameMode = req.parameters.get("gamemode", as:Int.self) ?? -2 let gameMode = req.parameters.get("gamemode", as:Int.self) ?? -2
mapStats = self.getMapStats(matches: matches,game: game, competitive: competitive, gameMode: gameMode) mapStats = self.getMapStats(matches: matches,game: game, competitive: competitive, gameMode: gameMode)
} }
else { else {
mapStats = self.getMapStats(matches: matches,game: "mw", competitive: true) 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 let records = sortedMaps.map { (mapId) -> MapRecord in
@@ -850,51 +938,51 @@ struct StatsController: RouteCollection {
//print("\(record.map.name) \(record.stats.record) \(record.ratio)") //print("\(record.map.name) \(record.stats.record) \(record.ratio)")
wins = wins + Double(record.stats.totalWins) wins = wins + Double(record.stats.totalWins)
loss = loss + Double(record.stats.totalLosses) loss = loss + Double(record.stats.totalLosses)
} }
return records return records
} }
// //
// 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] // let mapStats:[Int:Stats]
// //
// if let game = req.parameters.get("game", as: String.self), // if let game = req.parameters.get("game", as: String.self),
// let competitive = req.parameters.get("competitive", as:Bool.self) { // let competitive = req.parameters.get("competitive", as:Bool.self) {
// //
// let gameMode = req.parameters.get("gamemode", as:Int.self) ?? -2 // let gameMode = req.parameters.get("gamemode", as:Int.self) ?? -2
// mapStats = self.getMapStats(matches: matches,game: game, competitive: competitive, gameMode: gameMode) // mapStats = self.getMapStats(matches: matches,game: game, competitive: competitive, gameMode: gameMode)
// //
// } // }
// else { // else {
// mapStats = self.getMapStats(matches: matches,game: "mw", competitive: true) // 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 // let records = sortedMaps.map { (mapId) -> MapRecord in
// return MapRecord(map: MapData.allMaps[mapId]!, stats: mapStats[mapId]!, ratio:mapStats[mapId]!.winLossRatio) // return MapRecord(map: MapData.allMaps[mapId]!, stats: mapStats[mapId]!, ratio:mapStats[mapId]!.winLossRatio)
// } // }
// //
// var wins:Double = 0 // var wins:Double = 0
// var loss:Double = 0 // var loss:Double = 0
// //
// for record in records { // for record in records {
// //print("\(record.map.name) \(record.stats.record) \(record.ratio)") // //print("\(record.map.name) \(record.stats.record) \(record.ratio)")
// wins = wins + Double(record.stats.totalWins) // wins = wins + Double(record.stats.totalWins)
// loss = loss + Double(record.stats.totalLosses) // loss = loss + Double(record.stats.totalLosses)
// //
// } // }
// return records // return records
// } // }
} }
func mapsSortedByBest (records :[ Int:Stats] ) -> [ Int ] { func mapsSortedByBest (records :[ Int:Stats] ) -> [ Int ] {
@@ -904,16 +992,16 @@ struct StatsController: RouteCollection {
} }
func getCountedMatchesByPlayerCount(matches:[Match], playerCount:Int) -> Stats { func getCountedMatchesByPlayerCount(matches:[Match], playerCount:Int) -> Stats {
return getCountedMatches(matches: matches.filter{$0.playerList.count == playerCount}) return getCountedMatches(matches: matches.filter{$0.playerList.count == playerCount})
} }
func getRecordForMapId(matches:[Match], mapId:String) -> Stats { func getRecordForMapId(matches:[Match], mapId:String) -> Stats {
return getAllMatches(matches: matches.filter{$0.map == mapId}) return getAllMatches(matches: matches.filter{$0.map == mapId})
} }
func getAllMatchesByPlayerCount(matches:[Match], playerCount:Int) -> Stats { func getAllMatchesByPlayerCount(matches:[Match], playerCount:Int) -> Stats {
return getAllMatches(matches: matches.filter{$0.playerList.count == playerCount}) return getAllMatches(matches: matches.filter{$0.playerList.count == playerCount})
} }
func getBestMap (records :[ Int:Stats] ) -> Int { func getBestMap (records :[ Int:Stats] ) -> Int {
@@ -952,7 +1040,7 @@ struct StatsController: RouteCollection {
return true return true
} }
} }
for match in filteredMatches { for match in filteredMatches {
@@ -966,18 +1054,18 @@ struct StatsController: RouteCollection {
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 {
mapStats[mapInt] = Stats(totalWins: 0, totalLosses: 0) mapStats[mapInt] = Stats(totalWins: 0, totalLosses: 0)
} }
if match.win { if match.win {
mapStats[mapInt]?.totalWins += 1 mapStats[mapInt]?.totalWins += 1
} }
else{ else{
mapStats[mapInt]?.totalLosses += 1 mapStats[mapInt]?.totalLosses += 1
} }
} }
} }
return mapStats return mapStats
} }
@@ -1064,7 +1152,7 @@ struct StatsController: RouteCollection {
} }
return true return true
}).reversed() }).reversed()
) )
} }
} }
@@ -1086,9 +1174,9 @@ struct StatsController: RouteCollection {
func getCumulativeWinLossRatios(req:Request) -> EventLoopFuture<[DataPoint]> { func getCumulativeWinLossRatios(req:Request) -> EventLoopFuture<[DataPoint]> {
return getDaysPlayed(req: req).flatMap { (previousDays) -> (EventLoopFuture<[DataPoint]>) in
return getDaysPlayed(req: req).flatMap { (previousDays) -> (EventLoopFuture<[DataPoint]>) in
func getRatios (_ remaining: ArraySlice<CODDate>, allDailyStats: inout [DailyStats], cumulativeWinLossRatios: inout [DataPoint], eventLoop: EventLoop) -> EventLoopFuture<[DataPoint]> { func getRatios (_ remaining: ArraySlice<CODDate>, allDailyStats: inout [DailyStats], cumulativeWinLossRatios: inout [DataPoint], eventLoop: EventLoop) -> EventLoopFuture<[DataPoint]> {
var remaining = remaining var remaining = remaining
if let first = remaining.popLast() { if let first = remaining.popLast() {

View File

@@ -19,7 +19,7 @@ final class ColourScheme: Model, Content {
var id: UUID? var id: UUID?
@Field(key: "game_id") @Field(key: "game_id")
var gameId: Int var gameId: String
@Field(key: "tile_colour") @Field(key: "tile_colour")
var tileColour: String? var tileColour: String?
@@ -35,7 +35,7 @@ final class ColourScheme: Model, Content {
init() { } init() { }
// Creates a new with all properties set. // Creates a new with all properties set.
init(id: UUID? = nil, gameId: Int, tileColour: String?,winColour: String?,lossColour: String? ) { init(id: UUID? = nil, gameId: String, tileColour: String?,winColour: String?,lossColour: String? ) {
self.id = id self.id = id
self.gameId = gameId self.gameId = gameId
self.tileColour = tileColour self.tileColour = tileColour

View File

@@ -31,19 +31,26 @@ final class Game: Model, Content {
@Field(key: "enabled") @Field(key: "enabled")
var enabled: Bool var enabled: Bool
@Field(key: "short_name")
var shortName: String
@Field(key: "image_name")
var imageName: String
// Creates a new, empty . // Creates a new, empty .
init() { } init() { }
// Creates a new with all properties set. // Creates a new with all properties set.
init(id: UUID? = nil, gameId: String, name: String, maps:String, enabled:Bool) { init(id: UUID? = nil, gameId: String, name: String, maps:String, enabled:Bool, shortName:String, imageName:String) {
self.id = id self.id = id
self.gameId = gameId self.gameId = gameId
self.name = name self.name = name
self.maps = maps self.maps = maps
self.enabled = enabled self.enabled = enabled
self.shortName = shortName
self.imageName = imageName
} }