diff --git a/Package.swift b/Package.swift index d9797cb..45ccbfc 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.2 +6 5// swift-tools-version:5.2 import PackageDescription let package = Package( @@ -33,4 +33,4 @@ let package = Package( .product(name: "XCTVapor", package: "vapor"), ]) ] -) \ No newline at end of file +) diff --git a/Sources/App/Controllers/StatsController.swift b/Sources/App/Controllers/StatsController.swift index 0dba26f..ef81805 100644 --- a/Sources/App/Controllers/StatsController.swift +++ b/Sources/App/Controllers/StatsController.swift @@ -11,6 +11,7 @@ struct CODDate { let minute:Int } + struct StatsController: RouteCollection { func boot(routes: RoutesBuilder) throws { let statsRoute = routes.grouped("cod-tracker","api", "stats") @@ -425,6 +426,10 @@ struct StatsController: RouteCollection { var mwStats:StatsWithMostRecentDailyRecord? var bocwStats:StatsWithMostRecentDailyRecord? var mostRecentStats:Stats? + var mwSixPlayers:Stats? + var mwFivePlayers:Stats? + var mwFourPlayers:Stats? + var mapStats:[Int:Stats]? var worstMap:Int? var bestMap:Int? @@ -441,9 +446,6 @@ struct StatsController: RouteCollection { mwStats = self.getStatsWithMostRecentDailyRecord(sortedMatches: matches.filter({ (match) -> Bool in return match.codGame == "mw" && self.shouldCountMatch(match: match ) })) - - //print ("mw stats done \(Date().timeIntervalSince(startTime))") - group.leave() } @@ -489,19 +491,46 @@ struct StatsController: RouteCollection { group.leave() } + + group.enter() + queue.async { + mwFourPlayers = getStatsByPlayerCount(matches: matches, playerCount: 4) + group.leave() + } + + + group.enter() + queue.async { + mwFivePlayers = getStatsByPlayerCount(matches: matches, playerCount: 5) + group.leave() + } + + + + group.enter() + queue.async { + mwSixPlayers = getStatsByPlayerCount(matches: matches, playerCount: 6) + group.leave() + } + group.wait() let dashboardItems = [ - DashboardItem(title: "Overall", content: overallStats!.record, title2: "Ratio", content2: overallStats!.winLossRatio), + DashboardItem(title: "Total MW Games", content: "\(mwStats!.totalWins + mwStats!.totalLosses)" , title2:"", content2:""), DashboardItem(title: "MW Overall", content: mwStats!.record, title2: "Ratio", content2: mwStats!.winLossRatio), + DashboardItem(title: "MW 6 Players ", content: mwSixPlayers!.record, title2: "Ratio", content2: mwSixPlayers!.winLossRatio), + DashboardItem(title: "MW 5 Players ", content: mwFivePlayers!.record, title2: "Ratio", content2: mwFivePlayers!.winLossRatio), + DashboardItem(title: "MW 4 Players ", content: mwFourPlayers!.record, title2: "Ratio", content2: mwFourPlayers!.winLossRatio), + DashboardItem(title: "Overall", content: overallStats!.record, title2: "Ratio", content2: overallStats!.winLossRatio), DashboardItem(title: "Cold War Overall", content: bocwStats!.record, title2: "Ratio", content2: bocwStats!.winLossRatio), DashboardItem(title: "With Hyder", content: hyderStats[0].record, title2: "Ratio", content2: hyderStats[0].winLossRatio), DashboardItem(title: "No Hyder", content: hyderStats[1].record, title2: "Ratio", content2: hyderStats[1].winLossRatio), DashboardItem(title: "Best Map", content: MapData.allMaps[bestMap!]?.name ?? "error", title2: "Ratio", content2: "\(mapStats![bestMap!]!.winLossRatio) \(mapStats![bestMap!]!.record)"), DashboardItem(title: "Worst Map", content: MapData.allMaps[worstMap!]?.name ?? "error", title2: "Ratio", content2: "\(mapStats![worstMap!]!.winLossRatio) \(mapStats![worstMap!]!.record)"), DashboardItem(title: "Final Kills Ruined by Adam", content: "\(matches.filter{$0.finalKillRuinedPlayerId == 6}.count + 7)", title2: "", content2: ""), + ] return OverallStats(overall: overallStats!, mwStats: mwStats!, bocwStats: bocwStats!, mostRecentRecord: "Temporarily Unavailable", statsWithHyder:hyderStats[0], statsWithoutHyder: hyderStats[1], dashboardItems:dashboardItems) } @@ -545,6 +574,13 @@ struct StatsController: RouteCollection { }.reversed() } + func getStatsByPlayerCount(matches:[Match], playerCount:Int) -> Stats { + + return getStats(matches: matches.filter{$0.playerList.count == playerCount}) + + + + } func getBestMap (records :[ Int:Stats] ) -> Int { diff --git a/Sources/App/Models/AllStats.swift b/Sources/App/Models/AllStats.swift index c2c5355..958d956 100644 --- a/Sources/App/Models/AllStats.swift +++ b/Sources/App/Models/AllStats.swift @@ -117,6 +117,8 @@ final class Stats: Content { return (Double(totalWins) / Double(deno)).truncate(places: 3) } + + } final class StatsWithMostRecentDailyRecord: Content { diff --git a/Sources/App/Models/Match.swift b/Sources/App/Models/Match.swift index 1964b45..ed8fe4d 100644 --- a/Sources/App/Models/Match.swift +++ b/Sources/App/Models/Match.swift @@ -78,6 +78,13 @@ final class Match: Model, Content { } + + var playerList:[Int] { + return players?.components(separatedBy: ",").map({ (playerId) -> Int in + (Int(playerId.trimmingCharacters(in: .whitespaces) ) ?? -1) + }) ?? [] + } + } extension Match {