diff --git a/HuntStats/Features/ChartHandlers/BossChartHandler.cs b/HuntStats/Features/ChartHandlers/BossChartHandler.cs new file mode 100644 index 0000000..17983c0 --- /dev/null +++ b/HuntStats/Features/ChartHandlers/BossChartHandler.cs @@ -0,0 +1,53 @@ +using HuntStats.Data; +using MediatR; + +namespace HuntStats.Features.ChartHandlers; + +public class BossChartInfo +{ + public DateTime DateTime { get; set; } + + public int Assassin { get; set; } + public int Butcher { get; set; } + public int Spider { get; set; } + public int Scrapbeak { get; set; } +} + +public class BossChartQuery : IRequest +{ + public BossChartQuery(int amount) + { + Amount = amount; + } + + public int Amount { get; set; } +} + + +public class BossChartQueryHandler : IRequestHandler +{ + private readonly IDbConnectionFactory _connectionFactory; + private readonly IMediator _mediator; + + public BossChartQueryHandler(IDbConnectionFactory connectionFactory, IMediator mediator) + { + _connectionFactory = connectionFactory; + _mediator = mediator; + } + + public async Task Handle(BossChartQuery request, CancellationToken cancellationToken) + { + using var con = await _connectionFactory.GetOpenConnectionAsync(); + var Matches = await _mediator.Send(new GetAllMatchCommand()); + var Settings = await _mediator.Send(new GetSettingsCommand()); + Matches = Matches.OrderByDescending(x => x.DateTime).Take(request.Amount).ToList(); + + return new BossChartInfo() + { + Scrapbeak = Matches.Select(x => x.Scrapbeak ? 1 : 0).Sum(), + Spider = Matches.Select(x => x.Spider ? 1 : 0).Sum(), + Assassin = Matches.Select(x => x.Assassin ? 1 : 0).Sum(), + Butcher = Matches.Select(x => x.Butcher ? 1 : 0).Sum(), + }; + } +} \ No newline at end of file diff --git a/HuntStats/Features/ChartHandlers/MoneyChartHandler.cs b/HuntStats/Features/ChartHandlers/MoneyChartHandler.cs index d2a862b..c102eb7 100644 --- a/HuntStats/Features/ChartHandlers/MoneyChartHandler.cs +++ b/HuntStats/Features/ChartHandlers/MoneyChartHandler.cs @@ -33,29 +33,29 @@ public MoneyChartQueryHandler(IDbConnectionFactory connectionFactory, IMediator public async Task> Handle(MoneyChartQuery request, CancellationToken cancellationToken) { using var con = await _connectionFactory.GetOpenConnectionAsync(); - var Matches = await _mediator.Send(new GetAllMatchCommand()); - var Settings = await _mediator.Send(new GetSettingsCommand()); - Matches = Matches.OrderByDescending(x => x.DateTime).Take(request.Amount).ToList(); + var matches = await _mediator.Send(new GetAllMatchCommand()); + var settings = await _mediator.Send(new GetSettingsCommand()); + matches = matches.OrderByDescending(x => x.DateTime).Take(request.Amount).ToList(); - return Matches.Select(async x => + return matches.Select(async x => { var accolades = await _mediator.Send(new GetAccoladesByMatchIdCommand(x.Id)); var entries = await _mediator.Send(new GetEntriesByMatchIdCommand(x.Id)); - var team = x.Teams.FirstOrDefault(x => x.Players.FirstOrDefault(y => y.ProfileId == Settings.PlayerProfileId) != null); + var team = x.Teams.FirstOrDefault(x => x.Players.FirstOrDefault(y => y.ProfileId == settings.PlayerProfileId) != null); if (team != null) { - var HuntDollars = 0; - HuntDollars += accolades.Select(x => x.Bounty).Sum(); + var huntDollars = 0; + huntDollars += accolades.Select(x => x.Bounty).Sum(); var entry = entries.FirstOrDefault(x => x.Category == "accolade_found_gold"); if(entry != null) { - HuntDollars += entry.RewardSize; + huntDollars += entry.RewardSize; } return new MoneyChartInfo() { DateTime = x.DateTime, - HuntDollars = HuntDollars + HuntDollars = huntDollars }; } return null; diff --git a/HuntStats/Features/MatchHandler.cs b/HuntStats/Features/MatchHandler.cs index f0b3159..a1fcc94 100644 --- a/HuntStats/Features/MatchHandler.cs +++ b/HuntStats/Features/MatchHandler.cs @@ -193,6 +193,10 @@ public async Task> Handle(GetAllMatchCommand request, Cancellati { Id = x.Id, DateTime = x.DateTime, + Scrapbeak = x.Scrapbeak, + Assassin = x.Assassin, + Butcher = x.Butcher, + Spider = x.Spider, Teams = teams.Select(team => new Team() { Id = team.Id, diff --git a/HuntStats/Models/Dataset.cs b/HuntStats/Models/Dataset.cs index 3f20a16..431c831 100644 --- a/HuntStats/Models/Dataset.cs +++ b/HuntStats/Models/Dataset.cs @@ -9,6 +9,12 @@ public class Dataset [JsonPropertyName("data")] public List Data { get; set; } + + [JsonPropertyName("backgroundColor")] + public List BackgroundColor { get; set; } + + [JsonPropertyName("hoverOffset")] + public int HoverOffset { get; set; } [JsonPropertyName("fill")] public bool Fill { get; set; } diff --git a/HuntStats/Pages/Index.razor b/HuntStats/Pages/Index.razor index 7c81e16..86c198e 100644 --- a/HuntStats/Pages/Index.razor +++ b/HuntStats/Pages/Index.razor @@ -101,6 +101,33 @@ +
+
+
+ +
+ + + +
+
+
+ Spider: @Spider +
+
+ Scrapbeak: @Scrapbeak +
+
+ Butcher: @Butcher +
+
+ Assassin: @Assassin +
+
+
+
+
+
@@ -111,10 +138,12 @@ private ElementReference _killChart; private ElementReference _moneyChart; private ElementReference _xpChart; + private ElementReference _bossChart; public int MmrChartAmount { get; set; } = 25; public int MoneyChartAmount { get; set; } = 25; public int KillChartAmount { get; set; } = 25; + public int BossChartAmount { get; set; } = 25; public int XpChartAmount { get; set; } = 25; public int TotalKills { get; set; } public int TotalYourKills { get; set; } @@ -124,6 +153,10 @@ public int AverageMatchMmr { get; set; } = 0; public int AverageMoney { get; set; } = 0; public int AverageXp { get; set; } = 0; + public int Spider { get; set; } = 0; + public int Scrapbeak { get; set; } = 0; + public int Butcher { get; set; } = 0; + public int Assassin { get; set; } = 0; public async Task HandleKillChartChange(int Id) { @@ -131,6 +164,12 @@ await FetchKillChart(true); } + public async Task HandleBossChartChange(int Id) + { + BossChartAmount = Id; + await FetchBossChart(true); + } + public async Task HandleMmrChartChange(int Id) { MmrChartAmount = Id; @@ -192,6 +231,7 @@ await JS.InvokeAsync("resetChart", _mmrChart); await JS.InvokeAsync("resetChart", _xpChart); await JS.InvokeAsync("resetChart", _moneyChart); + await JS.InvokeAsync("resetChart", _bossChart); } private async void AppStateOnNewMatchAdded() @@ -206,8 +246,52 @@ await FetchMmrChart(reset); await FetchMoneyChart(reset); await FetchXpChart(reset); + await FetchBossChart(reset); + } + + public async Task FetchBossChart(bool reset = false) + { + if(reset) await JS.InvokeAsync("resetChart", _bossChart); + var bossChartInfo = await Mediator.Send(new BossChartQuery(BossChartAmount)); + Scrapbeak = bossChartInfo.Scrapbeak; + Assassin = bossChartInfo.Assassin; + Butcher = bossChartInfo.Butcher; + Spider = bossChartInfo.Spider; + await JS.InvokeAsync("createPieChart", _bossChart, new + { + labels = new List() + { + "Scrapbeak", + "Spider", + "Butcher", + "Assassin", + }, + datasets = new List() + { + new Dataset() + { + Label = "Bosses", + Data = new List() + { + bossChartInfo.Scrapbeak, + bossChartInfo.Spider, + bossChartInfo.Butcher, + bossChartInfo.Assassin, + }, + BackgroundColor = new List() + { + "rgb(255, 99, 132)", + "rgb(54, 162, 235)", + "rgb(255, 205, 86)", + "rgb(89, 206, 143)" + }, + HoverOffset = 4 + }, + } + }); } + public async Task FetchKillChart(bool reset = false) { if(reset) await JS.InvokeAsync("resetChart", _killChart); diff --git a/HuntStats/wwwroot/index.html b/HuntStats/wwwroot/index.html index f2badd3..eeee779 100644 --- a/HuntStats/wwwroot/index.html +++ b/HuntStats/wwwroot/index.html @@ -68,6 +68,18 @@ })] } + window.createPieChart = (chartElement, data) => { + console.log(data); + charts = [...charts, new Chart(chartElement, { + type: "pie", + data: data, + options: { + responsive:true, + maintainAspectRatio: false, + } + })] + } + window.createDropdown = (clickElement, dropdownElement) => { let dropdown = Popper.createPopper(clickElement, dropdownElement, { placement: "bottom-start",