feat: tanks table ready

This commit is contained in:
Mikhail Shabanov committed 2021-07-15 22:14:41 +02:00
1 parent 3093b5ce38
commit 08946996a5
8 files changed
+322 -54

No files matched your search

+14
View File
@@ -24,6 +24,20 @@
public const string ScaleUnicumColor = "#a785bb";
public const string ScaleSuperUnicumColor = "#8348ab";
public const string HeavyTank = "heavyTank";
public const string AtSpg = "AT-SPG";
public const string MediumTank = "mediumTank";
public const string LightTank = "lightTank";
public const string CountryUsa = "usa";
public const string CountryFrance = "france";
public const string CountryUssr = "ussr";
public const string CountryChina = "china";
public const string CountryUk = "uk";
public const string CountryJapan = "japan";
public const string CountryGermany = "germany";
public const string CountryOther = "other";
public const string CountryEuropean = "european";
}
}
@@ -20,14 +20,14 @@ namespace WotBlitzStatisticsPro.Blazor.Helpers
{
return tankTypeId switch
{
"heavyTank" when !isPremium => "/tank-type/vehicle.class.heavy.small.scale-200.png",
"heavyTank" when isPremium => "/tank-type/vehicle.class.heavy.premium.small.scale-200.png",
"AT-SPG" when !isPremium => "/tank-type/vehicle.class.atspg.small.scale-200.png",
"AT-SPG" when isPremium => "/tank-type/vehicle.class.atspg.premium.small.scale-200.png",
"mediumTank" when !isPremium => "/tank-type/vehicle.class.medium.small.scale-200.png",
"mediumTank" when isPremium => "/tank-type/vehicle.class.medium.premium.small.scale-200.png",
"lightTank" when !isPremium => "/tank-type/vehicle.class.light.small.scale-200.png",
"lightTank" when isPremium => "/tank-type/vehicle.class.light.premium.small.scale-200.png",
Constants.HeavyTank when !isPremium => "/tank-type/vehicle.class.heavy.small.scale-200.png",
Constants.HeavyTank when isPremium => "/tank-type/vehicle.class.heavy.premium.small.scale-200.png",
Constants.AtSpg when !isPremium => "/tank-type/vehicle.class.atspg.small.scale-200.png",
Constants.AtSpg when isPremium => "/tank-type/vehicle.class.atspg.premium.small.scale-200.png",
Constants.MediumTank when !isPremium => "/tank-type/vehicle.class.medium.small.scale-200.png",
Constants.MediumTank when isPremium => "/tank-type/vehicle.class.medium.premium.small.scale-200.png",
Constants.LightTank when !isPremium => "/tank-type/vehicle.class.light.small.scale-200.png",
Constants.LightTank when isPremium => "/tank-type/vehicle.class.light.premium.small.scale-200.png",
_ => ""
};
}
@@ -36,15 +36,15 @@ namespace WotBlitzStatisticsPro.Blazor.Helpers
{
return nationTypeId switch
{
"usa" => "flags/usa.png",
"france" => "flags/france.png",
"ussr" => "flags/ussr.png",
"china" => "flags/china.png",
"uk" => "flags/uk.png",
"japan" => "flags/japan.png",
"germany" => "flags/germany.png",
"other" => "flags/other.png",
"european" => "flags/eu.png",
Constants.CountryUsa => "flags/usa.png",
Constants.CountryFrance => "flags/france.png",
Constants.CountryUssr => "flags/ussr.png",
Constants.CountryChina => "flags/china.png",
Constants.CountryUk => "flags/uk.png",
Constants.CountryJapan => "flags/japan.png",
Constants.CountryGermany => "flags/germany.png",
Constants.CountryOther => "flags/other.png",
Constants.CountryEuropean => "flags/eu.png",
_ => "flags/vehicle.nation.unknown.scale-200.png"
};
}
@@ -0,0 +1,4 @@
namespace WotBlitzStatisticsPro.Blazor.Model
{
public record FilterItem<T>(T ItemId, string ItemName);
}
@@ -1,8 +0,0 @@
using System;
namespace WotBlitzStatisticsPro.Blazor.Model
{
[Obsolete("This is temporary item. In the future there should be two new data models with 'clan, winrate and battles' for player, and 'name, tag members count' for clan")]
public record SearchItem(long ItemId, string ItemName);
}
@@ -1,19 +1,67 @@
@using WotBlitzStatisticsPro.Blazor.Helpers
@inject TooltipService TooltipService
@inject IStringLocalizer<App> Localize
@inherits PlayerInfoTanksListBase;
<div class="row">
<div class="col-lg-2 col-md-2">
<RadzenDropDown @bind-Value="@FilteredTiers" Multiple="true" TextProperty="ItemName" ValueProperty="ItemId" Style="width: 100%"
AllowClear="false"
Change=@OnFilterChange
Placeholder="@Localize["Filter tier..."]"
Data="@TierFilter"/>
</div>
<div class="col-lg-2 col-md-2">
<RadzenDropDown @bind-Value="@FilteredTankTypes" Multiple="true" TextProperty="ItemName" ValueProperty="ItemId" Style="width: 100%"
AllowClear="false"
Change=@OnFilterChange
Placeholder="@Localize["Filter tank types..."]"
Data="@TankTypesFilter">
<Template Context="data">
<RadzenImage Path="@data.ItemName" style="width: 24px; height: 24px;" />
</Template>
</RadzenDropDown>
</div>
<div class="col-lg-2 col-md-2">
<RadzenCheckBox @bind-Value=@FilterIsPremium TriState="true" TValue="bool?" Change=@(args => OnFilterChange(args)) /><RadzenLabel Text="@Localize["Premium tanks"]" Style="margin-left: 5px" Component="CheckBox" />
</div>
<div class="col-lg-2 col-md-2">
<RadzenDropDown @bind-Value="@FilteredNations" Multiple="true" TextProperty="ItemName" ValueProperty="ItemId" Style="width: 100%"
AllowClear="false"
Change=@OnFilterChange
Placeholder="@Localize["Filter nations..."]"
Data="@NationsFilter">
<Template Context="data">
<RadzenImage Path="@data.ItemName" style="width: 35px; height: 23px; border-radius: 4px;" />
</Template>
</RadzenDropDown>
</div>
<div class="col-lg-2 col-md-2">
<RadzenDropDown @bind-Value="@FilteredMastery" Multiple="true" TextProperty="ItemName" ValueProperty="ItemId" Style="width: 100%"
AllowClear="false"
Change=@OnFilterChange
Placeholder="@Localize["Filter mark of mastery..."]"
Data="@MasteryFilter">
<Template Context="data">
<RadzenImage Path="@data.ItemName" style="width: 24px; height: 24px;" />
</Template>
</RadzenDropDown>
</div>
<div class="col-lg-2 col-md-2">
<RadzenNumeric TValue="int?" @bind-Value=@MinBattles Placeholder="@Localize["Min battles"]" Change=@(args => OnFilterChange(args)) />
</div>
</div>
<RadzenDataGrid AllowFiltering="true"
AllowColumnResize="true"
FilterMode="FilterMode.Advanced"
FilterMode="FilterMode.Simple"
PageSize="10"
AllowPaging="true"
AllowSorting="true"
Data="@TanksList"
Data="@FilteredTankList"
TItem="ITank"
ColumnWidth="300px"
LogicalFilterOperator="LogicalFilterOperator.Or">
LogicalFilterOperator="LogicalFilterOperator.Or"
@ref="TanksGrid">
<Columns>
<RadzenDataGridColumn TItem="ITank" Property="Tier" Filterable="false" Sortable="true" Title="" Frozen="true" Width="34px" TextAlign="TextAlign.Center">
<RadzenDataGridColumn TItem="ITank" Property="Tier" Sortable="true" Filterable="false" Title="" Frozen="true" Width="34px" TextAlign="TextAlign.Center">
<Template Context="data">
<b>@data.Tier.RomanNumber()</b>
</Template>
@@ -38,8 +86,16 @@
<RadzenImage Path="@data.PreviewImage" style="width: 50px; height: 40px; border-radius: 8px;" />
</Template>
</RadzenDataGridColumn>
<RadzenDataGridColumn TItem="ITank" Property="Name" Filterable="false" Sortable="true" Title="@Localize["Tank"]" Frozen="true" Width="100px" TextAlign="TextAlign.Left" />
<RadzenDataGridColumn TItem="ITank" Property="Battles" Filterable="false" Sortable="true" Title="⚔" Frozen="false" Width="70px" TextAlign="TextAlign.Center" />
<RadzenDataGridColumn TItem="ITank" Property="Name" Filterable="false" Sortable="true" Title="@Localize["Tank"]" Frozen="true" Width="100px" TextAlign="TextAlign.Left">
<FooterTemplate>
@Localize["Tanks"]: <b>@TanksGrid.View.Count()</b> @Localize["of"] <b>@TanksList.Count()</b>
</FooterTemplate>
</RadzenDataGridColumn>
<RadzenDataGridColumn TItem="ITank" Property="Battles" Filterable="false" Sortable="true" Title="⚔" Frozen="false" Width="70px" TextAlign="TextAlign.Center">
<FooterTemplate>
<b>@TotalBattles.ToString("N0")</b>
</FooterTemplate>
</RadzenDataGridColumn>
<RadzenDataGridColumn TItem="ITank" Property="WinRate"
Filterable="false"
Sortable="true"
@@ -51,6 +107,10 @@
@data.WinRate.ToString("N0")%
<div style="background-color: @data.WinRate.ScaleColor(); width: 100%; height: 5px; margin-left: 2px; margin-right: 2px;"></div>
</Template>
<FooterTemplate>
<b>∼@AvgWinRate%</b>
<div style="background-color: @AvgWinRate.ScaleColor(); width: 100%; height: 5px; margin-left: 2px; margin-right: 2px;"></div>
</FooterTemplate>
</RadzenDataGridColumn>
<RadzenDataGridColumn TItem="ITank" Property="Wn7"
Filterable="false"
@@ -64,29 +124,41 @@
@data.Wn7.ToString("N0")
<div style="background-color: @data.Wn7.Wn7ScaleColor(); width: 100%; height: 5px; margin-left: 2px; margin-right: 2px;"></div>
</Template>
<FooterTemplate>
<b>∼@AvgWn7.ToString("N0")%</b>
<div style="background-color: @AvgWn7.Wn7ScaleColor(); width: 100%; height: 5px; margin-left: 2px; margin-right: 2px;"></div>
</FooterTemplate>
</RadzenDataGridColumn>
<RadzenDataGridColumn TItem="ITank" Property="AvgDamage"
Filterable="false"
Sortable="true"
Title="💣"
Frozen="false"
Width="50px"
Width="80px"
TextAlign="TextAlign.Center"
FormatString="{0:N0}"/>
FormatString="{0:N0}">
<FooterTemplate>
<b>∼@AvgTotalDamage.ToString("N0")</b>
</FooterTemplate>
</RadzenDataGridColumn>
<RadzenDataGridColumn TItem="ITank" Property="AvgXp"
Filterable="false"
Sortable="true"
Title="⭐"
Frozen="false"
Width="50px"
Width="80px"
TextAlign="TextAlign.Center"
FormatString="{0:N0}"/>
FormatString="{0:N0}">
<FooterTemplate>
<b>∼@AvgTotalXp.ToString("N0")</b>
</FooterTemplate>
</RadzenDataGridColumn>
<RadzenDataGridColumn TItem="ITank" Property="MaxXp"
Filterable="false"
Sortable="true"
Title="🌟"
Frozen="false"
Width="50px"
Width="80px"
TextAlign="TextAlign.Center"
FormatString="{0:N0}"/>
<RadzenDataGridColumn TItem="ITank" Property="SurvivalRate"
@@ -96,7 +168,11 @@
Frozen="false"
Width="50px"
TextAlign="TextAlign.Center"
FormatString="{0:N0}%"/>
FormatString="{0:N0}%">
<FooterTemplate>
<b>∼@AvgSurvivalRate.ToString("N0")%</b>
</FooterTemplate>
</RadzenDataGridColumn>
<RadzenDataGridColumn TItem="ITank" Property="LastBattleTime"
Filterable="false"
Sortable="true"
@@ -108,18 +184,3 @@
SortOrder="SortOrder.Descending"/>
</Columns>
</RadzenDataGrid>
@code {
[Parameter]
public IEnumerable<ITank> TanksList { get; set; }
void ShowTooltip(ElementReference elementReference, string message, TooltipOptions options = null) => TooltipService.Open(elementReference, message, options);
void OnChange()
{
// Filter - dropdown with multiselect
// https://blazor.radzen.com/datagrid-filter-template
// TanksList = TanksList.Where(e => currentTOC >= 0 ? e.TitleOfCourtesy == currentTOC : true);
}
}
@@ -0,0 +1,149 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization;
using Radzen;
using Radzen.Blazor;
using WotBlitzStatisticsPro.Blazor.GraphQl;
using WotBlitzStatisticsPro.Blazor.Helpers;
using WotBlitzStatisticsPro.Blazor.Model;
namespace WotBlitzStatisticsPro.Blazor.Pages
{
public class PlayerInfoTanksListBase: ComponentBase
{
[Parameter]
public IEnumerable<ITank> TanksList { get; set; }
[Inject]
public TooltipService TooltipService { get; set; }
[Inject]
public IStringLocalizer<App> Localize { get; set; }
public RadzenDataGrid<ITank> TanksGrid { get; set; }
public IEnumerable<ITank> FilteredTankList { get; set; }
public List<FilterItem<int>> TierFilter { get; set; } = new();
public IEnumerable<int> FilteredTiers { get; set; } = new int[] { };
public List<FilterItem<string>> TankTypesFilter { get; set; } = new();
public IEnumerable<string> FilteredTankTypes { get; set; } = new string[] { };
public bool? FilterIsPremium { get; set; } = null;
public List<FilterItem<string>> NationsFilter { get; set; } = new();
public IEnumerable<string> FilteredNations { get; set; } = new string[] { };
public List<FilterItem<MarkOfMastery>> MasteryFilter { get; set; } = new();
public IEnumerable<MarkOfMastery> FilteredMastery { get; set; } = new MarkOfMastery[] { };
public int TotalBattles { get; set; }
public int AvgWinRate { get; set; }
public double AvgWn7 { get; set; }
public int AvgTotalDamage { get; set; }
public int AvgTotalXp { get; set; }
public int AvgSurvivalRate { get; set; }
public int? MinBattles { get; set; } = null;
protected override void OnInitialized()
{
FilteredTankList = TanksList;
CountTotalParams();
for (int i = 1; i < 11; i++)
{
TierFilter.Add(new FilterItem<int>(i, i.RomanNumber()));
}
FillTankTypesFilter();
FillNationsFilter();
FillMasteryFilter();
}
public void ShowTooltip(ElementReference elementReference, string message, TooltipOptions options = null) => TooltipService.Open(elementReference, message, options);
public void OnFilterChange(object value)
{
FilteredTankList = TanksList;
if (FilteredTiers.Any())
{
FilteredTankList = FilteredTankList.Where(t => FilteredTiers.Contains(t.Tier));
}
if (FilteredTankTypes.Any())
{
FilteredTankList = FilteredTankList.Where(t => FilteredTankTypes.Contains(t.TankTypeId));
}
if (FilterIsPremium.HasValue)
{
FilteredTankList = FilteredTankList.Where(t => t.IsPremium == FilterIsPremium.Value);
}
if (FilteredNations.Any())
{
FilteredTankList = FilteredTankList.Where(t => FilteredNations.Contains(t.TankNationId));
}
if (FilteredMastery.Any())
{
FilteredTankList = FilteredTankList.Where(t => FilteredMastery.Contains(t.MarkOfMastery));
}
if (MinBattles.HasValue)
{
FilteredTankList = FilteredTankList.Where(t => t.Battles > MinBattles.Value);
}
CountTotalParams();
}
private void FillTankTypesFilter()
{
// ToDo: Should get values from Dictionary here instead of hard code
TankTypesFilter.Add(new FilterItem<string>(Constants.HeavyTank, Constants.HeavyTank.TankTypeAsset(false)));
TankTypesFilter.Add(new FilterItem<string>(Constants.AtSpg, Constants.AtSpg.TankTypeAsset(false)));
TankTypesFilter.Add(new FilterItem<string>(Constants.MediumTank, Constants.MediumTank.TankTypeAsset(false)));
TankTypesFilter.Add(new FilterItem<string>(Constants.LightTank, Constants.LightTank.TankTypeAsset(false)));
}
private void FillNationsFilter()
{
// ToDo: Should get values from Dictionary here instead of hard code
NationsFilter.Add(new FilterItem<string>(Constants.CountryUsa, Constants.CountryUsa.NationAsset()));
NationsFilter.Add(new FilterItem<string>(Constants.CountryFrance, Constants.CountryFrance.NationAsset()));
NationsFilter.Add(new FilterItem<string>(Constants.CountryUssr, Constants.CountryUssr.NationAsset()));
NationsFilter.Add(new FilterItem<string>(Constants.CountryChina, Constants.CountryChina.NationAsset()));
NationsFilter.Add(new FilterItem<string>(Constants.CountryUk, Constants.CountryUk.NationAsset()));
NationsFilter.Add(new FilterItem<string>(Constants.CountryJapan, Constants.CountryJapan.NationAsset()));
NationsFilter.Add(new FilterItem<string>(Constants.CountryGermany, Constants.CountryGermany.NationAsset()));
NationsFilter.Add(new FilterItem<string>(Constants.CountryOther, Constants.CountryOther.NationAsset()));
NationsFilter.Add(new FilterItem<string>(Constants.CountryEuropean, Constants.CountryEuropean.NationAsset()));
}
private void FillMasteryFilter()
{
foreach (MarkOfMastery mastery in Enum.GetValues(typeof(MarkOfMastery)))
{
MasteryFilter.Add(new FilterItem<MarkOfMastery>(mastery, mastery.IconAsset()));
}
}
private void CountTotalParams()
{
TotalBattles = Convert.ToInt32(FilteredTankList.Sum(t => t.Battles));
if (TotalBattles > 0)
{
AvgWinRate = Convert.ToInt32(100 * FilteredTankList.Sum(t => t.Wins) / TotalBattles);
AvgWn7 = Convert.ToDouble(FilteredTankList.Sum(t => t.Wn7)) / FilteredTankList.Count();
AvgTotalDamage = Convert.ToInt32(FilteredTankList.Sum(t => t.DamageDealt) / TotalBattles);
AvgTotalXp = Convert.ToInt32(FilteredTankList.Sum(t => t.Xp) / TotalBattles);
AvgSurvivalRate = Convert.ToInt32(100 * FilteredTankList.Sum(t => t.WinAndSurvived) / TotalBattles);
}
else
{
AvgWinRate = 0;
AvgWn7 = 0;
AvgTotalDamage = 0;
AvgTotalXp = 0;
AvgSurvivalRate = 0;
}
}
}
}
@@ -132,6 +132,18 @@
<data name="days ago" xml:space="preserve">
<value>vor Tagen</value>
</data>
<data name="Filter mark of mastery..." xml:space="preserve">
<value>Meisterschaftfilter...</value>
</data>
<data name="Filter nations..." xml:space="preserve">
<value>Nationfilter...</value>
</data>
<data name="Filter tank types..." xml:space="preserve">
<value>Panzertypenfilter...</value>
</data>
<data name="Filter tier..." xml:space="preserve">
<value>Rangfilter...</value>
</data>
<data name="Home" xml:space="preserve">
<value>Startseite</value>
</data>
@@ -150,12 +162,21 @@
<data name="Members" xml:space="preserve">
<value>Mitglieder</value>
</data>
<data name="Min battles" xml:space="preserve">
<value>Min Schlachten</value>
</data>
<data name="minutes ago" xml:space="preserve">
<value>vor Minuten</value>
</data>
<data name="months ago" xml:space="preserve">
<value>vor Monaten</value>
</data>
<data name="of" xml:space="preserve">
<value>von</value>
</data>
<data name="Premium tanks" xml:space="preserve">
<value>Prämiepanzern</value>
</data>
<data name="Region" xml:space="preserve">
<value>Region</value>
</data>
@@ -171,6 +192,9 @@
<data name="Tank" xml:space="preserve">
<value>Panzer</value>
</data>
<data name="Tanks" xml:space="preserve">
<value>Panzern</value>
</data>
<data name="Welcome to WOT Blitz statistics application!" xml:space="preserve">
<value>Willkommen bei der WOT Blitz statistics!</value>
</data>
@@ -132,6 +132,18 @@
<data name="days ago" xml:space="preserve">
<value>дней назад</value>
</data>
<data name="Filter mark of mastery..." xml:space="preserve">
<value>Фильтр по знаку мастер...</value>
</data>
<data name="Filter nations..." xml:space="preserve">
<value>Фильтр по нациям...</value>
</data>
<data name="Filter tank types..." xml:space="preserve">
<value>Фильтр по типу танка...</value>
</data>
<data name="Filter tier..." xml:space="preserve">
<value>Фильтр по уровню...</value>
</data>
<data name="Home" xml:space="preserve">
<value>На главную</value>
</data>
@@ -150,12 +162,21 @@
<data name="Members" xml:space="preserve">
<value>Участников</value>
</data>
<data name="Min battles" xml:space="preserve">
<value>Мин боёв</value>
</data>
<data name="minutes ago" xml:space="preserve">
<value>минут назад</value>
</data>
<data name="months ago" xml:space="preserve">
<value>месяцев назад</value>
</data>
<data name="of" xml:space="preserve">
<value>из</value>
</data>
<data name="Premium tanks" xml:space="preserve">
<value>Премиум танки</value>
</data>
<data name="Region" xml:space="preserve">
<value>Регион</value>
</data>
@@ -171,6 +192,9 @@
<data name="Tank" xml:space="preserve">
<value>Танк</value>
</data>
<data name="Tanks" xml:space="preserve">
<value>Танков</value>
</data>
<data name="Welcome to WOT Blitz statistics application!" xml:space="preserve">
<value>Добро пожаловать в WOT Blitz statistics!</value>
</data>