Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A log was added (on screen and file) #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions py-span-task.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
__license__ = "GPL v2"

import sys, os, re, math, time, random
import datetime
import Tkinter, Tkdnd, tkFileDialog
from Tkconstants import PAGES, UNITS, NORMAL, RAISED, SUNKEN, HORIZONTAL, RIGHT, BOTH, LEFT, BOTTOM, TOP, NW, HIDDEN, X, Y, ALL, CENTER
from warnings import warn
Expand Down Expand Up @@ -128,13 +129,17 @@ def show_element(self, frame, key=None, **opts):
element, self.desired_answer = [s.strip() for s in self.processing_items.next().split('\t')]
self.times.append(time.time())
frame.set_text(element)
print "equation in screen: %s" % element
log_line("equation in screen: %s" % element)
self.number += 1
self.next = self.store_results

def store_results(self, frame, key, **opts):
if key not in responses.values():
return
self.next = lambda s,f,k:None
print key, self.desired_answer, responses[self.desired_answer]
log_line("key pressed: %s ; correct answer: %s ; correct response: %s" % (key, self.desired_answer, responses[self.desired_answer]) )
if key == responses[self.desired_answer]:
self.correct += 1
frame.set_text(practice_correct_response)
Expand All @@ -151,7 +156,10 @@ def show_results(self, frame, **opts):
frame.set_text(practice_summary % {
"total":practice_processing_items,
"correct":self.correct})

print "\n total: %s ; correct: %s \n" % (practice_processing_items,self.correct )
log_line(" ")
log_line("total: %s ; correct: %s" % (practice_processing_items,self.correct ) )
log_line(" ")
store_line("# Practice processing items: %d"
% practice_processing_items)
time_out = int(1000 * (mean(diff(self.times[measure_time_after_trial:]))
Expand Down Expand Up @@ -197,12 +205,16 @@ def show_element(self, frame, key=None, time_out=None, **opts):
element, self.desired_answer = self.cur.pop(0).split('\t')
self.start_time = time.time()
frame.set_text(element)
print "equation in screen: %s" % element
log_line("equation in screen: %s" % element)
self.after_id = frame.after(time_out, lambda:self.interrupt(frame, **opts))
self.next = self.show_target

def interrupt(self, frame, **opts):
self.next = lambda s,f,k:None
frame.set_text(time_out_message)
print "time out..."
log_line("Time out")
self.times.append(time.time() - self.start_time)
ti = self.cur_targets.next()
self.seen_targets.append(ti)
Expand All @@ -222,6 +234,10 @@ def show_target(self, frame, key, **opts):
ti = self.cur_targets.next()
self.seen_targets.append(ti)
frame.set_text(ti)
print key, self.desired_answer, responses[self.desired_answer] #############
log_line("key pressed: %s ; correct answer: %s ; correct response: %s" % (key, self.desired_answer, responses[self.desired_answer]) )
print ti
log_line("item presented: %s" %ti)
if not self.cur:
frame.after(target_display_time, lambda:self.finish_set(frame, **opts))
else:
Expand Down Expand Up @@ -270,7 +286,13 @@ def store_results(self, frame, key, **opts):
print " presented:", ", ".join(t)
print " recalled:", ", ".join(s)
print " correct:", correct, "out of", self.level

print " "
log_line(" ")
log_line( "trial: %s %s"% (self.phase, self.set_no))
log_line( " presented: %s " % ", ".join(t))
log_line( " recalled: %s " % ", ".join(s))
log_line( " correct: %s out of %s" % (correct, self.level))
log_line(" ")
self.results.append("%s\t%d\t%d\t%d\t%d\t%d\t%d"
% (self.phase, self.set_no, self.level, correct,
self.correct, int(1000*mean(self.times)),
Expand Down Expand Up @@ -370,6 +392,12 @@ def store_line(s, mode='a'):
f.write(s + '\n')
f.close()

def log_line(s): #to have a log of what happened
f = file("log.txt", 'a')
f.write(s + '\n')
f.close()


def request_subject_id():
"""
Prompt the user to enter a subject ID and check if the input
Expand All @@ -379,6 +407,9 @@ def request_subject_id():
sid = sys.stdin.readline()[:-1]
mo = re.match('[a-zA-Z0-9]+', sid)
if mo and mo.group() == sid:
log_line("########################################################")
log_line("subject number %s" %sid)
log_line(datetime.datetime.now().strftime("%Y-%m-%d %H:%M"))
return sid
else:
return request_subject_id()
Expand Down