Skip to content

Commit

Permalink
Optimise bin selection in difficulty calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamQiufeng committed Aug 17, 2024
1 parent 86f6f90 commit 562e412
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -556,12 +556,22 @@ private float CalculateOverallDifficulty()
var mapStart = StrainSolverData.Min(s => s.StartTime);
var mapEnd = StrainSolverData.Max(s => Math.Max(s.StartTime, s.EndTime));

var l = 0;
var r = 0;
while (l < StrainSolverData.Count && StrainSolverData[l].StartTime < mapStart)
l++;
for (var i = mapStart; i < mapEnd; i += binSize)
{
var valuesInBin = StrainSolverData.Where(s => s.StartTime >= i && s.StartTime < i + binSize).ToList();
while (r < StrainSolverData.Count - 1 && StrainSolverData[r + 1].StartTime < i + binSize)
r++;
if (l >= StrainSolverData.Count)
break;

var valuesInBin = StrainSolverData.GetRange(l, r - l + 1);
var averageRating = valuesInBin.Count > 0 ? valuesInBin.Average(s => s.TotalStrainValue) : 0;

bins.Add(averageRating);
l = r + 1;
}

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

0 comments on commit 562e412

Please sign in to comment.