diff --git a/WotBlitzStatisticsPro.Blazor/Helpers/DateDifferenceHelper.cs b/WotBlitzStatisticsPro.Blazor/Helpers/DateDifferenceHelper.cs index 639c02f..d8898c0 100644 --- a/WotBlitzStatisticsPro.Blazor/Helpers/DateDifferenceHelper.cs +++ b/WotBlitzStatisticsPro.Blazor/Helpers/DateDifferenceHelper.cs @@ -6,6 +6,12 @@ namespace WotBlitzStatisticsPro.Blazor.Helpers { public static class DateDifferenceHelper { + public static DateTime ConvertToLocalTime(this DateTimeOffset dateToConvert) + { + var specifiedTimeConvert = DateTime.SpecifyKind(dateToConvert.DateTime, DateTimeKind.Utc); + return specifiedTimeConvert.ToLocalTime(); + } + public static string SinceTime(this int timeInLinuxTimeStamp, IStringLocalizer localizer) { var currentDate = DateTime.Now; @@ -25,6 +31,11 @@ namespace WotBlitzStatisticsPro.Blazor.Helpers } public static string SinceTime(this DateTimeOffset time, IStringLocalizer localizer) + { + return time.DateTime.SinceTime(localizer); + } + + public static string SinceTime(this DateTime time, IStringLocalizer localizer) { var currentDate = DateTime.Now; @@ -41,6 +52,7 @@ namespace WotBlitzStatisticsPro.Blazor.Helpers return $"{difference.value} {ago}"; } + public static (int value, TimeInterval interval) ParseTheDifference(TimeSpan difference) { if (difference.TotalHours < 1) diff --git a/WotBlitzStatisticsPro.Blazor/Helpers/TanksHelper.cs b/WotBlitzStatisticsPro.Blazor/Helpers/TanksHelper.cs new file mode 100644 index 0000000..c16cca6 --- /dev/null +++ b/WotBlitzStatisticsPro.Blazor/Helpers/TanksHelper.cs @@ -0,0 +1,81 @@ +using System.Collections.Generic; +using System.Linq; +using System.Text; +using WotBlitzStatisticsPro.Blazor.GraphQl; + +namespace WotBlitzStatisticsPro.Blazor.Helpers +{ + public static class TanksHelper + { + public static ITank FindMostRelevantTank(this IReadOnlyList allTanks) + { + const int topTanksToMerge = 6; + if (allTanks.Count == 1) + { + return allTanks.First(); + } + + // Merge 6 tanks with max battles with 6 tanks with max Wn7, then with 6 tanks with max AvgDamage then with 6 tanks with Max Win rate. And sort result by max AvgXp and take first + + var topByBattles = allTanks + .OrderByDescending(t => t.Battles) + .Take(topTanksToMerge) + .Select(t => t.TankId) + .ToList(); + var topByWn7 = allTanks + .Where(t => topByBattles.Contains(t.TankId)) + .OrderByDescending(t => t.Wn7) + .Take(topTanksToMerge) + .Select(t => t.TankId) + .ToList(); + var topByDamage = allTanks + .Where(t => topByBattles.Contains(t.TankId)) + .OrderByDescending(t => t.AvgDamage) + .Take(topTanksToMerge) + .Select(t => t.TankId) + .ToList(); + var topByWinRate = allTanks + .Where(t => topByBattles.Contains(t.TankId)) + .OrderByDescending(t => t.WinRate) + .Take(topTanksToMerge) + .Select(t => t.TankId) + .ToList(); + + var firstIntersection = topByBattles.Intersect(topByWn7).ToList(); + if (!firstIntersection.Any()) + { + return allTanks.First(t => t.TankId == topByBattles.First()); + } + if(firstIntersection.Count() == 1) + { + return allTanks.First(t => t.TankId == firstIntersection.First()); + } + + var secondIntersection = topByDamage.Intersect(firstIntersection).ToList(); + if (!secondIntersection.Any()) + { + return allTanks.First(t => t.TankId == firstIntersection.First()); + } + if (secondIntersection.Count() == 1) + { + return allTanks.First(t => t.TankId == secondIntersection.First()); + } + + var thirdIntersection = topByWinRate.Intersect(secondIntersection).ToList(); + if (!thirdIntersection.Any()) + { + return allTanks.First(t => t.TankId == secondIntersection.First()); + } + if (thirdIntersection.Count() == 1) + { + return allTanks.First(t => t.TankId == thirdIntersection.First()); + } + + return allTanks + .Where(t => thirdIntersection.Contains(t.TankId)) + .OrderByDescending(t => t.AvgXp) + .First(); + } + + } +} \ No newline at end of file diff --git a/WotBlitzStatisticsPro.Blazor/Pages/PlayerInfoLayout.razor b/WotBlitzStatisticsPro.Blazor/Pages/PlayerInfoLayout.razor index 81356f6..15cca5c 100644 --- a/WotBlitzStatisticsPro.Blazor/Pages/PlayerInfoLayout.razor +++ b/WotBlitzStatisticsPro.Blazor/Pages/PlayerInfoLayout.razor @@ -17,7 +17,7 @@ @Localize["Created"]: @AccountInfo.CreatedAt.ToString("d") | @AccountInfo.CreatedAt.SinceTime(Localize)
- @Localize["Last battle"]: @AccountInfo.LastBattleTime.ToString("g") | @AccountInfo.LastBattleTime.SinceTime(Localize) + @Localize["Last battle"]: @AccountInfo.LastBattleTime.ConvertToLocalTime().ToString("g") | @AccountInfo.LastBattleTime.ConvertToLocalTime().SinceTime(Localize)
@@ -29,6 +29,7 @@ + @*TODO: In case of @SmallScreen == true, then show new tanks list component - mobile version *@ diff --git a/WotBlitzStatisticsPro.Blazor/Pages/PlayerInfoLayoutBase.cs b/WotBlitzStatisticsPro.Blazor/Pages/PlayerInfoLayoutBase.cs index bc965eb..9fe4ff3 100644 --- a/WotBlitzStatisticsPro.Blazor/Pages/PlayerInfoLayoutBase.cs +++ b/WotBlitzStatisticsPro.Blazor/Pages/PlayerInfoLayoutBase.cs @@ -22,6 +22,9 @@ namespace WotBlitzStatisticsPro.Blazor.Pages [Inject] public INotificationsService Notifications { get; set; } + [Inject] + public IMediaQueriesService MediaQueriesService { get; set; } + [Parameter] public long AccountId { get; set; } @@ -32,12 +35,16 @@ namespace WotBlitzStatisticsPro.Blazor.Pages public IReadOnlyList AchievementsBySection { get; set; } + public bool SmallScreen { get; set; } + protected override async Task OnInitializedAsync() { var loggedInInfo = await LocalStorageService.GetItemAsync(Constants.LoginInfoLocalStorageKey); var settings = await LocalStorageService.ReadSettings(); CurrentRealmType = settings.RealmType; + SmallScreen = await MediaQueriesService.IsScreenWidthLessThen(1000); + try { // Maybe add refresh button instead of calling mutation each time diff --git a/WotBlitzStatisticsPro.Blazor/Pages/PlayerInfoOverview.razor b/WotBlitzStatisticsPro.Blazor/Pages/PlayerInfoOverview.razor index 5250d22..1c89bdf 100644 --- a/WotBlitzStatisticsPro.Blazor/Pages/PlayerInfoOverview.razor +++ b/WotBlitzStatisticsPro.Blazor/Pages/PlayerInfoOverview.razor @@ -53,7 +53,7 @@ } -
+
@Localize["Tank with Max frags"] (@AccountInfo.MaxFrags):
@@ -76,7 +76,7 @@ protected override void OnInitialized() { - MostRelevantTank = AccountInfo?.Tanks?.Where(t => t.Battles > 50).OrderByDescending(t => t.Wn7).FirstOrDefault(); + MostRelevantTank = AccountInfo?.Tanks?.FindMostRelevantTank(); MaxXpTank = AccountInfo?.Tanks?.FirstOrDefault(t => t.TankId == AccountInfo.MaxXpTankId); MaxFragsTank = AccountInfo?.Tanks?.FirstOrDefault(t => t.TankId == AccountInfo.MaxFragsTankId); } diff --git a/WotBlitzStatisticsPro.Blazor/Pages/PlayerInfoTanksList.razor b/WotBlitzStatisticsPro.Blazor/Pages/PlayerInfoTanksList.razor index d102d55..ec64946 100644 --- a/WotBlitzStatisticsPro.Blazor/Pages/PlayerInfoTanksList.razor +++ b/WotBlitzStatisticsPro.Blazor/Pages/PlayerInfoTanksList.razor @@ -83,7 +83,7 @@ @@ -94,7 +94,7 @@ - @TotalBattles.ToString("N0") + @TotalBattles.ToString("N0") @@ -119,8 +119,7 @@ Title="@Localize["Wn7"]" Frozen="false" Width="80px" - TextAlign="TextAlign.Center" - > + TextAlign="TextAlign.Center">