Author: adc
Date: Mon Mar 23 05:12:14 2015
New Revision: 1668516

URL: http://svn.apache.org/r1668516
Log:
fussy changes

Modified:
    steve/trunk/pysteve/www/cgi-bin/lib/__init__.py
    steve/trunk/pysteve/www/cgi-bin/lib/election.py
    steve/trunk/pysteve/www/cgi-bin/lib/form.py
    steve/trunk/pysteve/www/cgi-bin/lib/response.py
    steve/trunk/pysteve/www/cgi-bin/lib/voter.py

Modified: steve/trunk/pysteve/www/cgi-bin/lib/__init__.py
URL: 
http://svn.apache.org/viewvc/steve/trunk/pysteve/www/cgi-bin/lib/__init__.py?rev=1668516&r1=1668515&r2=1668516&view=diff
==============================================================================
--- steve/trunk/pysteve/www/cgi-bin/lib/__init__.py (original)
+++ steve/trunk/pysteve/www/cgi-bin/lib/__init__.py Mon Mar 23 05:12:14 2015
@@ -1,3 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
 """
 Stuff
 """
\ No newline at end of file

Modified: steve/trunk/pysteve/www/cgi-bin/lib/election.py
URL: 
http://svn.apache.org/viewvc/steve/trunk/pysteve/www/cgi-bin/lib/election.py?rev=1668516&r1=1668515&r2=1668516&view=diff
==============================================================================
--- steve/trunk/pysteve/www/cgi-bin/lib/election.py (original)
+++ steve/trunk/pysteve/www/cgi-bin/lib/election.py Mon Mar 23 05:12:14 2015
@@ -1,13 +1,32 @@
-import hashlib, json, random, os, sys, time
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+import hashlib
+import json
+import os
+
 from __main__ import homedir, config
-from os import listdir
 
 
 def exists(election):
     elpath = os.path.join(homedir, "issues", election)
     return os.path.isdir(elpath)
 
-def getBasedata(election, hideHash = False):
+
+def getBasedata(election, hideHash=False):
     elpath = os.path.join(homedir, "issues", election)
     if os.path.isdir(elpath):
         with open(elpath + "/basedata.json", "r") as f:
@@ -19,7 +38,8 @@ def getBasedata(election, hideHash = Fal
             basedata['id'] = election
             return basedata
     return None
-    
+
+
 def getIssue(electionID, issueID):
     issuepath = os.path.join(homedir, "issues", electionID, issueID) + ".json"
     issuedata = None
@@ -33,6 +53,7 @@ def getIssue(electionID, issueID):
         issuedata['prettyURL'] = "https://%s/steve/ballot?%s/%s"; % 
(config.get("general", "rooturl"), electionID, issueID)
     return issuedata
 
+
 def getVotes(electionID, issueID):
     issuepath = os.path.join(homedir, "issues", electionID, issueID) + 
".json.votes"
     issuedata = {}
@@ -42,14 +63,16 @@ def getVotes(electionID, issueID):
             f.close()
             issuedata = json.loads(data)
     return issuedata
-    
+
+
 def listIssues(election):
     issues = []
     elpath = os.path.join(homedir, "issues", election)
     if os.path.isdir(elpath):
-        issues = [ f.strip(".json") for f in os.listdir(elpath) if 
os.path.isfile(os.path.join(elpath,f)) and f != "basedata.json" and f != 
"voters.json" and f.endswith(".json")]
+        issues = [f.strip(".json") for f in os.listdir(elpath) if 
os.path.isfile(os.path.join(elpath, f)) and f != "basedata.json" and f != 
"voters.json" and f.endswith(".json")]
     return issues
 
+
 def vote(electionID, issueID, voterID, vote):
     votes = {}
     basedata = getBasedata(electionID)
@@ -70,17 +93,18 @@ def vote(electionID, issueID, voterID, v
 
 
 def invalidate(issueData, vote):
-    letters = ['y','n','a']
+    letters = ['y', 'n', 'a']
     if issueData['type'].find("stv") == 0:
-        letters = [chr(i) for i in range(ord('a'),ord('a') + 
len(issueData['candidates']))]
+        letters = [chr(i) for i in range(ord('a'), ord('a') + 
len(issueData['candidates']))]
     for char in letters:
         if vote.count(char) > 1:
             return "Duplicate letters found"
     for char in vote:
-        if not char in letters:
+        if char not in letters:
             return "Invalid characters in vote. Accepted are: %s" % ", 
".join(letters)
     return None
 
+
 def deleteIssue(electionID, issueID):
     if exists(electionID):
         issuepath = os.path.join(homedir, "issues", electionID, issueID) + 
".json"
@@ -91,21 +115,32 @@ def deleteIssue(electionID, issueID):
         return True
     else:
         raise Exception("No such election")
-    
-    
+
+
 debug = []
 
+
 def yna(votes):
-    y,n,a = 0,0,0
-    for key in votes:
-        vote = votes[key]
-        if vote == 'y': y+=1
-        if vote == 'n': n+=1
-        if vote == 'a': a+=1
-    return y,n,a
+    y = n = a = 0
+    for vote in votes.values():
+        if vote == 'y':
+            y += 1
+        if vote == 'n':
+            n += 1
+        if vote == 'a':
+            a += 1
+
+    return y, n, a
+
 
 def getproportion(votes, winners, step, surplus):
-    "Proportionally move votes"
+    """ Proportionally move votes
+    :param votes:
+    :param winners:
+    :param step:
+    :param surplus:
+    :return:
+    """
     prop = {}
     tvotes = 0
     for key in votes:
@@ -113,7 +148,7 @@ def getproportion(votes, winners, step,
         xstep = step
         char = vote[xstep]
         # Step through votes till we find a non-winner vote
-        while (xstep < len(vote) and vote[xstep] in winners):
+        while xstep < len(vote) and vote[xstep] in winners:
             xstep += 1
         if xstep >= step:
             tvotes += 1
@@ -121,44 +156,49 @@ def getproportion(votes, winners, step,
         if xstep < len(vote) and not vote[xstep] in winners:
             char = vote[xstep]
             prop[char] = (prop[char] if char in prop else 0) + 1
-            
+
     # If this isn't the initial 1st place tally, do the proportional math:
     # surplus votes / votes with an Nth preference * number of votes in that 
preference for the candidate
     if step > 0:
         for c in prop:
-            prop[c] = surplus / tvotes * prop[c]
-        
+            prop[c] *= surplus / tvotes
+
     debug.append("Proportional move: %s" % json.dumps(prop))
     return prop
-    
+
 
 def stv(candidates, votes, numseats):
-    "Calculate N winners using STV"
-    
+    """ Calculate N winners using STV
+    :param candidates:
+    :param votes:
+    :param int numseats: the number of seats available
+    :return:
+    """
+
     # Set up letters for mangling
-    letters = [chr(i) for i in range(ord('a'),ord('a') + len(candidates))]
+    letters = [chr(i) for i in range(ord('a'), ord('a') + len(candidates))]
     cc = "".join(letters)
-    
+
     # Keep score of votes
     points = {}
-    
+
     # Set all scores to 0 at first
     for c in cc:
         points[c] = 0
-    
+
     # keep score of winners
     winners = []
     turn = 0
-    
+
     # Find quota to win a seat
-    quota = ( len(votes) / (numseats +1) ) + 1
+    quota = ( len(votes) / (numseats + 1) ) + 1
     debug.append("Votes required to win a seat: %u" % quota)
-    
+
     # While we still have seats to fill
     if not len(candidates) < numseats:
-        while len(winners) < numseats and len(cc) > 0 and turn < 1000: #Don't 
run for > 1000 iterations, that's a bug
+        while len(winners) < numseats and len(cc) > 0 and turn < 1000:  #Don't 
run for > 1000 iterations, that's a bug
             turn += 1
-            
+
             s = 0
             y = 0
             # Get votes
@@ -166,7 +206,7 @@ def stv(candidates, votes, numseats):
             for x in xpoints:
                 points[x] += xpoints[x]
             mq = 0
-            
+
             # For each candidate letter, find if someone won a seat
             for c in cc:
                 if len(winners) >= numseats:
@@ -176,8 +216,7 @@ def stv(candidates, votes, numseats):
                     debug.append("WINNER: %s got elected in with %u votes! %u 
seats remain" % (c, points[c], numseats - len(winners)))
                     cc.replace(c, "")
                     mq += 1
-                    #break
-                    
+
             # If we found no winners in this round, eliminate the lowest 
scorer and retally
             if mq < 1:
                 lowest = 99999999
@@ -186,23 +225,23 @@ def stv(candidates, votes, numseats):
                     if points[c] < lowest:
                         lowest = points[c]
                         lowestC = c
-                        
+
                 debug.append("DRAW: %s is eliminated" % lowestC)
                 if lowestC:
                     cc.replace(lowestC, "")
                 else:
                     debug.append("No more canididates?? buggo?")
                     break
-    
+
     # Everyone's a winner!!
     else:
         winners = letters
-        
+
     # Compile list of winner names
     winnernames = []
     for c in winners:
         i = ord(c) - ord('a')
         winnernames.append(candidates[i]['name'])
-        
+
     # Return the data
     return winners, winnernames, debug
\ No newline at end of file

Modified: steve/trunk/pysteve/www/cgi-bin/lib/form.py
URL: 
http://svn.apache.org/viewvc/steve/trunk/pysteve/www/cgi-bin/lib/form.py?rev=1668516&r1=1668515&r2=1668516&view=diff
==============================================================================
--- steve/trunk/pysteve/www/cgi-bin/lib/form.py (original)
+++ steve/trunk/pysteve/www/cgi-bin/lib/form.py Mon Mar 23 05:12:14 2015
@@ -1,3 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
 import hashlib, json, random, os, sys, time
 from __main__ import homedir, config
 import cgi

Modified: steve/trunk/pysteve/www/cgi-bin/lib/response.py
URL: 
http://svn.apache.org/viewvc/steve/trunk/pysteve/www/cgi-bin/lib/response.py?rev=1668516&r1=1668515&r2=1668516&view=diff
==============================================================================
--- steve/trunk/pysteve/www/cgi-bin/lib/response.py (original)
+++ steve/trunk/pysteve/www/cgi-bin/lib/response.py Mon Mar 23 05:12:14 2015
@@ -1,4 +1,20 @@
 #!/usr/bin/env python
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
 import json
 
 responseCodes = {

Modified: steve/trunk/pysteve/www/cgi-bin/lib/voter.py
URL: 
http://svn.apache.org/viewvc/steve/trunk/pysteve/www/cgi-bin/lib/voter.py?rev=1668516&r1=1668515&r2=1668516&view=diff
==============================================================================
--- steve/trunk/pysteve/www/cgi-bin/lib/voter.py (original)
+++ steve/trunk/pysteve/www/cgi-bin/lib/voter.py Mon Mar 23 05:12:14 2015
@@ -1,3 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
 import hashlib, json, random, os, sys, time
 from __main__ import homedir, config
 


Reply via email to