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
struct ColorSchemeConfig: Content {
var gameId: Int
var gameId: String
var tileColour: String?
var winColour: String?
var lossColour: String?

View File

@@ -17,7 +17,7 @@ struct Configuration : Content {
var gameModes:[GameModeConfig]
var gameModeGroups:[GameModeGroupConfig]
var players:[PlayerConfig]
var lossReasons:[LossReasonConfig]
var 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 enabled:Bool
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)
}

View File

@@ -35,14 +35,21 @@ 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 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
@@ -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,29 +72,31 @@ 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"{
title2 = "Ratio"
content1 = "\(statisticItem.wins)-\(statisticItem.losses)"
content2 = Utils.getRatio(wins: statisticItem.wins, losses: statisticItem.losses)
sortOrder = 50
}
else if statisticItem.codTrackerId == "bocw_overall"{
title2 = "Ratio"
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"{
title2 = "Ratio"
@@ -99,15 +109,16 @@ 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"{
title2 = "Ratio"
content1 = "\(statisticItem.wins)-\(statisticItem.losses)"
content2 = Utils.getRatio(wins: statisticItem.wins, losses: statisticItem.losses)
sortOrder = 40
}
else if statisticItem.codTrackerId == "overall_four_players"{
title2 = "Ratio"
@@ -128,35 +139,74 @@ struct StatsController: RouteCollection {
sortOrder = 90
}
else if statisticItem.codTrackerId == "bocw_nuketown_halloween"{
title2 = "Ratio"
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),
]
).sorted{$0.sortOrder < $1.sortOrder}
[
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}
)
}
}
func dashboard(req: Request) throws -> EventLoopFuture<DashboardStats> {
return try dashboard(db: req.db)
}
@@ -217,7 +267,7 @@ struct StatsController: RouteCollection {
}
func getAllMatches(matches:[Match]) -> Stats{
let totals = matches.reduce([0,0]) { (totals, match) -> [Int] in
if match.win == true {
return [totals[0] + 1, totals[1]]
@@ -235,35 +285,35 @@ struct StatsController: RouteCollection {
}
func getStatsWithMostRecentDailyRecord(sortedMatches:[Match], game:String? = nil) -> StatsWithMostRecentDailyRecord {
let stats = getCountedMatches(matches: sortedMatches)
//print ("MRR STATS \(Date().timeIntervalSince(startTime))")
let mostRecentDailyStats = self.mostRecentDailyStats(matches: sortedMatches, game: game)
//print ("MRR DAILY \(Date().timeIntervalSince(startTime))")
let ret = StatsWithMostRecentDailyRecord(winLoss: stats.winLossRatio, totalWins: stats.totalWins, totalLosses: stats.totalLosses, mostRecentRecord:"\(mostRecentDailyStats.totalWins)-\(mostRecentDailyStats.totalLosses)")
return ret
}
func mostRecentDailyStats (matches:[Match], game:String? = nil) -> Stats{
let daysPlayed = getDaysPlayed(sortedMatches: matches)
let lastDayPlayed = daysPlayed.last
//print ("MDD days played \(Date().timeIntervalSince(startTime))")
return getCountedMatches(matches: matches.filter({ (match) -> Bool in
var shouldInclude =
match.date.day == lastDayPlayed?.day &&
match.date.month == lastDayPlayed?.month &&
match.date.year == lastDayPlayed?.year &&
self.shouldCountMatch(match: match)
match.date.day == lastDayPlayed?.day &&
match.date.month == lastDayPlayed?.month &&
match.date.year == lastDayPlayed?.year &&
self.shouldCountMatch(match: match)
if let game = game {
shouldInclude = shouldInclude && match.codGame == game
@@ -278,7 +328,7 @@ struct StatsController: RouteCollection {
let isColdWar = match.codGame == "bocw"
let numberOfPlayers = self.numberOfPlayers(match: match)
if match.competitive == false {
return false
}
@@ -295,7 +345,7 @@ struct StatsController: RouteCollection {
}
}
else {
if numberOfPlayers > 4 || numberOfPlayers == 0 {
return true
}
@@ -308,7 +358,7 @@ struct StatsController: RouteCollection {
}
}
}
}
func getStatsForYear(year:Int, db: Database) -> EventLoopFuture<Stats>{
@@ -321,7 +371,7 @@ struct StatsController: RouteCollection {
dateComponents.timeZone = TimeZone(abbreviation: "EST") // Japan Standard Time
dateComponents.hour = 8
dateComponents.minute = 0
// Create date from components
let userCalendar = Calendar(identifier: .gregorian) // since the components above (like year 1980) are for Gregorian
let startDate = userCalendar.date(from: dateComponents)
@@ -335,10 +385,10 @@ struct StatsController: RouteCollection {
endDateComponenents.timeZone = TimeZone(abbreviation: "EST") // Japan Standard Time
endDateComponenents.hour = 8
endDateComponenents.minute = 0
let endDate = userCalendar.date(from: endDateComponenents)
return Match.query(on: db).filter(\.$date > startDate!).filter(\.$date < endDate!).all().map { (matches) -> (Stats) in
return self.getCountedMatches(matches: matches)
@@ -352,7 +402,7 @@ struct StatsController: RouteCollection {
private func getDaysPlayed(sortedMatches:[Match]) -> [CODDate] {
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)
}
@@ -441,7 +491,7 @@ struct StatsController: RouteCollection {
return getstatsForMonth(year: 2020, month: 03, req: req)
}
func getstatsForMonth(year:Int, month:Int, req: Request) -> EventLoopFuture<Stats>{
@@ -467,14 +517,19 @@ struct StatsController: RouteCollection {
func getCasualStats( db: Database) -> EventLoopFuture<Stats>{
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)
}
}
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)
}
}
func recalc(req:Request) -> EventLoopFuture<[String:Stats]> {
return forceCalculatedStats(db: req.db)
}
func forceCalculatedStats(db: Database) -> EventLoopFuture<[String:Stats]> {
let statsWithHyder = statsWithPlayer(db: db, playerId: 5)
let statsWithoutHyder = statsWithoutPlayer(db: db, playerId: 5)
let statsFor2020 = getStatsForYear(year: 2020, db: db)
let statsFor2021 = getStatsForYear(year: 2021, db: db)
let hyderFuture = statsWithHyder.and(statsWithoutHyder)
@@ -629,32 +684,40 @@ 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))")
let queue = DispatchQueue(label: "com.sledsoft.cod-tracker.queue", attributes: .concurrent)
let group = DispatchGroup()
var overallStats:StatsWithMostRecentDailyRecord?
var mwStats:StatsWithMostRecentDailyRecord?
var bocwStats:StatsWithMostRecentDailyRecord?
var mostRecentStats:Stats?
var mwSixPlayers:Stats?
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)
@@ -678,7 +741,7 @@ struct StatsController: RouteCollection {
return match.codGame == "bocw" && self.shouldCountMatch(match: match )
}))
group.leave()
}
@@ -694,7 +757,7 @@ struct StatsController: RouteCollection {
mwFivePlayers = self.getCountedMatchesByPlayerCount(matches: matches.filter{$0.codGame == "mw"}, playerCount: 5)
group.leave()
}
group.enter()
queue.async {
@@ -707,10 +770,32 @@ struct StatsController: RouteCollection {
blackOpsColdWarNuketownHalloween = self.getRecordForMapId(matches: matches.filter{$0.codGame == "bocw"}, mapId: "69")
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()
return [
"bocw_nuketown_halloween":Stats(totalWins: blackOpsColdWarNuketownHalloween!.totalWins, totalLosses: blackOpsColdWarNuketownHalloween!.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),
"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),
]
}
}
func overall(db: Database) throws -> EventLoopFuture<OverallStats> {
let dashboardStats = try dashboard(db:db)
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
let ((matches, dashboardStats),mapConfigs) = arg
let queue = DispatchQueue(label: "com.sledsoft.cod-tracker.queue", attributes: .concurrent)
let group = DispatchGroup()
@@ -755,43 +843,43 @@ struct StatsController: RouteCollection {
var worstMap:Int?
var bestMap:Int?
//
//
group.enter()
queue.async {
mapStats = self.getMapStats(matches: matches,game: "mw", competitive: true)
//print ("maps done \(Date().timeIntervalSince(startTime))")
mapStats = self.getMapStats(matches: matches,game: "mw", competitive: true)
//print ("maps done \(Date().timeIntervalSince(startTime))")
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),
]).sorted{
$0.sortOrder < $1.sortOrder
}
]).sorted{
$0.sortOrder < $1.sortOrder
}
return OverallStats(dashboardItems: dashboardItems)
}
}
@@ -801,7 +889,7 @@ struct StatsController: RouteCollection {
return try overall(db: req.db)
}
func getMapConfigs(db: Database) -> EventLoopFuture<[MapConfig]> {
@@ -817,26 +905,26 @@ struct StatsController: RouteCollection {
func mapRecords(req: Request) throws -> EventLoopFuture<[MapRecord]> {
let matches = Match.query(on: req.db).all()
let mapConfigs = getMapConfigs(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),
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)
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)
mapStats = self.getMapStats(matches: matches,game: "mw", competitive: true)
}
let sortedMaps = self.mapsSortedByBest(records: mapStats)
let records = sortedMaps.map { (mapId) -> MapRecord in
@@ -850,51 +938,51 @@ struct StatsController: RouteCollection {
//print("\(record.map.name) \(record.stats.record) \(record.ratio)")
wins = wins + Double(record.stats.totalWins)
loss = loss + Double(record.stats.totalLosses)
}
return records
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
// }
//
// 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 ] {
@@ -904,16 +992,16 @@ struct StatsController: RouteCollection {
}
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 {
return getAllMatches(matches: matches.filter{$0.map == mapId})
return getAllMatches(matches: matches.filter{$0.map == mapId})
}
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 {
@@ -952,7 +1040,7 @@ struct StatsController: RouteCollection {
return true
}
}
for match in filteredMatches {
@@ -966,18 +1054,18 @@ struct StatsController: RouteCollection {
if let map = match.map, let mapInt = Int(map) {
if mapStats[mapInt] == nil {
mapStats[mapInt] = Stats(totalWins: 0, totalLosses: 0)
mapStats[mapInt] = Stats(totalWins: 0, totalLosses: 0)
}
if match.win {
mapStats[mapInt]?.totalWins += 1
mapStats[mapInt]?.totalWins += 1
}
else{
mapStats[mapInt]?.totalLosses += 1
}
}
}
return mapStats
}
@@ -1064,7 +1152,7 @@ struct StatsController: RouteCollection {
}
return true
}).reversed()
)
}
}
@@ -1086,9 +1174,9 @@ struct StatsController: RouteCollection {
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]> {
var remaining = remaining
if let first = remaining.popLast() {

View File

@@ -19,7 +19,7 @@ final class ColourScheme: Model, Content {
var id: UUID?
@Field(key: "game_id")
var gameId: Int
var gameId: String
@Field(key: "tile_colour")
var tileColour: String?
@@ -35,7 +35,7 @@ final class ColourScheme: Model, Content {
init() { }
// 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.gameId = gameId
self.tileColour = tileColour

View File

@@ -31,19 +31,26 @@ final class Game: Model, Content {
@Field(key: "enabled")
var enabled: Bool
@Field(key: "short_name")
var shortName: String
@Field(key: "image_name")
var imageName: String
// Creates a new, empty .
init() { }
// 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.gameId = gameId
self.name = name
self.maps = maps
self.enabled = enabled
self.shortName = shortName
self.imageName = imageName
}