diff --git a/backend/postings/models.py b/backend/postings/models.py index f6ca417..69af1a2 100644 --- a/backend/postings/models.py +++ b/backend/postings/models.py @@ -40,12 +40,27 @@ class RateableEntity(models.Model): return None return rating_sum / reviews.count() - # Gets a 5-item list of the count of each rating. + # Gets a 5-item list of the count of each rating, and the percentage of total votes. def getRatingDistribution(self): reviews = self.review_set.select_related() - distribution = [0, 0, 0, 0, 0] + distribution = [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0]] + review_count = len(reviews) + for review in reviews: - distribution[review.rating-1] += 1 + distribution[review.rating-1][0] += 1 + + max_val = 0 + for rating_dist in distribution: + rating_dist[1] = (rating_dist[0] / review_count) * 100 + if (rating_dist[1] > max_val): + max_val = rating_dist[1] + + print(max_val) + print(distribution) + for rating_dist in distribution: + rating_dist[1] = (rating_dist[1] / max_val) * 100 + + print(distribution) return distribution # Simply returns the name as the string representation. diff --git a/backend/postings/templates/postings/frontend/entity.html b/backend/postings/templates/postings/frontend/entity.html index 7eb64a0..3977c31 100644 --- a/backend/postings/templates/postings/frontend/entity.html +++ b/backend/postings/templates/postings/frontend/entity.html @@ -25,18 +25,6 @@ {# Rating Distribution Display #} - - - -