Skip to content

Commit 98e9e47

Browse files
committed
Fix infinity CR being applied to specific levels
1 parent 1e7c0f8 commit 98e9e47

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

Refresh.Interfaces.Workers/Repeating/CoolLevelsJob.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,15 @@ private static float CalculatePositiveScore(GameLevel level, WorkContext context
147147

148148
// Reward for a good ratio between plays and yays.
149149
// Doesn't apply to LBP1 levels.
150-
float ratingRatio = (positiveRatings - negativeRatings) / (float)uniquePlays;
151-
if (ratingRatio > 0.5f && level.GameVersion != TokenGame.LittleBigPlanet1)
150+
// Skip this reward entirely if the level has no unique plays, as division by 0.0 floats
151+
// results in infinity values, which should never happen and will also screw with API clients.
152+
if (uniquePlays > 0)
152153
{
153-
score += positiveRatings * (positiveRatingPoints * ratingRatio);
154+
float ratingRatio = (positiveRatings - negativeRatings) / (float)uniquePlays;
155+
if (ratingRatio > 0.5f && level.GameVersion != TokenGame.LittleBigPlanet1)
156+
{
157+
score += positiveRatings * (positiveRatingPoints * ratingRatio);
158+
}
154159
}
155160

156161
if (level.Publisher?.Role == GameUserRole.Trusted)

0 commit comments

Comments
 (0)