示例#1
0
 def runTests(self):
     # for each election, run with openmmv and openstv and print results
     if self.file:
         files = [self.file]
     else:
         files = os.listdir(self.path)
     if self.randomize: random.shuffle(files)
     self.diff = {}
     self.times = {}
     cur = 0
     for file in files:
         if cur < self.max and file[-4:].lower() == ".blt":
             print "Processing file: %s..." % file
             msg = ""
             b = ballots.Ballots()
             loader = BltBallotLoader()
             loader.load(b,self.path+file)
             s, sdelta =  self.runSTV(self.path + file,b)
             m2, m2delta = self.runMMV2(self.path + file,b)
             msg += "======================================\n"
             msg += "Election file: %s\n" % file
             msg += "%s\n" % s
             msg += "%s\n\n" % m2
             #print msg
             self.times[file] = (sdelta, m2delta)
             if s[3:] != m2[3:]:
                 self.diff[file] = msg
             cur += 1
     print "Files with differing results:"
     for _, msg in sorted(self.diff.items()):
         print msg
     print "\nTimings (in milliseconds):\nFilename\tSTV time\tMMV time"
     print "========================================================"
     for t in sorted(self.times.keys()):
         s, m2 = self.times[t]
         print "%s\t\t%4.3f\t\t%4.3f" % (t, s, m2)
示例#2
0
 def runTests(self):
     # for each election, run with openmmv and openstv and print results
     if self.file:
         files = [self.file]
     else:
         files = os.listdir(self.path)
     if self.randomize: random.shuffle(files)
     self.diff = {}
     self.times = {}
     cur = 0
     for file in files:
         if cur < self.max and file[-4:].lower() == ".blt":
             print "Processing file: %s..." % file
             msg = ""
             b = ballots.Ballots()
             loader = BltBallotLoader()
             loader.load(b, self.path + file)
             s, sdelta = self.runSTV(self.path + file, b)
             m2, m2delta = self.runMMV2(self.path + file, b)
             msg += "======================================\n"
             msg += "Election file: %s\n" % file
             msg += "%s\n" % s
             msg += "%s\n\n" % m2
             #print msg
             self.times[file] = (sdelta, m2delta)
             if s[3:] != m2[3:]:
                 self.diff[file] = msg
             cur += 1
     print "Files with differing results:"
     for _, msg in sorted(self.diff.items()):
         print msg
     print "\nTimings (in milliseconds):\nFilename\tSTV time\tMMV time"
     print "========================================================"
     for t in sorted(self.times.keys()):
         s, m2 = self.times[t]
         print "%s\t\t%4.3f\t\t%4.3f" % (t, s, m2)
 def __init__(self, fName=""):
     BltBallotLoader.__init__(self, fName)
     self.fName = fName
 def __init__(self, fName=""):
   BltBallotLoader.__init__(self,fName)
   self.fName = fName