mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-10 15:20:48 -05:00
continue working on per servver topstats
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using IW4MAdmin.Plugins.Stats.Helpers;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SharedLibraryCore;
|
||||
@ -13,19 +14,43 @@ namespace IW4MAdmin.Plugins.Stats.Web.Controllers
|
||||
public class StatsController : BaseController
|
||||
{
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> TopPlayersAsync()
|
||||
public IActionResult TopPlayersAsync()
|
||||
{
|
||||
ViewBag.Title = Utilities.CurrentLocalization.LocalizationIndex.Set["WEBFRONT_STATS_INDEX_TITLE"];
|
||||
ViewBag.Description = Utilities.CurrentLocalization.LocalizationIndex.Set["WEBFRONT_STATS_INDEX_DESC"];
|
||||
ViewBag.Servers = Manager.GetServers().Select(_server => new ServerInfo() { Name = _server.Hostname, ID = _server.GetHashCode() });
|
||||
|
||||
return View("Index", await Plugin.Manager.GetTopStats(0, 50));
|
||||
return View("Index");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetTopPlayersAsync(int count, int offset)
|
||||
public async Task<IActionResult> GetTopPlayersAsync(int count, int offset, long? serverId = null)
|
||||
{
|
||||
return View("_List", await Plugin.Manager.GetTopStats(offset, count));
|
||||
// this prevents empty results when we really want aggregate
|
||||
if (serverId == 0)
|
||||
{
|
||||
serverId = null;
|
||||
}
|
||||
|
||||
var server = Manager.GetServers().FirstOrDefault(_server => _server.EndPoint == serverId);
|
||||
|
||||
if (server != null)
|
||||
{
|
||||
serverId = await StatManager.GetIdForServer(server);
|
||||
}
|
||||
|
||||
var results = await Plugin.Manager.GetTopStats(offset, count, serverId);
|
||||
|
||||
// this returns an empty result so we know to stale the loader
|
||||
if (results.Count == 0 && offset > 0)
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
return View("Components/TopPlayers/_List", results);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@ -40,7 +65,7 @@ namespace IW4MAdmin.Plugins.Stats.Web.Controllers
|
||||
where message.ServerId == serverId
|
||||
where message.TimeSent >= whenLower
|
||||
where message.TimeSent <= whenUpper
|
||||
select new SharedLibraryCore.Dtos.ChatInfo()
|
||||
select new ChatInfo()
|
||||
{
|
||||
ClientId = message.ClientId,
|
||||
Message = message.Message,
|
||||
|
@ -18,6 +18,5 @@ namespace IW4MAdmin.Plugins.Stats.Web.Dtos
|
||||
public int Deaths { get; set; }
|
||||
public int RatingChange { get; set; }
|
||||
public List<double> PerformanceHistory { get; set; }
|
||||
public List<ServerInfo> Servers { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -82,13 +82,13 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<TopStatsInfo>> GetTopStats(int start, int count)
|
||||
public async Task<List<TopStatsInfo>> GetTopStats(int start, int count, long? serverId = null)
|
||||
{
|
||||
using (var context = new DatabaseContext(true))
|
||||
{
|
||||
// setup the query for the clients within the given rating range
|
||||
var iqClientRatings = (from rating in context.Set<EFRating>()
|
||||
.Where(GetRankingFunc())
|
||||
.Where(GetRankingFunc(serverId))
|
||||
select new
|
||||
{
|
||||
rating.RatingHistory.ClientId,
|
||||
@ -113,7 +113,7 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
|
||||
|
||||
var iqRatingInfo = from rating in context.Set<EFRating>()
|
||||
where clientIds.Contains(rating.RatingHistory.ClientId)
|
||||
where rating.ServerId == null
|
||||
where rating.ServerId == serverId
|
||||
select new
|
||||
{
|
||||
rating.Ranking,
|
||||
|
@ -26,7 +26,7 @@ namespace IW4MAdmin.Plugins.Stats
|
||||
public string Author => "RaidMax";
|
||||
|
||||
public static StatManager Manager { get; private set; }
|
||||
private IManager ServerManager;
|
||||
public static IManager ServerManager;
|
||||
public static BaseConfigurationHandler<StatsConfiguration> Config { get; private set; }
|
||||
|
||||
public async Task OnEventAsync(GameEvent E, Server S)
|
||||
|
28
Plugins/Stats/ViewComponents/TopPlayersViewComponent.cs
Normal file
28
Plugins/Stats/ViewComponents/TopPlayersViewComponent.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using IW4MAdmin.Plugins.Stats;
|
||||
using IW4MAdmin.Plugins.Stats.Helpers;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Stats.ViewComponents
|
||||
{
|
||||
public class TopPlayersViewComponent : ViewComponent
|
||||
{
|
||||
public async Task<IViewComponentResult> InvokeAsync(int count, int offset, long? serverId = null)
|
||||
{
|
||||
if (serverId == 0)
|
||||
{
|
||||
serverId = null;
|
||||
}
|
||||
|
||||
var server = Plugin.ServerManager.GetServers().FirstOrDefault(_server => _server.EndPoint == serverId);
|
||||
|
||||
if (server != null)
|
||||
{
|
||||
serverId = await StatManager.GetIdForServer(server);
|
||||
}
|
||||
|
||||
return View("_List", await Plugin.Manager.GetTopStats(offset, count, serverId));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user