Subversion Repositories Local Hare Voting

Rev

Rev 54 | Rev 63 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 54 Rev 62
Line 21... Line 21...
21
        <table>
21
        <table>
22
        <tr><td>CSV file of ballots:
22
        <tr><td>CSV file of ballots:
23
                <td><input type=file size=70 name=name>
23
                <td><input type=file size=70 name=name>
24
        </table>
24
        </table>
25
        <p>
25
        <p>
26
        <input type=submit name="run1" value="Run 1 Time">
26
        <input type=submit name="run1" value="Run">
27
        <input type=submit name="run1000" value="Run 1000 Times">
-
 
28
    </form>
27
    </form>
29
    <p>
28
    <p>
30
Input file format is given
29
Input file format is given
31
<a href="http://www.bikmort.com/wiki/index.php?title=Hare_Voting_Procedure">here</a>.
30
<a href="http://www.bikmort.com/wiki/index.php?title=Hare_Voting_Procedure">here</a>.
32
Almost no error checking is done, so be sure to review the trace output.
31
Little error checking is done, so be sure to review the trace output.
33
The source code is available <a href="%s?fetch=yes">here</a>.
32
The source code is available <a href="%s?fetch=yes">here</a>.
34
<p>
33
<p>
35
<small>%s</small>
34
<small>%s</small>
36
<hr>
35
<hr>
37
<pre>
36
<pre>
38
""" % (formaction, formaction, "$Id: vote.py 54 2007-09-20 23:39:27Z jtkorb $"))
37
""" % (formaction, formaction, "$Id: vote.py 62 2007-09-24 13:57:27Z jtkorb $"))
39
    return
38
    return
40
 
39
 
41
def emitPostHTML():
40
def emitPostHTML():
42
    emitHTML("""</pre>
41
    emitHTML("""</pre>
43
</body>
42
</body>
Line 94... Line 93...
94
        tally.trace(contents)
93
        tally.trace(contents)
95
 
94
 
96
        nWinners, ballots = parseinput.parsestring(contents)
95
        nWinners, ballots = parseinput.parsestring(contents)
97
        if form.has_key("run1"):
96
        if form.has_key("run1"):
98
            doone(nWinners, ballots)
97
            doone(nWinners, ballots)
99
        elif form.has_key("run1000"):
-
 
100
            domany(1000, nWinners, ballots)
-
 
101
        else:
98
        else:
102
            print "UNEXPECTED SUBMIT BUTTON: %s" % form
99
            print "UNEXPECTED SUBMIT BUTTON: %s" % form
103
                
100
                
104
    emitPostHTML()
101
    emitPostHTML()
105
    return
102
    return
106
 
103
 
107
def main():
104
def main():
108
    usage = "usage: %prog [options] filename.csv"
105
    usage = "usage: %prog [options] filename.csv"
109
    parser = optparse.OptionParser(usage)
106
    parser = optparse.OptionParser(usage)
110
    parser.add_option("-m", "--multi", dest="multi", action="store_true",
-
 
111
                      help="run process multiple (1000) times")
-
 
112
    (options, args) = parser.parse_args()
107
    (options, args) = parser.parse_args()
113
 
108
 
114
    if len(args) == 0:
109
    if len(args) == 0:
115
        doweb()
110
        doweb()
116
    else:
111
    else:
117
        nWinners, ballots = parseinput.parsefile(args[0])
112
        nWinners, ballots = parseinput.parsefile(args[0])
118
        if options.multi:
-
 
119
            domany(1000, nWinners, ballots)
-
 
120
        else:
-
 
121
            doone(nWinners, ballots)
113
        doone(nWinners, ballots)
122
 
114
 
123
if __name__=='__main__':
115
if __name__=='__main__':
124
    main()
116
    main()