Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!//usr/bin/env python
- max_digit=12
- max_big=30
- def get_add_operation():
- import random
- a=random.randint(1,max_big)
- b=random.randint(1,a)
- if random.random()<0.5:
- return ('%d+%d?'%(a-b,b),a)
- else:
- return ('%d+%d?'%(b,a-b),a)
- def get_mult_operation():
- import random
- a=random.randint(1,max_digit)
- b=random.randint(1,max_digit)
- return ('%dx%d?'%(a,b),a*b)
- def get_minus_operation():
- import random
- a=random.randint(1,max_big)
- b=random.randint(1,a)
- return ('%d-%d?'%(a,b),a-b)
- def get_div_operation():
- import random
- a=random.randint(1,max_digit)
- b=random.randint(1,max_digit)
- return ('%d/%d?'%(a*b,b),a)
- op_funcs = [ get_add_operation, get_mult_operation, get_minus_operation, get_div_operation ]
- def get_random_operation():
- return random.choice(op_funcs)()
- if __name__ == '__main__':
- import time
- import random
- import cPickle
- import sys
- if len(sys.argv) < 2: raise "Usage : compute.py login"
- ops_per_serie=15
- try:
- f=open("compute_stats_%s.pck" % sys.argv[1],"rb") #read stats on disk
- operations=cPickle.load(f)
- f.close()
- op_list = operations.items()
- op_list.sort(key=lambda i:sum(i[1][0])/len(i[1][0])) #sort by accuracy score
- bad_ops = [a[0] for a in op_list if sum(a[1][0])/len(a[1][0]) < 0.9] #ops the user doesn't master
- op_list.sort(key=lambda e:sum(e[1][1])/len(e[1][1]),reverse=True) #sort by answer time
- bad_ops.extend([a[0] for a in op_list[:10]]) #ops the user is slow to answer
- bad_ops=list(set(bad_ops)) #remove duplicates
- except Exception, e:
- operations={} #operations["5*2"] = [a,b,c,d,e] with a=1. if good, a=0. if wrong storing the 5 last results
- bad_ops=[]
- before = time.time()
- errors = 0
- for i in range(ops_per_serie):
- op_string,expected=get_random_operation()
- if random.random() < len(bad_ops)/(1.5*ops_per_serie):#train user specifically on stuff he doesn't master
- #print "training on bad op"
- op_string,expected = random.choice(bad_ops)
- #print len(bad_ops)/(1.5*ops_per_serie) #badop training probability
- scores,answer_times=operations.get((op_string,expected),([],[]))
- print op_string
- before_op=time.time()
- try:
- answer = int(raw_input())
- except:
- answer = expected-1 # this should be always wrong
- answer_time=time.time()-before_op
- if len(scores) > 5 : scores.pop(0) # keep only 5 scores
- if len(answer_times) > 5 : answer_times.pop(0) # keep only 5 timings
- answer_times.append(answer_time)
- if answer != expected:
- errors += 1
- scores.append(0.)
- operations[(op_string,expected)] = (scores,answer_times)
- print "WRONG!"
- else:
- scores.append(1.)
- operations[(op_string,expected)] = (scores,answer_times)
- print "good."
- total_time = time.time() - before
- print "Time: %.2fs, Errors : %d, Total points : %d" % (total_time,errors,100*ops_per_serie*(5.-errors)/total_time)
- cPickle.dump(operations,open("compute_stats_%s.pck"%sys.argv[1],"wb"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement