From 7ec85e78b0a1fb7b6a1ab87298c57db53f2b1246 Mon Sep 17 00:00:00 2001 From: "Jill \"oatmealine\" Monoids" Date: Sat, 7 Jan 2023 19:55:19 +0300 Subject: [PATCH] cap community difficulties to 2-9 stars --- src/endpoints/levels/rateLevel.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/endpoints/levels/rateLevel.cr b/src/endpoints/levels/rateLevel.cr index ec441e8..eb8c06c 100644 --- a/src/endpoints/levels/rateLevel.cr +++ b/src/endpoints/levels/rateLevel.cr @@ -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)