Simple Relative Mental Functionality Logger (just a typing test)

The following code obtains and logs an error adjusted performance time for the copying of a simple random paragraph. This test measures the users speed and correctness in translating visual data into reasonably complex fine hand motions. It is intended to be used frequently in order for the user to establish a baseline and detect deviations therefrom. This data is subject to user bias, as the user would be able to arbitrarily lengthen their own times. Thus, the test doesn’t work if the user doesn’t put in their “best” effort, so to speak. The user must create two text files of their own as input and log files. The first test_words.txt should be populated with a list of line separated words that the user wishes to use in the randomly generated paragraphs. The second, test_scores.txt just needs to be created and left empty in the program directory prior to the first use.

It’s python (underscores must be replaced with spaces or tabs):

import sys
import random
from datetime import datetime, date, time, timedelta
try:
____f = open(‘test_words.txt’,’r’)
except:
____print “test_words.txt failed to open!”
words = []
for line in f:
____# print line
____words.append(line)
#print old
f.close()
test_set=random.sample(words,50)
test= “”
for word in test_set:
____word = word[0:len(word)-1]
____if test == “”:
________test=word
____else:
________test= test + ” ” + word
print “n”
print “n”
print test
print “n”
print “Please copy the above words exactly as they appear.”
print “n”
start_t = datetime.now()
user = raw_input()
end_t = datetime.now()
firsttime = end_t-start_t
firsterrors=0
index = 0
for index in range(0,len(test)):
____try:
________if test[index] == user[index]:
____________continue
________else:
____________firsterrors+=1
________if isinstance(user[index],string):
____________continue
________else:
____________firsterrors+=1
____except:
________firsterrors+=1
print “n”
print “errors: ” + str(firsterrors)
print “time: ” + str(firsttime.total_seconds())
print “error adjusted time: ” + str(firsttime.total_seconds()+5*firsterrors)
print “n”
try:
____f=open(“/media/usbdisc/test_scores.txt”,”r”)
except:
____print “Failed to open test_scores.txt”
scores=[]
for line in f:
____scores.append(line[0:len(line)-1])
f.close()
scores.append(str(end_t)+” “+”errors= ” +str(firsterrors)+ ” test time= “+str(firsttime.total_seconds())+” error adjusted time: ” + str(firsttime.total_seconds()+5*firsterrors))
write_scores = “”
for score in scores:
____write_scores = write_scores + str(score) + “n”
try:
____f2=open(“test_scores.txt”,”w+”)
except:
____print “Failed to open test_scores.txt”
try:
____f2.truncate()
____f2.write(write_scores)
____f2.close()
except:
____f2.close()
____print “Failed to Write Scores!”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s