diff --git a/Plugins/Stats/Commands/ViewStats.cs b/Plugins/Stats/Commands/ViewStats.cs index 96c409f49..5ef774de7 100644 --- a/Plugins/Stats/Commands/ViewStats.cs +++ b/Plugins/Stats/Commands/ViewStats.cs @@ -53,13 +53,15 @@ namespace IW4MAdmin.Plugins.Stats.Commands var serverId = StatManager.GetIdForServer(E.Owner); + var totalRankedPlayers = await Plugin.Manager.GetTotalRankedPlayers(serverId); + // getting stats for a particular client if (E.Target != null) { var performanceRanking = await Plugin.Manager.GetClientOverallRanking(E.Target.ClientId, serverId); var performanceRankingString = performanceRanking == 0 ? _translationLookup["WEBFRONT_STATS_INDEX_UNRANKED"] - : $"{_translationLookup["WEBFRONT_STATS_INDEX_RANKED"]} #{performanceRanking}"; + : $"{_translationLookup["WEBFRONT_STATS_INDEX_RANKED"]} #{performanceRanking}/{totalRankedPlayers}"; // target is currently connected so we want their cached stats if they exist if (E.Owner.GetClientsAsList().Any(client => client.Equals(E.Target))) @@ -87,7 +89,7 @@ namespace IW4MAdmin.Plugins.Stats.Commands var performanceRanking = await Plugin.Manager.GetClientOverallRanking(E.Origin.ClientId, serverId); var performanceRankingString = performanceRanking == 0 ? _translationLookup["WEBFRONT_STATS_INDEX_UNRANKED"] - : $"{_translationLookup["WEBFRONT_STATS_INDEX_RANKED"]} #{performanceRanking}"; + : $"{_translationLookup["WEBFRONT_STATS_INDEX_RANKED"]} #{performanceRanking}/{totalRankedPlayers}"; // check if current client is connected to the server if (E.Owner.GetClientsAsList().Any(client => client.Equals(E.Origin))) diff --git a/Plugins/Stats/Helpers/StatManager.cs b/Plugins/Stats/Helpers/StatManager.cs index 36740172f..b7f80486e 100644 --- a/Plugins/Stats/Helpers/StatManager.cs +++ b/Plugins/Stats/Helpers/StatManager.cs @@ -113,19 +113,33 @@ namespace IW4MAdmin.Plugins.Stats.Helpers return 0; } + public Expression> GetNewRankingFunc(int? clientId = null, long? serverId = null) + { + return (ranking) => ranking.ServerId == serverId + && ranking.Client.Level != Data.Models.Client.EFClient.Permission.Banned + && ranking.Client.LastConnection >= Extensions.FifteenDaysAgo() + && ranking.ZScore != null + && ranking.PerformanceMetric != null + && ranking.Newest + && ranking.Client.TotalConnectionTime >= + _configHandler.Configuration().TopPlayersMinPlayTime; + } + + public async Task GetTotalRankedPlayers(long serverId) + { + await using var context = _contextFactory.CreateContext(enableTracking: false); + + return await context.Set() + .Where(GetNewRankingFunc(serverId: serverId)) + .CountAsync(); + } + public async Task> GetNewTopStats(int start, int count, long? serverId = null) { await using var context = _contextFactory.CreateContext(false); var clientIdsList = await context.Set() - .Where(ranking => ranking.ServerId == serverId) - .Where(ranking => ranking.Client.Level != Data.Models.Client.EFClient.Permission.Banned) - .Where(ranking => ranking.Client.LastConnection >= Extensions.FifteenDaysAgo()) - .Where(ranking => ranking.ZScore != null) - .Where(ranking => ranking.PerformanceMetric != null) - .Where(ranking => ranking.Newest) - .Where(ranking => - ranking.Client.TotalConnectionTime >= _configHandler.Configuration().TopPlayersMinPlayTime) + .Where(GetNewRankingFunc(serverId: serverId)) .OrderByDescending(ranking => ranking.PerformanceMetric) .Select(ranking => ranking.ClientId) .Skip(start)