diff --git a/Sources/App/Content/DashboardItem.swift b/Sources/App/Content/DashboardItem.swift index 6fb97d8..c682df5 100644 --- a/Sources/App/Content/DashboardItem.swift +++ b/Sources/App/Content/DashboardItem.swift @@ -16,7 +16,8 @@ struct DashboardItem: Content { var content:String var title2:String? = nil var content2:String? = nil - var sortOrder: Int + var sortOrder: Int + var backgroundColor = "004999" } diff --git a/Sources/App/Controllers/StatsController.swift b/Sources/App/Controllers/StatsController.swift index 8fb3f3a..5be7541 100644 --- a/Sources/App/Controllers/StatsController.swift +++ b/Sources/App/Controllers/StatsController.swift @@ -27,6 +27,8 @@ struct StatsController: RouteCollection { 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("recalculate", use: recalc) + statsRoute.get("stats","q",":query", use: history) } @@ -80,13 +82,6 @@ struct StatsController: RouteCollection { sortOrder = 5 } -// else if statisticItem.codTrackerId == "best_map_overall"{ -// title2 = "Ratio" -// content1 = "\(statisticItem.wins)-\(statisticItem.losses)" -// content2 = Utils.getRatio(wins: statisticItem.wins, losses: statisticItem.losses) -// -// -// } else if statisticItem.codTrackerId == "bocw_overall"{ title2 = "Ratio" content1 = "\(statisticItem.wins)-\(statisticItem.losses)" @@ -94,13 +89,6 @@ struct StatsController: RouteCollection { sortOrder = 3 } -// else if statisticItem.codTrackerId == "worst_map_overall"{ -// title2 = "Ratio" -// content1 = "\(statisticItem.wins)-\(statisticItem.losses)" -// content2 = Utils.getRatio(wins: statisticItem.wins, losses: statisticItem.losses) -// -// -// } else if statisticItem.codTrackerId == "with_hyder_overall"{ title2 = "Ratio" content1 = "\(statisticItem.wins)-\(statisticItem.losses)" @@ -142,15 +130,26 @@ struct StatsController: RouteCollection { } + else if statisticItem.codTrackerId == "bocw_nuketown_halloween"{ + title2 = "Ratio" + content1 = "\(statisticItem.wins)-\(statisticItem.losses)" + content2 = Utils.getRatio(wins: statisticItem.wins, losses: statisticItem.losses) + sortOrder = -2 + + } + + else { } - return DashboardItem(codTrackerId:statisticItem.codTrackerId, title: title, content: content1, title2: title2, content2: content2, sortOrder: sortOrder) + return + + 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: 100), - DashboardItem(codTrackerId:"total_mw_games", title: "Total MW Games", content: "\(totalMWGames)", title2: "", content2: "", sortOrder: -1) + DashboardItem(codTrackerId:"total_mw_games", title: "Total MW Games", content: "\(totalMWGames)", title2: "", content2: "", sortOrder: -1), ] ).sorted{$0.sortOrder < $1.sortOrder} ) @@ -624,6 +623,9 @@ struct StatsController: RouteCollection { // // } + func recalc(req:Request) -> EventLoopFuture<[String:Stats]> { + return forceCalculatedStats(db: req.db) + } func forceCalculatedStats(db: Database) -> EventLoopFuture<[String:Stats]> { @@ -661,7 +663,8 @@ struct StatsController: RouteCollection { var mwSixPlayers:Stats? var mwFivePlayers:Stats? var overallFourPlayers:Stats? -// + var blackOpsColdWarNuketownHalloween:Stats? + // var mapStats:[Int:Stats]? // var worstMap:Int? // var bestMap:Int? @@ -670,12 +673,8 @@ struct StatsController: RouteCollection { queue.async { overallStats = self.getStatsWithMostRecentDailyRecord(sortedMatches: matches) group.leave() - //print ("all stats done \(Date().timeIntervalSince(startTime))") } - - - group.enter() queue.async { mwStats = self.getStatsWithMostRecentDailyRecord(sortedMatches: matches.filter({ (match) -> Bool in @@ -716,31 +715,18 @@ struct StatsController: RouteCollection { mwSixPlayers = self.getCountedMatchesByPlayerCount(matches: matches.filter{$0.codGame == "mw"}, playerCount: 6) group.leave() } + + group.enter() + queue.async { + blackOpsColdWarNuketownHalloween = self.getRecordForMapId(matches: matches.filter{$0.codGame == "bocw"}, mapId: "Nuketown Halloween") + group.leave() + } group.wait() -// let dashboardItems:[DashboardItem] = [ -// -// // DashboardItem(codTrackerId:"total_mw_games", title: "Total MW Games", content: "\(mwStats!.totalWins + mwStats!.totalLosses)" , title2:"", content2:""), -// DashboardItem(codTrackerId:"mw_overall",title: "MW Overall", content: mwStats!.record, title2: "Ratio", content2: mwStats!.winLossRatio), -// DashboardItem(codTrackerId:"mw_six_players", title: "MW 6 Players ", content: mwSixPlayers!.record, title2: "Ratio", content2: mwSixPlayers!.winLossRatio), -// DashboardItem(codTrackerId:"mw_five_players", title: "MW 5 Players ", content: mwFivePlayers!.record, title2: "Ratio", content2: mwFivePlayers!.winLossRatio), -// DashboardItem(codTrackerId:"overall_four_players", title: "4 Player Crew", content: overallFourPlayers!.record, title2: "Ratio", content2: overallFourPlayers!.winLossRatio), -// DashboardItem(codTrackerId:"overall", title: "Overall", content: overallStats!.record, title2: "Ratio", content2: overallStats!.winLossRatio), -// DashboardItem(codTrackerId:"2021_overall", title: "2021 Overall", content: statsFor2021.record, title2: "Ratio", content2: statsFor2021.winLossRatio), -// DashboardItem(codTrackerId:"2020_overall", title: "2020 Overall", content: statsFor2020.record, title2: "Ratio", content2: statsFor2020.winLossRatio), -//// DashboardItem(codTrackerId:"win_rate_overall", title: "Win Rate", content: "\(overallStats!.winRate)", title2: "", content2: ""), -// DashboardItem(codTrackerId:"bocw_overall", title: "Cold War Overall", content: bocwStats!.record, title2: "Ratio", content2: bocwStats!.winLossRatio), -// DashboardItem(codTrackerId:"with_hyder_overall", title: "With Hyder", content: hyderStats[0].record, title2: "Ratio", content2: hyderStats[0].winLossRatio), -// DashboardItem(codTrackerId:"no_hyder_overall", title: "No Hyder", content: hyderStats[1].record, title2: "Ratio", content2: hyderStats[1].winLossRatio), -//// DashboardItem(codTrackerId:"best_map_overall", title: "Best Map", content: MapData.allMaps[bestMap!]?.name ?? "error", title2: "Ratio", content2: "\(mapStats![bestMap!]!.winLossRatio) \(mapStats![bestMap!]!.record)"), -//// DashboardItem(codTrackerId:"worst_map_overall", title: "Worst Map", content: MapData.allMaps[worstMap!]?.name ?? "error", title2: "Ratio", content2: "\(mapStats![worstMap!]!.winLossRatio) \(mapStats![worstMap!]!.record)"), -//// DashboardItem(codTrackerId:"adam_ruined_final_kills", title: "Final Kills Ruined by Adam", content: "\(matches.filter{$0.finalKillRuinedPlayerId == 6}.count + 7)", title2: "", content2: ""), -//// -// ] -// return [ + "bocw_nuketown_halloween":Stats(totalWins: blackOpsColdWarNuketownHalloween!.totalWins, totalLosses: blackOpsColdWarNuketownHalloween!.totalLosses), "mw_overall":Stats(totalWins: mwStats!.totalWins, totalLosses: mwStats!.totalLosses), "no_hyder_overall":Stats(totalWins: hyderStats[1].totalWins, totalLosses: hyderStats[1].totalLosses), "with_hyder_overall":Stats(totalWins:hyderStats[0].totalWins, totalLosses: hyderStats[0].totalLosses), @@ -752,6 +738,7 @@ 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), + ] @@ -874,6 +861,12 @@ struct StatsController: RouteCollection { func getCountedMatchesByPlayerCount(matches:[Match], playerCount:Int) -> Stats { return getCountedMatches(matches: matches.filter{$0.playerList.count == playerCount}) } + + func getRecordForMapId(matches:[Match], mapId:String) -> Stats { + return getCountedMatches(matches: matches.filter{$0.map == mapId}) + } + + func getAllMatchesByPlayerCount(matches:[Match], playerCount:Int) -> Stats { return getAllMatches(matches: matches.filter{$0.playerList.count == playerCount}) } diff --git a/Sources/App/Data/MapData.swift b/Sources/App/Data/MapData.swift index f4d9e73..47cc220 100644 --- a/Sources/App/Data/MapData.swift +++ b/Sources/App/Data/MapData.swift @@ -90,12 +90,15 @@ class MapData { 66: Map(id: 66, name: "Deprogram", imageName: "bocw_deprogram"), 67: Map(id: 67, name: "Amerika", imageName: "bocw_amerika"), 68: Map(id: 68, name: "Gluboko", imageName: "bocw_gluboko"), + + 69: Map(id: 69, name: "Nuketown Halloween", imageName: "bocw_nuketown_halloween"), + ] static let bocwMaps = { - return [1,3,8,7,4,2,29,31,5,6,30,0,34,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60].compactMap { + return [1,3,8,7,4,2,29,31,5,6,30,0,34,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,66,67,68,69].compactMap { return allMaps[$0]; } .sorted { (m1, m2) -> Bool in