Skip to content

Commit

Permalink
Merge pull request #179 from WilliamQiufeng/optimise-diffcalc-bin
Browse files Browse the repository at this point in the history
Optimise bin selection in difficulty calculation
  • Loading branch information
Warp9000 authored Aug 19, 2024
2 parents 5f4c01d + d313626 commit 05ab6e2
Showing 1 changed file with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -560,12 +560,37 @@ private float CalculateOverallDifficulty()
var mapStart = StrainSolverData.Min(s => s.StartTime);
var mapEnd = StrainSolverData.Max(s => Math.Max(s.StartTime, s.EndTime));

var leftIndex = 0;
var rightIndex = 0;
var useFallback = Map.GetKeyCount(false) % 2 == 1;
while (leftIndex < StrainSolverData.Count && StrainSolverData[leftIndex].StartTime < mapStart)
leftIndex++;
for (var i = mapStart; i < mapEnd; i += binSize)
{
var valuesInBin = StrainSolverData.Where(s => s.StartTime >= i && s.StartTime < i + binSize).ToList();
List<StrainSolverData> valuesInBin;
if (useFallback)
{
valuesInBin = StrainSolverData.Where(s => s.StartTime >= i && s.StartTime < i + binSize)
.ToList();
}
else
{
while (rightIndex < StrainSolverData.Count - 1 && StrainSolverData[rightIndex + 1].StartTime < i + binSize)
rightIndex++;

if (leftIndex >= StrainSolverData.Count)
{
bins.Add(0);
continue;
}

valuesInBin = StrainSolverData.GetRange(leftIndex, rightIndex - leftIndex + 1);
}

var averageRating = valuesInBin.Count > 0 ? valuesInBin.Average(s => s.TotalStrainValue) : 0;

bins.Add(averageRating);
leftIndex = rightIndex + 1;
}

if (!bins.Any(strain => strain > 0)) return 0;
Expand Down

0 comments on commit 05ab6e2

Please sign in to comment.