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 #26 from Zaxiure/development
Browse files Browse the repository at this point in the history
Added boss piechart to dashboard.
  • Loading branch information
Zaxiure committed Oct 10, 2022
2 parents 31061a5 + fa88ab0 commit a8fd6bd
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 9 deletions.
53 changes: 53 additions & 0 deletions HuntStats/Features/ChartHandlers/BossChartHandler.cs
Original file line number Diff line number Diff line change
@@ -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<BossChartInfo>
{
public BossChartQuery(int amount)
{
Amount = amount;
}

public int Amount { get; set; }
}


public class BossChartQueryHandler : IRequestHandler<BossChartQuery, BossChartInfo>
{
private readonly IDbConnectionFactory _connectionFactory;
private readonly IMediator _mediator;

public BossChartQueryHandler(IDbConnectionFactory connectionFactory, IMediator mediator)
{
_connectionFactory = connectionFactory;
_mediator = mediator;
}

public async Task<BossChartInfo> 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(),
};
}
}
18 changes: 9 additions & 9 deletions HuntStats/Features/ChartHandlers/MoneyChartHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,29 @@ public MoneyChartQueryHandler(IDbConnectionFactory connectionFactory, IMediator
public async Task<List<MoneyChartInfo>> 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;
Expand Down
4 changes: 4 additions & 0 deletions HuntStats/Features/MatchHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ public async Task<List<HuntMatch>> 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,
Expand Down
6 changes: 6 additions & 0 deletions HuntStats/Models/Dataset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ public class Dataset

[JsonPropertyName("data")]
public List<int> Data { get; set; }

[JsonPropertyName("backgroundColor")]
public List<string> BackgroundColor { get; set; }

[JsonPropertyName("hoverOffset")]
public int HoverOffset { get; set; }

[JsonPropertyName("fill")]
public bool Fill { get; set; }
Expand Down
84 changes: 84 additions & 0 deletions HuntStats/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,33 @@
</div>
</div>
</div>
<div class="chart-container d-flex flex-xl-row flex-column mt-3">
<div class="card col position-relative me-xl-2" style="max-height: 750px;">
<div class="card-body">
<DropdownSelect TValue="int" SearchDisabled="true" ValueChanged="HandleBossChartChange" Value="BossChartAmount" ListItems="ListItems"></DropdownSelect>
<div class="moneyChart">
<canvas @ref="_bossChart" id="chart" width="400" height="400">

</canvas>
</div>
<div class="d-flex flex-row justify-content-between mt-2">
<div class="stats" style="padding: 10px 15px; border: 2px solid #343740;border-radius: 15px;">
Spider: @Spider
</div>
<div class="stats" style="padding: 10px 15px; border: 2px solid #343740;border-radius: 15px;">
Scrapbeak: @Scrapbeak
</div>
<div class="stats" style="padding: 10px 15px; border: 2px solid #343740;border-radius: 15px;">
Butcher: @Butcher
</div>
<div class="stats" style="padding: 10px 15px; border: 2px solid #343740;border-radius: 15px;">
Assassin: @Assassin
</div>
</div>
</div>
</div>
<div class="col"></div>
</div>
</div>


Expand All @@ -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; }
Expand All @@ -124,13 +153,23 @@
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)
{
KillChartAmount = Id;
await FetchKillChart(true);
}

public async Task HandleBossChartChange(int Id)
{
BossChartAmount = Id;
await FetchBossChart(true);
}

public async Task HandleMmrChartChange(int Id)
{
MmrChartAmount = Id;
Expand Down Expand Up @@ -192,6 +231,7 @@
await JS.InvokeAsync<string>("resetChart", _mmrChart);
await JS.InvokeAsync<string>("resetChart", _xpChart);
await JS.InvokeAsync<string>("resetChart", _moneyChart);
await JS.InvokeAsync<string>("resetChart", _bossChart);
}

private async void AppStateOnNewMatchAdded()
Expand All @@ -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<string>("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<string>("createPieChart", _bossChart, new
{
labels = new List<string>()
{
"Scrapbeak",
"Spider",
"Butcher",
"Assassin",
},
datasets = new List<Dataset>()
{
new Dataset()
{
Label = "Bosses",
Data = new List<int>()
{
bossChartInfo.Scrapbeak,
bossChartInfo.Spider,
bossChartInfo.Butcher,
bossChartInfo.Assassin,
},
BackgroundColor = new List<string>()
{
"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<string>("resetChart", _killChart);
Expand Down
12 changes: 12 additions & 0 deletions HuntStats/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit a8fd6bd

Please sign in to comment.