1
0
mirror of https://github.com/RaidMax/IW4M-Admin.git synced 2025-06-10 23:31:13 -05:00

Add max concurrent players over 24 hours badge to home

This commit is contained in:
RaidMax
2021-08-26 17:35:05 -05:00
parent 6cef75b5b5
commit fe140707ee
34 changed files with 4904 additions and 47 deletions

View File

@ -1,15 +1,11 @@
using System;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using SharedLibraryCore;
using SharedLibraryCore.Dtos;
using SharedLibraryCore.Interfaces;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Data.Abstractions;
using Data.Models.Client;
using Data.Models.Client.Stats;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using static SharedLibraryCore.Server;
using ILogger = Microsoft.Extensions.Logging.ILogger;
@ -20,33 +16,25 @@ namespace WebfrontCore.Controllers
{
private readonly ITranslationLookup _translationLookup;
private readonly ILogger _logger;
private readonly IDataValueCache<EFClient, (int, int)> _serverStatsCache;
private const string ServerStatKey = nameof(ServerStatKey);
private readonly IServerDataViewer _serverDataViewer;
public HomeController(ILogger<HomeController> logger, IManager manager, ITranslationLookup translationLookup,
IDataValueCache<EFClient, (int, int)> serverStatsCache) : base(manager)
IServerDataViewer serverDataViewer) : base(manager)
{
_logger = logger;
_translationLookup = translationLookup;
_serverStatsCache = serverStatsCache;
_serverStatsCache.SetCacheItem(async set =>
{
var count = await set.CountAsync();
var startOfPeriod = DateTime.UtcNow.AddHours(-24);
var recentCount = await set.CountAsync(client => client.LastConnection >= startOfPeriod);
return (count, recentCount);
}, ServerStatKey);
_serverDataViewer = serverDataViewer;
}
public async Task<IActionResult> Index(Game? game = null)
public async Task<IActionResult> Index(Game? game = null, CancellationToken cancellationToken = default)
{
ViewBag.Description = Localization["WEBFRONT_DESCRIPTION_HOME"];
ViewBag.Title = Localization["WEBFRONT_HOME_TITLE"];
ViewBag.Keywords = Localization["WEBFRONT_KEWORDS_HOME"];
var servers = Manager.GetServers().Where(_server => !game.HasValue || _server.GameName == game);
var (count, recentCount) = await _serverStatsCache.GetCacheItem(ServerStatKey);
var maxConcurrentClients = await _serverDataViewer.MaxConcurrentClientsAsync(token: cancellationToken);
var (count, recentCount) = await _serverDataViewer.ClientCountsAsync(token: cancellationToken);
var model = new IW4MAdminInfo()
{
@ -54,6 +42,7 @@ namespace WebfrontCore.Controllers
TotalOccupiedClientSlots = servers.SelectMany(_server => _server.GetClientsAsList()).Count(),
TotalClientCount = count,
RecentClientCount = recentCount,
MaxConcurrentClients = maxConcurrentClients,
Game = game,
ActiveServerGames = Manager.GetServers().Select(_server => _server.GameName).Distinct().ToArray()
};

View File

@ -129,6 +129,7 @@ namespace WebfrontCore
.GetRequiredService<IConfigurationHandler<DefaultSettings>>());
services.AddSingleton(Program.ApplicationServiceProvider
.GetRequiredService<IConfigurationHandler<StatsConfiguration>>());
services.AddSingleton(Program.ApplicationServiceProvider.GetRequiredService<IServerDataViewer>());
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

View File

@ -8,13 +8,16 @@
}
}
<div class="row mb-4 border-bottom border-top pt-3 pb-3 bg-dark">
<div class="col-xl-4 col-12">
<div class="col-xl-3 col-12">
<div class="text-muted text-center text-xl-left">@Html.Raw(formatTranslation("WEBFRONT_HOME_CLIENTS_ONLINE", Model.TotalOccupiedClientSlots, Model.TotalAvailableClientSlots))</div>
</div>
<div class="col-xl-4 col-12">
<div class="col-xl-3 col-12">
<div class="text-muted text-center text-xl-left">@Html.Raw(formatTranslation("WEBFRONT_HOME_MAX_CONCURRENT_CLIENTS", Model.MaxConcurrentClients.ToString("#,##0")))</div>
</div>
<div class="col-xl-3 col-12">
<div class="text-muted text-center">@Html.Raw(formatTranslation("WEBFRONT_HOME_RECENT_CLIENTS", Model.RecentClientCount.ToString("#,##0")))</div>
</div>
<div class="col-xl-4 col-12">
<div class="col-xl-3 col-12">
<div class="text-muted text-center text-xl-right">@Html.Raw(formatTranslation("WEBFRONT_HOME_TOTAL_CLIENTS", Model.TotalClientCount.ToString("#,##0")))</div>
</div>
</div>

View File

@ -97,6 +97,6 @@
</Target>
<Target Name="MyPreCompileTarget" BeforeTargets="Build">
<Exec Command="dotnet bundle" />
<!--<Exec Command="dotnet bundle" />-->
</Target>
</Project>