File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -314,8 +314,13 @@ class InMemoryPackageIndex {
314314 final downloadScore = doc.downloadScore ?? 0.0 ;
315315 final likeScore = doc.likeScore ?? 0.0 ;
316316 final popularityScore = (downloadScore + likeScore) / 2 ;
317- final pointScore =
318- math.sqrt (doc.grantedPoints / math.max (1 , doc.maxPoints));
317+
318+ // prevent division by zero in case maxPoints is zero
319+ final pointRatio = doc.grantedPoints / math.max (1 , doc.maxPoints);
320+ // force value between 0.0 and 1.0 in case we have bad points
321+ // using square root to lower the differences between higher values
322+ final pointScore = math.sqrt (math.max (0.0 , math.min (1.0 , pointRatio)));
323+
319324 final overall = popularityScore * 0.5 + pointScore * 0.5 ;
320325 doc.overallScore = overall;
321326 // adding a base score prevents later multiplication with zero
You can’t perform that action at this time.
0 commit comments