Created
December 21, 2017 22:49
-
-
Save bmease/3429b9ed4955db43f891c6ceabd4204a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pct_breakdown(self, grouping): | |
# provide the grouping and this function will return the percent upvoted for each group | |
rating_breakdown = {} | |
groups = IdeaInteraction.objects.filter(idea=self.pk).values(grouping) | |
for item in groups: | |
for key, value in item.items(): | |
upvotes = IdeaInteraction.objects.filter(idea=self.pk, vote='up-vote', **{key: value}).count() | |
downvotes = IdeaInteraction.objects.filter(idea=self.pk, vote='down-vote', **{key: value}).count() | |
rating = (upvotes / (upvotes + downvotes)) * 100 | |
rating_breakdown[value] = rating | |
return rating_breakdown | |
def pct_breakdown(self, grouping): | |
# declare variables | |
rating_breakdown = {} | |
groups = IdeaInteraction.objects.filter(idea=self.pk).values(grouping) | |
# do your work | |
for item in groups: | |
for key, value in item.items(): | |
# grab some data | |
upvotes = IdeaInteraction.objects.filter(idea=self.pk, vote='up-vote', **{key: value}).count() | |
downvotes = IdeaInteraction.objects.filter(idea=self.pk, vote='down-vote', **{key: value}).count() | |
# do some work | |
rating = (upvotes / (upvotes + downvotes)) * 100 | |
rating_breakdown[value] = rating | |
# return results | |
return rating_breakdown |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment