Skip to content

Commit

Permalink
Boost games towards a 1.0 multiplier before boosting the average game…
Browse files Browse the repository at this point in the history
… above 1.0
  • Loading branch information
timoschwarzer committed Jul 7, 2024
1 parent f9b0972 commit 1c4bc4c
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/main/kotlin/wotw/server/database/model/LeagueSeason.kt
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,33 @@ class LeagueSeason(id: EntityID<Long>) : LongEntity(id) {
additionalPartsDiscarded += partToActuallyDiscardAdditionally
}

// Pass 3: If we discarded additional parts (outliers), compensate them by boosting games around the average
submissions.minByOrNull { abs(it.points - averagePoints) }?.let { gameNearestToAverage ->
if (gameNearestToAverage.points <= 0) {
// Pass 3: If we discarded additional parts (outliers), boost previously discarded games towards 1
var pointsToBoostLeft = (averagePoints * additionalPartsDiscarded).toInt()
submissions.reversed().forEach { submission ->
if (submission.rankingMultiplier >= 1.0f || submission.points == 0) {
return@forEach
}

val pointsAvailableToBoostForThisGame = submission.points - (submission.points * submission.rankingMultiplier).toInt()

if (pointsAvailableToBoostForThisGame <= pointsToBoostLeft) {
submission.rankingMultiplier = 1.0f
pointsToBoostLeft -= pointsAvailableToBoostForThisGame
} else {
val additionalMultiplier = pointsToBoostLeft / submission.points
submission.rankingMultiplier += additionalMultiplier.toFloat()
pointsToBoostLeft = 0
}
}

// Pass 4: Compensate the rest by boosting the game nearest to the average
submissions.minByOrNull { abs(it.points - averagePoints) }?.let { submissionNearestToAverage ->
if (submissionNearestToAverage.points <= 0) {
return@let
}

val pointsToBoost = averagePoints * additionalPartsDiscarded
val additionalMultiplier = pointsToBoost / gameNearestToAverage.points
gameNearestToAverage.rankingMultiplier += additionalMultiplier.toFloat()
val additionalMultiplier = pointsToBoostLeft / submissionNearestToAverage.points
submissionNearestToAverage.rankingMultiplier += additionalMultiplier.toFloat()
}

// Pass 4: Round multipliers to 2 decimal places
Expand Down

0 comments on commit 1c4bc4c

Please sign in to comment.