mirror of
https://github.com/DrMboga/WotBlitzStatisticsBlazor.git
synced 2026-10-23 19:30:06 +02:00
chore: fixed the relevant tank finding algorithm
This commit is contained in:
1 parent
d3e1e52e19
commit
644a841709
2 files changed
+83
-2
No files matched your search
@@ -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<ITank> 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -53,7 +53,7 @@
|
|||||||
<TankCard Tank=@MaxXpTank></TankCard>
|
<TankCard Tank=@MaxXpTank></TankCard>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-3 col-lg-3 align-items-center d-flex">
|
<div class="col-md-3 col-lg-3 align-items-center d-flex">
|
||||||
<div style="width: 100px; margin: 3px;">
|
<div style="width: 100px; margin: 3px;">
|
||||||
@Localize["Tank with Max frags"] (@AccountInfo.MaxFrags):
|
@Localize["Tank with Max frags"] (@AccountInfo.MaxFrags):
|
||||||
</div>
|
</div>
|
||||||
@@ -76,7 +76,7 @@
|
|||||||
|
|
||||||
protected override void OnInitialized()
|
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);
|
MaxXpTank = AccountInfo?.Tanks?.FirstOrDefault(t => t.TankId == AccountInfo.MaxXpTankId);
|
||||||
MaxFragsTank = AccountInfo?.Tanks?.FirstOrDefault(t => t.TankId == AccountInfo.MaxFragsTankId);
|
MaxFragsTank = AccountInfo?.Tanks?.FirstOrDefault(t => t.TankId == AccountInfo.MaxFragsTankId);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user