Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
33 lines (28 sloc) 1.24 KB
from import BaseCommand
from vote import models, views, render_content
class Command(BaseCommand):
help = '''
Find pairs of parties that tend to be at first and second place together.
Based on users' shared results / "wisdom of the crowd".
def handle(self, *args, **options):
count_of_pair = {}
for publish in models.Publish.objects.all():
user_answers, vote_ids = views.parse_publish_votes_str(
votes = {}
for vote in models.Vote.objects.filter(id__in=tuple(vote_ids)):
vote = views.export_vote(vote)
votes[vote['id']] = vote
(results, _unused) = render_content.calc_results(
votes, user_answers)
top_two_parties = tuple(sorted(
party_name for pos, party_name, score in
count_of_pair[top_two_parties] = 1 + count_of_pair.get(
top_two_parties, 0)
def key(item):
key, val = item
return -val
for (a, b), count in sorted(count_of_pair.items(), key=key)[:50]:
print('%s vs %s: %d' % (a, b, count))