mirror of
https://github.com/DrMboga/WotBlitzStatisticsBlazor.git
synced 2026-10-21 10:27:18 +02:00
feat: Search player component implemented. Plus Winrate color schale implementation
This commit is contained in:
1 parent
edfc9aa139
commit
4fb56c3b16
10 files changed
+160
-4
No files matched your search
@@ -27,6 +27,60 @@ namespace WotBlitzStatisticsPro.Blazor.Tests.Helpers
|
||||
}
|
||||
}
|
||||
|
||||
// ToDo: Write months, days, hours and minutes scenarios
|
||||
[Test]
|
||||
public void ShouldCalculateMonths()
|
||||
{
|
||||
var currentDate = new DateTime(2021, 5, 18);
|
||||
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
var initialTime = currentDate.AddMonths(-(1 + i * 2)).AddDays(-i);
|
||||
var result = DateDifferenceHelper.ParseTheDifference(currentDate - initialTime);
|
||||
result.interval.Should().Be(TimeInterval.Month, $"iterator {i}");
|
||||
result.value.Should().Be(1 + i * 2);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ShouldCalculateDays()
|
||||
{
|
||||
var currentDate = new DateTime(2021, 5, 18);
|
||||
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
var initialTime = currentDate.AddDays(-(1 + i * 2)).AddHours(-i);
|
||||
var result = DateDifferenceHelper.ParseTheDifference(currentDate - initialTime);
|
||||
result.interval.Should().Be(TimeInterval.Day, $"iterator {i}");
|
||||
result.value.Should().Be(1 + i * 2);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ShouldCalculateHours()
|
||||
{
|
||||
var currentDate = new DateTime(2021, 5, 18);
|
||||
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
var initialTime = currentDate.AddHours(-(1 + i * 2)).AddMinutes(-i);
|
||||
var result = DateDifferenceHelper.ParseTheDifference(currentDate - initialTime);
|
||||
result.interval.Should().Be(TimeInterval.Hour, $"iterator {i}");
|
||||
result.value.Should().Be(1 + i * 2);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ShouldCalculateMinutes()
|
||||
{
|
||||
var currentDate = new DateTime(2021, 5, 18);
|
||||
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
var initialTime = currentDate.AddMinutes(-(1 + i * 2)).AddSeconds(-i);
|
||||
var result = DateDifferenceHelper.ParseTheDifference(currentDate - initialTime);
|
||||
result.interval.Should().Be(TimeInterval.Minute, $"iterator {i}");
|
||||
result.value.Should().Be(1 + i * 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,5 +3,27 @@
|
||||
public class Constants
|
||||
{
|
||||
public const string ClanTagColor = "#d4d481";
|
||||
|
||||
|
||||
//public const string ScaleVeryBadColor = "#000000";
|
||||
//public const string ScaleBadColor = "#cd3333";
|
||||
//public const string ScaleBelowAverageColor = "#d77900";
|
||||
//public const string ScaleAverageColor = "#d7b600";
|
||||
//public const string ScaleGoodColor = "#6d9521";
|
||||
//public const string ScaleVeryGoodColor = "#4c762e";
|
||||
//public const string ScaleGreatColor = "#4a92b7";
|
||||
//public const string ScaleUnicumColor = "#83579d";
|
||||
//public const string ScaleSuperUnicumColor = "#5a3175";
|
||||
public const string ScaleVeryBadColor = "#a3a3a3";
|
||||
public const string ScaleBadColor = "#dc7070";
|
||||
public const string ScaleBelowAverageColor = "#ff9f25";
|
||||
public const string ScaleAverageColor = "#ffdd25";
|
||||
public const string ScaleGoodColor = "#9ad131";
|
||||
public const string ScaleVeryGoodColor = "#6fad43";
|
||||
public const string ScaleGreatColor = "#81b3cd";
|
||||
public const string ScaleUnicumColor = "#a785bb";
|
||||
public const string ScaleSuperUnicumColor = "#8348ab";
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -24,13 +24,39 @@ namespace WotBlitzStatisticsPro.Blazor.Helpers
|
||||
return $"{difference.value} {ago}";
|
||||
}
|
||||
|
||||
public static string SinceTime(this DateTimeOffset time, IStringLocalizer<App> localizer)
|
||||
{
|
||||
var currentDate = DateTime.Now;
|
||||
|
||||
var difference = ParseTheDifference(currentDate - time);
|
||||
string ago = difference.interval switch
|
||||
{
|
||||
TimeInterval.Year => localizer.GetString("years ago"),
|
||||
TimeInterval.Month => localizer.GetString("months ago"),
|
||||
TimeInterval.Day => localizer.GetString("days ago"),
|
||||
TimeInterval.Hour => localizer.GetString("hours ago"),
|
||||
TimeInterval.Minute => localizer.GetString("minutes ago")
|
||||
};
|
||||
|
||||
return $"{difference.value} {ago}";
|
||||
}
|
||||
|
||||
public static (int value, TimeInterval interval) ParseTheDifference(TimeSpan difference)
|
||||
{
|
||||
// ToDo: Check hours and mins if Days is 0
|
||||
if (difference.TotalHours < 1)
|
||||
{
|
||||
return (Convert.ToInt32(difference.TotalMinutes), TimeInterval.Minute);
|
||||
}
|
||||
|
||||
if (difference.TotalDays < 1)
|
||||
{
|
||||
return (Convert.ToInt32(difference.TotalHours), TimeInterval.Hour);
|
||||
}
|
||||
|
||||
return difference.TotalDays switch
|
||||
{
|
||||
>= 365 => (CalculateYears(difference.TotalDays), TimeInterval.Year),
|
||||
(> 30) and (< 365) => (CalculateMonths(difference.TotalDays), TimeInterval.Month),
|
||||
(>= 30) and (< 365) => (CalculateMonths(difference.TotalDays), TimeInterval.Month),
|
||||
_ => (Convert.ToInt32(difference.TotalDays), TimeInterval.Day)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
namespace WotBlitzStatisticsPro.Blazor.Helpers
|
||||
{
|
||||
public static class ScaleHelper
|
||||
{
|
||||
public static string ScaleColor(this int winRate)
|
||||
{
|
||||
return winRate switch
|
||||
{
|
||||
( > 0 ) and ( < 45) => Constants.ScaleVeryBadColor,
|
||||
( >= 45 ) and ( < 47 ) => Constants.ScaleBadColor,
|
||||
( >= 47 ) and ( < 49 ) => Constants.ScaleBelowAverageColor,
|
||||
( >= 49 ) and ( < 52 ) => Constants.ScaleAverageColor,
|
||||
( >= 52 ) and ( < 54 ) => Constants.ScaleGoodColor,
|
||||
( >= 54 ) and ( < 56 ) => Constants.ScaleVeryGoodColor,
|
||||
( >= 56 ) and ( < 60 ) => Constants.ScaleGreatColor,
|
||||
( >= 60 ) and ( < 65 ) => Constants.ScaleUnicumColor,
|
||||
_ => Constants.ScaleSuperUnicumColor
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
|
||||
@@ -1,4 +1,24 @@
|
||||
@Player.Nickname @(Player.ClanTag == null ? string.Empty : $"[{Player.ClanTag}]")
|
||||
@using WotBlitzStatisticsPro.Blazor.Helpers
|
||||
@inject IStringLocalizer<App> Localize
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
@Player.Nickname
|
||||
@if (Player.ClanTag != null)
|
||||
{
|
||||
<span style="color: @Constants.ClanTagColor;"> [<span style="font-weight: bolder;">@Player.ClanTag</span>]</span>
|
||||
}
|
||||
</div>
|
||||
<div class="row">
|
||||
<span style="font-size: 12px; color: @Player.WinRate.ScaleColor()"> <RadzenIcon Icon="flag" Style="height: 15px;" /> @Player.WinRate%</span>
|
||||
</div>
|
||||
<div class="row" title="@Localize["Battles"]">
|
||||
<span style="font-size: 12px"><RadzenIcon Icon="videogame_asset" /> @Player.BattlesCount</span>
|
||||
</div>
|
||||
<div class="row" title="@Localize["Last battle"]">
|
||||
<span style="font-size: 12px"><RadzenIcon Icon="schedule" /> @Player.LastBattle.SinceTime(Localize)</span>
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
|
||||
@@ -126,12 +126,18 @@
|
||||
<data name="Home" xml:space="preserve">
|
||||
<value>Startseite</value>
|
||||
</data>
|
||||
<data name="hours ago" xml:space="preserve">
|
||||
<value>vor Stunden</value>
|
||||
</data>
|
||||
<data name="Login with WG.net ID" xml:space="preserve">
|
||||
<value>Anmelden mit WG.net-ID</value>
|
||||
</data>
|
||||
<data name="Members" xml:space="preserve">
|
||||
<value>Mitglieder</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>
|
||||
|
||||
@@ -126,12 +126,18 @@
|
||||
<data name="Home" xml:space="preserve">
|
||||
<value>На главную</value>
|
||||
</data>
|
||||
<data name="hours ago" xml:space="preserve">
|
||||
<value>часов назад</value>
|
||||
</data>
|
||||
<data name="Login with WG.net ID" xml:space="preserve">
|
||||
<value>Войти с WG.net ID</value>
|
||||
</data>
|
||||
<data name="Members" 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>
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.9 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.7 KiB |
Reference in new issue
Block a user