Al/small updates #17

Closed
andrewlalis wants to merge 14 commits from al/small_updates into master
1 changed files with 9 additions and 11 deletions
Showing only changes of commit ef24a303e3 - Show all commits

View File

@ -44,23 +44,21 @@ class RateableEntity(models.Model):
def getRatingDistribution(self): def getRatingDistribution(self):
reviews = self.review_set.select_related() reviews = self.review_set.select_related()
distribution = [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0]] distribution = [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]
review_count = len(reviews) review_count = reviews.count()
for review in reviews: for review in reviews:
distribution[review.rating-1][0] += 1 distribution[review.rating-1][0] += 1
max_val = 0 if (review_count > 0):
for rating_dist in distribution: max_val = 0
rating_dist[1] = (rating_dist[0] / review_count) * 100 for rating_dist in distribution:
if (rating_dist[1] > max_val): rating_dist[1] = (rating_dist[0] / review_count) * 100
max_val = rating_dist[1] if (rating_dist[1] > max_val):
max_val = rating_dist[1]
print(max_val) for rating_dist in distribution:
print(distribution) rating_dist[1] = (rating_dist[1] / max_val) * 100
for rating_dist in distribution:
rating_dist[1] = (rating_dist[1] / max_val) * 100
print(distribution)
return distribution return distribution
# Simply returns the name as the string representation. # Simply returns the name as the string representation.