cap community difficulties to 2-9 stars

This commit is contained in:
Jill 2023-01-07 19:55:19 +03:00
parent 9241e0b24c
commit 7ec85e78b0
1 changed files with 1 additions and 1 deletions

View File

@ -33,7 +33,7 @@ CrystalGauntlet.endpoints["/rateGJStars211.php"] = ->(context : HTTP::Server::Co
# todo: cache in some form?
votes = DATABASE.query_all("select stars from difficulty_votes where level_id = ?", level_id, as: {Int32})
avg = votes.sum() / votes.size
difficulty = stars_to_difficulty(Int32.new(avg.round()))
difficulty = stars_to_difficulty(Int32.new(avg.round()).clamp(2..9))
if difficulty
DATABASE.exec("update levels set community_difficulty = ? where id = ?", difficulty.value, level_id)