This commit is contained in:
Ross
2025-12-06 23:11:17 +00:00
parent e541e4cc31
commit 6bbc281a9b
6 changed files with 118 additions and 27 deletions
+10 -2
View File
@@ -102,9 +102,17 @@ class Dinosaur(models.Model):
"""Convert a 0-100 percent into a 0-5 star score in 0.5 increments."""
if percent is None:
return 0.0
val = float(percent) * 0.05 # scale 0-100 -> 0-5
pct = float(percent)
# scale 0-100 -> 0-5
val = pct * 0.05
# round to nearest 0.5
return round(val * 2) / 2.0
rounded = round(val * 2) / 2.0
# Avoid promoting near-100 values to 5.0 via rounding. Only an
# exact 100% should map to a full 5.0. Anything less will be
# capped at 4.5 to keep 5-star visually reserved for true maxima.
if pct >= 100.0:
return 5.0
return min(rounded, 4.5)
def _stars_string(self, percent):
"""Return a simple star string like '★★★★½' and trailing empty stars ''."""