Example #1
0
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#

from array import array
import random, sys, pickle, os
import key_vote_lib

if __name__ == '__main__':
  results = ([],[]) # tableau contenant les résultats (un pour chaque main)
  matchs = {} # matchs réellement effectués
  
  if len( sys.argv ) < 2 :
    sortedResultFile = 'result-sorted'
    key_vote_lib.printStdOut( u'Pas de fichier spécifié, utilisation du fichier ' + sortedResultFile )
  else:
    sortedResultFile = sys.argv[1]

  if len( sys.argv ) < 3 :
    resultFile = 'result'
    key_vote_lib.printStdOut( u'Pas de fichier spécifié, utilisation du fichier ' + resultFile )
  else:
    resultFile = sys.argv[2]

  # choix du clavier
  kbd = key_vote_lib.chooseKbd()
  
  if os.path.exists( sortedResultFile ):
    results = pickle.load( file( sortedResultFile ) )
  else:
Example #2
0
for fName in sys.argv[1:] :
  f = file( fName )
  results = pickle.load( f )
  
  if isinstance( results, tuple ):
    results = key_vote_lib.computeMachs( results )
  
  key_vote_lib.countLost( results, scores )
  
  # for the individual ratios
  ratios.append( key_vote_lib.computeScores( key_vote_lib.countLost( results ) ) )
  
  f.close()
  
ratio = key_vote_lib.computeScores( scores )

sigma = {}
total = 0
for k in ratio.keys() :
  sum2 = 0
  for r in ratios :
    sum2 += math.pow( r[k] - ratio[k], 2 )
  s = math.sqrt( sum2 / len(ratios) )
  sigma[k] = s
  total += s

key_vote_lib.printScores( sigma, hands )
key_vote_lib.printStdOut()
key_vote_lib.printStdOut( u"Différence totale: " + str( total ) )
key_vote_lib.printKbdScores( sigma )
Example #3
0
def generateCandidate( candidateSize, min, max, wrong=[] ):
  candidate = []
  for i in range( candidateSize ):
    n = random.randint( min, max )
    while n in candidate:
      n = random.randint( min, max )
    candidate.append( n )
  if candidate == list( wrong ):
    return generateCandidate( candidateSize, min, max, wrong )
  return tuple( candidate )

if __name__ == '__main__':
  
  if len( sys.argv ) == 1 :
    resultFile = 'result'
    key_vote_lib.printStdOut( u'Pas de fichier spécifié, utilisation du fichier ' + resultFile )
  else:
    resultFile = sys.argv[1]
  
  hands = key_vote_lib.chooseKbd()
  leftHand,rightHand = hands
  
  nbOfChars = 1
  
  nbOfVotes = 10
  
  if os.path.exists( resultFile ):
    results = pickle.load( file( resultFile ) )
  else:
    results = {}