You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@steve.apache.org by hu...@apache.org on 2015/03/25 01:49:06 UTC
svn commit: r1669031 - in /steve/trunk/pysteve: lib/plugins/dh.py
lib/plugins/stv.py www/htdocs/js/steve_rest.js
Author: humbedooh
Date: Wed Mar 25 00:49:05 2015
New Revision: 1669031
URL: http://svn.apache.org/r1669031
Log:
Re-factor and add some more DH/STV types, why stop at 9?!
Also, this requires some snazzy sorting, so let's do that.
Modified:
steve/trunk/pysteve/lib/plugins/dh.py
steve/trunk/pysteve/lib/plugins/stv.py
steve/trunk/pysteve/www/htdocs/js/steve_rest.js
Modified: steve/trunk/pysteve/lib/plugins/dh.py
URL: http://svn.apache.org/viewvc/steve/trunk/pysteve/lib/plugins/dh.py?rev=1669031&r1=1669030&r2=1669031&view=diff
==============================================================================
--- steve/trunk/pysteve/lib/plugins/dh.py (original)
+++ steve/trunk/pysteve/lib/plugins/dh.py Wed Mar 25 00:49:05 2015
@@ -91,68 +91,17 @@ constants.VOTE_TYPES += (
'vote_func': None,
'tally_func': tallyDH
},
- {
- 'key': "dh2",
- 'description': "D'Hondt Election with 2 seats",
- 'category': 'dh',
- 'validate_func': validateDH,
- 'vote_func': None,
- 'tally_func': tallyDH
- },
- {
- 'key': "dh3",
- 'description': "D'Hondt Election with 3 seats",
- 'category': 'dh',
- 'validate_func': validateDH,
- 'vote_func': None,
- 'tally_func': tallyDH
- },
- {
- 'key': "dh4",
- 'description': "D'Hondt Election with 4 seats",
- 'category': 'dh',
- 'validate_func': validateDH,
- 'vote_func': None,
- 'tally_func': tallyDH
- },
- {
- 'key': "dh5",
- 'description': "D'Hondt Election with 5 seats",
- 'category': 'dh',
- 'validate_func': validateDH,
- 'vote_func': None,
- 'tally_func': tallyDH
- },
- {
- 'key': "dh6",
- 'description': "D'Hondt Election with 6 seats",
- 'category': 'dh',
- 'validate_func': validateDH,
- 'vote_func': None,
- 'tally_func': tallyDH
- },
- {
- 'key': "dh7",
- 'description': "D'Hondt Election with 7 seats",
- 'category': 'dh',
- 'validate_func': validateDH,
- 'vote_func': None,
- 'tally_func': tallyDH
- },
- {
- 'key': "dh8",
- 'description': "D'Hondt Election with 8 seats",
- 'category': 'dh',
- 'validate_func': validateDH,
- 'vote_func': None,
- 'tally_func': tallyDH
- },
- {
- 'key': "dh9",
- 'description': "D'Hondt Election with 9 seats",
- 'category': 'dh',
- 'validate_func': validateDH,
- 'vote_func': None,
- 'tally_func': tallyDH
- }
-)
\ No newline at end of file
+)
+
+# Add ad nauseam
+for i in range(2,21):
+ constants.VOTE_TYPES += (
+ {
+ 'key': "dh%u" % i,
+ 'description': "D'Hondt Election with %u seats" % i,
+ 'category': 'dh',
+ 'validate_func': validateDH,
+ 'vote_func': None,
+ 'tally_func': tallyDH
+ },
+ )
\ No newline at end of file
Modified: steve/trunk/pysteve/lib/plugins/stv.py
URL: http://svn.apache.org/viewvc/steve/trunk/pysteve/lib/plugins/stv.py?rev=1669031&r1=1669030&r2=1669031&view=diff
==============================================================================
--- steve/trunk/pysteve/lib/plugins/stv.py (original)
+++ steve/trunk/pysteve/lib/plugins/stv.py Wed Mar 25 00:49:05 2015
@@ -176,68 +176,17 @@ constants.VOTE_TYPES += (
'vote_func': None,
'tally_func': tallySTV
},
- {
- 'key': "stv2",
- 'description': "Single Transferrable Vote with 2 seats",
- 'category': 'stv',
- 'validate_func': validateSTV,
- 'vote_func': None,
- 'tally_func': tallySTV
- },
- {
- 'key': "stv3",
- 'description': "Single Transferrable Vote with 3 seats",
- 'category': 'stv',
- 'validate_func': validateSTV,
- 'vote_func': None,
- 'tally_func': tallySTV
- },
- {
- 'key': "stv4",
- 'description': "Single Transferrable Vote with 4 seats",
- 'category': 'stv',
- 'validate_func': validateSTV,
- 'vote_func': None,
- 'tally_func': tallySTV
- },
- {
- 'key': "stv5",
- 'description': "Single Transferrable Vote with 5 seats",
- 'category': 'stv',
- 'validate_func': validateSTV,
- 'vote_func': None,
- 'tally_func': tallySTV
- },
- {
- 'key': "stv6",
- 'description': "Single Transferrable Vote with 6 seats",
- 'category': 'stv',
- 'validate_func': validateSTV,
- 'vote_func': None,
- 'tally_func': tallySTV
- },
- {
- 'key': "stv7",
- 'description': "Single Transferrable Vote with 7 seats",
- 'category': 'stv',
- 'validate_func': validateSTV,
- 'vote_func': None,
- 'tally_func': tallySTV
- },
- {
- 'key': "stv8",
- 'description': "Single Transferrable Vote with 8 seats",
- 'category': 'stv',
- 'validate_func': validateSTV,
- 'vote_func': None,
- 'tally_func': tallySTV
- },
- {
- 'key': "stv9",
- 'description': "Single Transferrable Vote with 9 seats",
- 'category': 'stv',
- 'validate_func': validateSTV,
- 'vote_func': None,
- 'tally_func': tallySTV
- }
-)
\ No newline at end of file
+)
+
+# Add ad nauseam
+for i in range(2,21):
+ constants.VOTE_TYPES += (
+ {
+ 'key': "stv%02u" % i,
+ 'description': "Single Transferrable Vote with %u seats" % i,
+ 'category': 'stv',
+ 'validate_func': validateSTV,
+ 'vote_func': None,
+ 'tally_func': tallySTV
+ },
+ )
Modified: steve/trunk/pysteve/www/htdocs/js/steve_rest.js
URL: http://svn.apache.org/viewvc/steve/trunk/pysteve/www/htdocs/js/steve_rest.js?rev=1669031&r1=1669030&r2=1669031&view=diff
==============================================================================
--- steve/trunk/pysteve/www/htdocs/js/steve_rest.js (original)
+++ steve/trunk/pysteve/www/htdocs/js/steve_rest.js Wed Mar 25 00:49:05 2015
@@ -996,7 +996,16 @@ function setVoteTypes(code, response, st
option.value = i;
sortable.push([option, type])
}
- sortable.sort(function(a,b) { return (a[1] > b[1])})
+ sortable.sort(
+ function(a,b) {
+ var ta = a[1].match(/^(.+?)\d+/) ? a[1].match(/(.+?)\d+/)[1] : null
+ var tb = b[1].match(/^(.+?)\d+/) ? b[1].match(/(.+?)\d+/)[1] : null
+ if ( ta && tb && ta == tb ) {
+ return parseInt(a[1].match(/(\d+)/)[1]) > parseInt(b[1].match(/(\d+)/)[1])
+ } else {
+ return (a[1] > b[1])
+ }
+ })
for (i in sortable) {
tobj.add(sortable[i][0])
}