player count stats

This commit is contained in:
Michael Simard
2021-01-18 07:55:55 -06:00
parent ce46570099
commit 5f6d96137b
4 changed files with 51 additions and 6 deletions

View File

@@ -1,4 +1,4 @@
// swift-tools-version:5.2
6 5// swift-tools-version:5.2
import PackageDescription
let package = Package(

View File

@@ -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()
}
@@ -490,18 +492,45 @@ struct StatsController: RouteCollection {
}
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 {

View File

@@ -117,6 +117,8 @@ final class Stats: Content {
return (Double(totalWins) / Double(deno)).truncate(places: 3)
}
}
final class StatsWithMostRecentDailyRecord: Content {

View File

@@ -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 {