Skip to content

Instantly share code, notes, and snippets.

@blole
Last active May 16, 2016 15:49
Show Gist options
  • Save blole/3f689b3425ecd05bd142842f7caeacac to your computer and use it in GitHub Desktop.
Save blole/3f689b3425ecd05bd142842f7caeacac to your computer and use it in GitHub Desktop.
Schulze non-proportional ordering of the Eurovision 2016 final results
#!/usr/bin/env python2
#
# Schulze non-proportional ordering of the Eurovision 2016 final results.
# data from http://eurovisionworld.com/?eurovision=2016
from pyvotecore.schulze_npr import SchulzeNPR
def transpose(matrix):
return map(list, zip(*matrix))
countries = [
'Ukraine', 'Australia', 'Russia', 'Bulgaria', 'Sweden', 'France',
'Armenia', 'Poland', 'Lithuania', 'Belgium', 'Netherlands', 'Malta',
'Austria', 'Israel', 'Latvia', 'Italy', 'Azerbaijan', 'Serbia',
'Hungary', 'Georgia', 'Cyprus', 'Spain', 'Croatia',
'United Kingdom', 'Czech Republic', 'Germany'
]
jury = [
[0, 0, 2, 0, 10, 7, 3, 12, 0, 0, 0, 0, 12, 7, 0, 0, 12, 12, 7, 2, 0, 0, 0, 12, 10, 12, 8, 0, 12, 0, 3, 4, 12, 0, 12, 12, 12, 0, 0, 6, 0, 10],
[12,5, 0, 12, 7, 6, 12, 10, 8, 12, 10, 0, 10, 10, 8, 6, 8, 8, 6, 7, 12, 10, 0, 10, 6, 5, 12, 3, 10, 4, 12, 10, 10, 2, 0, 6, 6, 8, 12, 12, 5, 8 ],
[7, 2, 0, 3, 12, 12, 0, 5, 6, 6, 12, 0, 0, 0, 0, 1, 0, 0, 0, 12, 0, 8, 0, 0, 0, 7, 0, 4, 7, 8, 0, 0, 0, 0, 7, 1, 0, 4, 6, 0, 0, 0 ],
[4, 7, 8, 0, 8, 1, 6, 3, 0, 0, 0, 0, 6, 0, 0, 10, 10, 0, 0, 0, 0, 0, 10, 7, 0, 1, 2, 10, 0, 2, 0, 8, 3, 0, 0, 4, 10, 0, 0, 1, 1, 5 ],
[0, 0, 0, 8, 0, 8, 0, 0, 0, 0, 0, 12, 4,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0, 0 ]
]
# schulze ordering
ballots = []
for voter in transpose(jury) + transpose(tele):
rating = {countries[i]: rate for (i, rate) in sorted(enumerate(voter), key=lambda (i, rate): rate) if rate > 0}
ballots.append({'ballot': rating})
schulze = SchulzeNPR(ballots, ballot_notation="rating").as_dict()['order']
# the ordinary ordering for 2016
esc = [x[1] for x in sorted(zip([sum(row1)+sum(row2) for (row1,row2) in zip(jury,tele)], countries), reverse=True)]
print '# SchulzeNPR ESC2016 diff'
for (i, (s, e)) in enumerate(zip(schulze, esc)):
print '%2d. %-14s %-14s%s' % (i+1, s, e, ' *'*(s!=e))
@blole
Copy link
Author

blole commented May 16, 2016

output

#   SchulzeNPR     ESC2016         diff
 1. Russia         Ukraine        *
 2. Ukraine        Australia      *
 3. Australia      Russia         *
 4. Bulgaria       Bulgaria      
 5. Sweden         Sweden        
 6. France         France        
 7. Armenia        Armenia       
 8. Lithuania      Poland         *
 9. Poland         Lithuania      *
10. Austria        Belgium        *
11. Malta          Netherlands    *
12. Belgium        Malta          *
13. Israel         Austria        *
14. Hungary        Israel         *
15. Netherlands    Latvia         *
16. Latvia         Italy          *
17. Italy          Azerbaijan     *
18. Azerbaijan     Serbia         *
19. Spain          Hungary        *
20. Georgia        Georgia       
21. Cyprus         Cyprus        
22. Serbia         Spain          *
23. Croatia        Croatia       
24. United Kingdom United Kingdom
25. Czech Republic Czech Republic
26. Germany        Germany       

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment