Skip to content

Instantly share code, notes, and snippets.

@wkta
Created March 31, 2014 17:01
Show Gist options
  • Save wkta/9896955 to your computer and use it in GitHub Desktop.
Save wkta/9896955 to your computer and use it in GitHub Desktop.
#MonthOfCode day 28 - race
import random
import time
def detPrecision( candidate, model):
chars_cand = list( candidate)
chars_model = list(model)
while( len(chars_cand)<len(chars_model) ):
chars_cand.append(' ')
while( len(chars_cand)>len(chars_model) ):
chars_cand.pop()
nb_valid_chars = 0
for i in xrange( len(chars_model)):
if( chars_model[i]==chars_cand[i] ):
nb_valid_chars+=1
return 100.0 *( float(nb_valid_chars)/len(chars_model) )
latin_samples = [
"entitas ipsa involvit aptitudinem ad extorquendum certum assensum",
"entia non sunt multiplicanda praeter necessitatem",
"ense petit placidam sub libertate quietem",
"et nunc reges intelligite erudimini qui judicatis terram",
"ex vita discedo, tanquam ex hospitio, non tanquam ex domo",
"omnia praesumuntur legitime facta donec probetur in contrarium",
"sed ipse spiritus postulat pro nobis, gemitibus inenarrabilibus",
"scribimus indocti doctique poemata passim" ]
random.shuffle( latin_samples )
exercise = latin_samples.pop()
print "You will have to type the following text as fast as you can...",
print "Hit ENTER when ready!"
print " ",exercise,
raw_input()
print "> ",
t0 = time.time()
res = raw_input()
diff = (time.time() - t0)
print " Text typed in:",diff,"seconds"
# printing estimated WPM (words per minute) value with 1 decimal digit
AVG_WORD_LEN = 5
print " estimated WPM:","%.1f" % (
60.0*(float(len(exercise))/diff) / AVG_WORD_LEN
)
# printing precision value with 2 decimal digits max.
print " precision achieved:", "%.2f" % detPrecision( res, exercise),"%"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment