private static async Task <UnRankedObject> ComputeStats(ModeStats stats) { if (stats != null) { return(new UnRankedObject() { GamesPlayed = (int)stats.RoundsPlayed, Wins = (int)stats.Wins, WinPercent = Math.Round(StatsCalculation.GetWinRatio(stats.Wins, stats.RoundsPlayed), 2), AvgSurvivalTime = Math.Round(StatsCalculation.GetAverageSurvivedTime(stats.TimeSurvived, stats.RoundsPlayed), 2), Adr = (int)StatsCalculation.GetAdr(stats.DamageDealt, stats.RoundsPlayed), HeadshotRatio = Math.Round(StatsCalculation.GetHeadshotRatio(stats.HeadshotKills, stats.Kills), 2), MaxKills = (int)stats.RoundMostKills, LongestKill = Math.Round(stats.LongestKill, 2), DbnosPerRound = Math.Round(StatsCalculation.GetKnocksPerRound(stats.DBNOS, stats.RoundsPlayed), 2), FraggerRating = Math.Round(StatsCalculation.GetFraggerRating( StatsCalculation.GetAdr(stats.DamageDealt, stats.RoundsPlayed), StatsCalculation.GetHeadshotRatioBelowOne(stats.HeadshotKills, stats.Kills), StatsCalculation.GetAverageSurvivedTimeBase10(stats.TimeSurvived, stats.RoundsPlayed), StatsCalculation.GetWinRatioBelowOne(stats.Wins, stats.RoundsPlayed)), 0) }); } else { return(new UnRankedObject() { GamesPlayed = 0, Wins = 0, WinPercent = 0, AvgSurvivalTime = 0, Adr = 0, HeadshotRatio = 0, MaxKills = 0, LongestKill = 0, DbnosPerRound = 0, FraggerRating = 0 }); } }
private static async Task <double> ComputeRankedFraggerRating(List <RootMatch> matches, string playername) { if (matches.Count == 0) { return(0); } else { double totalKills = 0; double headshotKills = 0; double damageDealt = 0; double timeSurvived = 0; double winPlace = 0; int count = 0; foreach (RootMatch match in matches) { if (count == 20) { break; } if (match.data.attributes.matchType == "competitive") { foreach (MatchSingleObject participant in match.included) { if (participant.type == "participant") { ParticipantObject matchplayer = (ParticipantObject)participant; string name = matchplayer.attributes.stats.name; if (name == playername) { totalKills += matchplayer.attributes.stats.kills; headshotKills += matchplayer.attributes.stats.headshotKills; damageDealt += matchplayer.attributes.stats.damageDealt; timeSurvived += matchplayer.attributes.stats.timeSurvived; if (matchplayer.attributes.stats.winPlace == 1) { winPlace += matchplayer.attributes.stats.winPlace; } count++; break; } } } } } double adr = StatsCalculation.GetAdr(damageDealt, count); double headshotratio = StatsCalculation.GetHeadshotRatioBelowOne(headshotKills, totalKills); double survivedtime = StatsCalculation.GetAverageSurvivedTimeBase10(timeSurvived, count); double winratepercent = StatsCalculation.GetWinRatioBelowOne(winPlace, count); double fraggerRating = Math.Round(StatsCalculation.GetFraggerRating(adr, headshotratio, survivedtime, winratepercent), 0); return(fraggerRating); } }