Created
November 30, 2011 00:29
-
-
Save cooncesean/1407334 to your computer and use it in GitHub Desktop.
Find the total number of EditorialReviews by platform and the average score given per platform/developer.
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
developers = {} | |
for er in EditorialReview.objects.all(): | |
print er | |
for dtg in er.game.developers.all(): | |
if dtg.company.name in developers: | |
_dict = developers[dtg.company.name] | |
_dict['total_reviews'] += 1 | |
_dict['total_review_score'] += er.score | |
_dict['avg_review_score'] = '%.1f' % (float(_dict['total_review_score']) / float(_dict['total_reviews'])) | |
else: | |
developers.update({ | |
dtg.company.name:{ | |
'total_reviews': 1, | |
'total_review_score':er.score, | |
'avg_review_score': er.score | |
} | |
}) | |
print developers |
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
platforms = {} | |
for er in EditorialReview.objects.all(): | |
print er | |
for platform in er.platforms.all(): | |
if platform.name in platforms: | |
platform_dict = platforms[platform.name] | |
platform_dict['total_reviews'] += 1 | |
platform_dict['total_review_score'] += er.score | |
platform_dict['avg_review_score'] = '%.1f' % (float(platform_dict['total_review_score']) / float(platform_dict['total_reviews'])) | |
else: | |
platforms.update({ | |
platform.name:{ | |
'total_reviews': 1, | |
'total_review_score':er.score, | |
'avg_review_score': er.score | |
} | |
}) | |
print platforms |
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
platforms = {} | |
for er in EditorialReview.objects.all(): | |
print er | |
for platform in er.platforms.all(): | |
if platform.name in platforms: | |
platform_dict = platforms[platform.name] | |
platform_dict['total_reviews'] += 1 | |
platform_dict['total_review_score'] += er.score | |
platform_dict['avg_review_score'] = '%.1f' % (float(platform_dict['total_review_score']) / float(platform_dict['total_reviews'])) | |
else: | |
platforms.update({ | |
platform.name:{ | |
'total_reviews': 1, | |
'total_review_score':er.score, | |
'avg_review_score': er.score | |
} | |
}) | |
print platforms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can I use setdefault() to either speed this up?