Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #30 from Zaxiure/add_totals_of_all_matches_to_dash…
Browse files Browse the repository at this point in the history
…board

Added totals to the dashboard.
  • Loading branch information
Zaxiure committed Oct 23, 2022
2 parents a8fd6bd + 1aae4ce commit 0d20479
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 2 deletions.
73 changes: 73 additions & 0 deletions HuntStats/Features/TotalHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using HuntStats.Data;
using HuntStats.State;
using MediatR;

namespace HuntStats.Features;

public class TotalView
{
public int Kills { get; set; }
public int YourKills { get; set; }

public int Assists { get; set; }

public int Deaths { get; set; }
}

public class GetTotalsCommand : IRequest<TotalView>
{

}

public class GetTotalsCommandHandler : IRequestHandler<GetTotalsCommand, TotalView>
{
private readonly IDbConnectionFactory _connectionFactory;
private readonly AppState _appState;
private readonly IMediator _mediator;

public GetTotalsCommandHandler(IDbConnectionFactory connectionFactory, AppState appState, IMediator mediator)
{
_connectionFactory = connectionFactory;
_appState = appState;
_mediator = mediator;
}

public async Task<TotalView> Handle(GetTotalsCommand request, CancellationToken cancellationToken)
{
using var con = await _connectionFactory.GetOpenConnectionAsync(cancellationToken);
var matches = await _mediator.Send(new GetAllMatchCommand());
var Settings = await _mediator.Send(new GetSettingsCommand());
var test = matches.Select(x => x.Teams.Select(x => x.Players.Select(x => x.KilledByMe).Sum()).Sum());


var totals = matches.Select(async x =>
{
var accolades = await _mediator.Send(new GetAccoladesByMatchIdCommand(x.Id));
var team = x.Teams.FirstOrDefault(x => x.Players.FirstOrDefault(y => y.ProfileId == Settings.PlayerProfileId) != null);
if (team != null)
{
var Assists = 0;
if (accolades.FirstOrDefault(x => x.Category == "accolade_players_killed_assist") != null) Assists = accolades.FirstOrDefault(x => x.Category == "accolade_players_killed_assist").Hits;
var Kills = x.Teams.Select(x => x.Players.Select(y => y.KilledByMe + y.DownedByMe + y.KilledByTeammate + y.DownedByTeammate).Sum()).Sum();
var YourKills = x.Teams.Select(x => x.Players.Select(y => y.KilledByMe + y.DownedByMe).Sum()).Sum();
var Deaths = x.Teams.Select(x => x.Players.Select(y => y.KilledMe + y.DownedMe).Sum()).Sum();
return new TotalView
{
YourKills = YourKills,
Deaths = Deaths,
Kills = Kills,
Assists = Assists
};
}
return null;
}).Select(x => x.Result).Where(x => x != null).ToList();

return new TotalView()
{
Kills = totals.Select(x => x.Kills).Sum(),
YourKills = totals.Select(x => x.YourKills).Sum(),
Deaths = totals.Select(x => x.Deaths).Sum(),
Assists = totals.Select(x => x.Assists).Sum(),
};
}
}
32 changes: 30 additions & 2 deletions HuntStats/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,29 @@
@inject IJSRuntime JS

<div class="card-container" style="margin: auto;">
<h3>Statistics</h3>
<div class="chart-container d-flex flex-xl-row flex-column">
<h5>Overall Statistics</h5>
<div class="d-flex flex-row justify-content-between mt-2 mb-3">
<div class="stats" style="padding: 10px 15px; border: 2px solid #343740;border-radius: 15px;">
Total Kills: @Totals.Kills
</div>
<div class="stats" style="padding: 10px 15px; border: 2px solid #343740;border-radius: 15px;">
Your kills: @Totals.YourKills
</div>
<div class="stats" style="padding: 10px 15px; border: 2px solid #343740;border-radius: 15px;">
Assists: @Totals.Assists
</div>
<div class="stats" style="padding: 10px 15px; border: 2px solid #343740;border-radius: 15px;">
KD: @(((double)Totals.YourKills / Totals.Deaths).ToString("#.##").Replace("NaN", "0"))
</div>
<div class="stats" style="padding: 10px 15px; border: 2px solid #343740;border-radius: 15px;">
KDA: @(((double)(Totals.YourKills + Totals.Assists) / Totals.Deaths).ToString("#.##").Replace("NaN", "0"))
</div>
<div class="stats" style="padding: 10px 15px; border: 2px solid #343740;border-radius: 15px;">
Deaths: @Totals.Deaths
</div>
</div>
<h5>Graphical statistics</h5>
<div class="chart-container d-flex flex-xl-row flex-column mt-2">
<div class="card col position-relative me-xl-2" style="max-height: 750px;">
<div class="card-body">
<DropdownSelect TValue="int" SearchDisabled="true" ValueChanged="HandleKillChartChange" Value="KillChartAmount" ListItems="ListItems"></DropdownSelect>
Expand Down Expand Up @@ -140,6 +161,7 @@
private ElementReference _xpChart;
private ElementReference _bossChart;

public TotalView Totals { get; set; } = new();
public int MmrChartAmount { get; set; } = 25;
public int MoneyChartAmount { get; set; } = 25;
public int KillChartAmount { get; set; } = 25;
Expand Down Expand Up @@ -247,6 +269,12 @@
await FetchMoneyChart(reset);
await FetchXpChart(reset);
await FetchBossChart(reset);
await FetchTotals();
}

public async Task FetchTotals()
{
Totals = await Mediator.Send(new GetTotalsCommand());
}

public async Task FetchBossChart(bool reset = false)
Expand Down

0 comments on commit 0d20479

Please sign in to comment.