1
0
mirror of https://github.com/RaidMax/IW4M-Admin.git synced 2025-06-27 23:50:40 -05:00

zombie stats code

This commit is contained in:
RaidMax
2024-07-02 16:09:30 -05:00
parent 962abcf833
commit 79bd6ca8e1
44 changed files with 2354 additions and 4264 deletions

View File

@ -17,6 +17,7 @@ using Microsoft.Extensions.Logging;
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Events;
using SharedLibraryCore.Events.Game;
using SharedLibraryCore.Events.Game.GameScript;
using SharedLibraryCore.Events.Game.GameScript.Zombie;
using SharedLibraryCore.Events.Management;
using Stats.Client.Abstractions;
@ -412,7 +413,7 @@ public class HitCalculator : IClientStatisticCalculator
}
}
private async Task<EFClientHitStatistic> GetOrAddClientHit(int clientId, long? serverId = null,
private async Task<EFClientHitStatistic> GetOrAddClientHit(int clientId, long? serverId = null, string performanceBucket = null,
int? hitLocationId = null, int? weaponId = null, int? attachmentComboId = null,
int? meansOfDeathId = null)
{
@ -424,7 +425,7 @@ public class HitCalculator : IClientStatisticCalculator
&& hit.WeaponId == weaponId
&& hit.WeaponAttachmentComboId == attachmentComboId
&& hit.MeansOfDeathId == meansOfDeathId
&& hit.ServerId == serverId);
&& (performanceBucket is not null && performanceBucket == hit.Server.PerformanceBucket || (performanceBucket is null && hit.ServerId == serverId)));
if (hitStat != null)
{
@ -432,7 +433,7 @@ public class HitCalculator : IClientStatisticCalculator
return hitStat;
}
hitStat = new EFClientHitStatistic()
hitStat = new EFClientHitStatistic
{
ClientId = clientId,
ServerId = serverId,
@ -444,18 +445,11 @@ public class HitCalculator : IClientStatisticCalculator
try
{
/*if (state.UpdateCount > MaxUpdatesBeforePersist)
{
await UpdateClientStatistics(clientId);
state.UpdateCount = 0;
}
state.UpdateCount++;*/
state.Hits.Add(hitStat);
}
catch (Exception ex)
{
_logger.LogError(ex, "Could not add {statsName} for {id}", nameof(EFClientHitStatistic),
_logger.LogError(ex, "Could not add {StatsName} for {Id}", nameof(EFClientHitStatistic),
clientId);
state.Hits.Remove(hitStat);
}

View File

@ -27,7 +27,7 @@ namespace Stats.Client
private readonly StatsConfiguration _configuration;
private readonly ApplicationConfiguration _appConfig;
private readonly List<long> _serverIds = new();
private readonly List<Tuple<long, string>> _serverIds = [];
private const string DistributionCacheKey = nameof(DistributionCacheKey);
private const string MaxZScoreCacheKey = nameof(MaxZScoreCacheKey);
@ -50,7 +50,6 @@ namespace Stats.Client
_distributionCache.SetCacheItem(async (set, token) =>
{
var validPlayTime = _configuration.TopPlayersMinPlayTime;
var distributions = new Dictionary<string, Extensions.LogParams>();
await LoadServers();
@ -60,13 +59,19 @@ namespace Stats.Client
.Where(s => s.EloRating >= 0)
.Where(s => s.Client.Level != EFClient.Permission.Banned);
foreach (var serverId in _serverIds)
{
foreach (var (serverId, performanceBucket) in _serverIds)
{
var bucketConfig =
_configuration.PerformanceBuckets.FirstOrDefault(bucket =>
bucket.Name == performanceBucket) ?? new PerformanceBucketConfiguration();
var oldestPerf = DateTime.UtcNow - bucketConfig.RankingExpiration;
var performances = await iqPerformances.Where(s => s.ServerId == serverId)
.Where(s => s.TimePlayed >= validPlayTime)
.Where(s => s.UpdatedAt >= Extensions.FifteenDaysAgo())
.Where(s => s.TimePlayed >= bucketConfig.ClientMinPlayTime.TotalSeconds)
.Where(s => s.UpdatedAt >= oldestPerf)
.Select(s => s.EloRating * 1 / 3.0 + s.Skill * 2 / 3.0)
.ToListAsync(token);
var distributionParams = performances.GenerateDistributionParameters();
distributions.Add(serverId.ToString(), distributionParams);
}
@ -165,7 +170,7 @@ namespace Stats.Client
await using var context = _contextFactory.CreateContext(false);
_serverIds.AddRange(await context.Servers
.Where(s => s.EndPoint != null && s.HostName != null)
.Select(s => s.ServerId)
.Select(s => new Tuple<long, string>(s.ServerId, s.PerformanceBucket))
.ToListAsync());
}
}
@ -204,7 +209,7 @@ namespace Stats.Client
public async Task<double?> GetRatingForZScore(double? value, string performanceBucket)
{
var maxZScore = await _maxZScoreCache.GetCacheItem(MaxZScoreCacheKey, new[] { performanceBucket ?? "null" });
var maxZScore = await _maxZScoreCache.GetCacheItem(MaxZScoreCacheKey, new[] { performanceBucket });
return maxZScore == 0 ? null : value.GetRatingForZScore(maxZScore);
}
}