From 644a8417093437f1633f49c092fe0cc5daff8f58 Mon Sep 17 00:00:00 2001 From: Mikhail Shabanov Date: Wed, 3 Nov 2021 15:29:03 +0100 Subject: [PATCH] chore: fixed the relevant tank finding algorithm --- .../Helpers/TanksHelper.cs | 81 +++++++++++++++++++ .../Pages/PlayerInfoOverview.razor | 4 +- 2 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 WotBlitzStatisticsPro.Blazor/Helpers/TanksHelper.cs 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/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); }