Subversion Repositories Local Hare Voting

Rev

Rev 39 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 39 Rev 45
Line 1... Line 1...
1
#!/p/python/python
1
#!/p/python/python
2
 
2
 
3
import os
3
import os
4
import random
4
import random
-
 
5
import cStringIO
5
 
6
 
6
import parseinput
7
import parseinput
7
import tally
8
import tally
-
 
9
import vote
8
 
10
 
9
def testfile(dirpath, filename):
11
def testfile(dirpath, filename):
10
    print filename + ":",
12
    print filename + ":",
-
 
13
    tally.fdOut = cStringIO.StringIO()
-
 
14
 
11
    filenameCSV = os.path.join(dirpath, filename)
15
    filenameCSV = os.path.join(dirpath, filename)
12
    filenameOut = os.path.splitext(filenameCSV)[0] + ".out"
16
    filenameOut = os.path.splitext(filenameCSV)[0] + ".out"
13
    result = tallyfile(filenameCSV)
-
 
14
    handleresult(result, filename, filenameOut)
-
 
15
 
-
 
16
def tallyfile(filenameCSV):
-
 
17
    nWinners, ballots = parseinput.parsefile(filenameCSV)
17
    nWinners, ballots = parseinput.parsefile(filenameCSV)
-
 
18
 
18
    random.seed(1)
19
    random.seed(1)
-
 
20
    vote.domany(10, nWinners, ballots)
-
 
21
    tally.trace("")
19
    return str(tally.dotally(nWinners, ballots)) + "\n"
22
    vote.doone(nWinners, ballots)
-
 
23
    result = tally.fdOut.getvalue()
20
 
24
 
21
def handleresult(result, filename, filenameOut):
-
 
22
    if os.path.isfile(filenameOut):
25
    if os.path.isfile(filenameOut):
23
        fOut = open(filenameOut)
26
        fOut = open(filenameOut)
24
        correct = fOut.read()
27
        correct = fOut.read()
25
        if result == correct:
28
        if result == correct:
26
            print "OK"
29
            print "OK"
Line 32... Line 35...
32
        print "***** Creating output for " + filename + ": " + result,
35
        print "***** Creating output for " + filename + ": " + result,
33
        fOut = open(filenameOut, "w")
36
        fOut = open(filenameOut, "w")
34
        fOut.write(result)
37
        fOut.write(result)
35
 
38
 
36
def main(dir):
39
def main(dir):
37
    tally.fTrace = 0
-
 
38
    for dirpath, dirnames, filenames in os.walk(dir):
40
    for dirpath, dirnames, filenames in os.walk(dir):
39
        for filename in filenames:
41
        for filename in filenames:
40
            if filename.endswith(".csv"):
42
            if filename.endswith(".csv"):
41
                testfile(dirpath, filename)
43
                testfile(dirpath, filename)
42
 
44