From 8eddb4f8d391689940cf19257e30b2cd02c27ee9 Mon Sep 17 00:00:00 2001 From: bnicenboim <bruno.nicenboim@gmail.com> Date: Tue, 4 Feb 2014 17:31:34 +0100 Subject: [PATCH 1/3] A log was added (on screen and file) --- py-span-task.py | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/py-span-task.py b/py-span-task.py index 59eac86..ed4acc4 100755 --- a/py-span-task.py +++ b/py-span-task.py @@ -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 @@ -128,6 +129,8 @@ 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 @@ -135,6 +138,8 @@ 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) @@ -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:])) @@ -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) @@ -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: @@ -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)), @@ -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 @@ -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() From 66f19c438251a895492b11ddee3f9b624e1210aa Mon Sep 17 00:00:00 2001 From: bnicenboim <bruno.nicenboim@gmail.com> Date: Tue, 4 Feb 2014 17:47:03 +0100 Subject: [PATCH 2/3] Spaces between target items of one character are added --- py-span-task.py | 46 +++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/py-span-task.py b/py-span-task.py index ed4acc4..e2e3b94 100755 --- a/py-span-task.py +++ b/py-span-task.py @@ -10,7 +10,7 @@ __license__ = "GPL v2" import sys, os, re, math, time, random -import datetime +import datetime #added to save the date and time 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 @@ -130,7 +130,7 @@ def show_element(self, frame, key=None, **opts): self.times.append(time.time()) frame.set_text(element) print "equation in screen: %s" % element - log_line("equation in screen: %s" % element) + log_line("equation in screen: %s" % element) #Bruno self.number += 1 self.next = self.store_results @@ -138,8 +138,8 @@ 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]) ) + 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]) ) #Bruno if key == responses[self.desired_answer]: self.correct += 1 frame.set_text(practice_correct_response) @@ -157,9 +157,9 @@ def show_results(self, frame, **opts): "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(" ") + log_line(" ") #Bruno + log_line("total: %s ; correct: %s" % (practice_processing_items,self.correct ) ) #Bruno + log_line(" ") #Bruno store_line("# Practice processing items: %d" % practice_processing_items) time_out = int(1000 * (mean(diff(self.times[measure_time_after_trial:])) @@ -205,16 +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) + print "equation in screen: %s" % element #Bruno + log_line("equation in screen: %s" % element) #Bruno 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") + print "time out..." #Bruno + log_line("Time out") #Bruno self.times.append(time.time() - self.start_time) ti = self.cur_targets.next() self.seen_targets.append(ti) @@ -235,9 +235,9 @@ def show_target(self, frame, key, **opts): 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) + log_line("key pressed: %s ; correct answer: %s ; correct response: %s" % (key, self.desired_answer, responses[self.desired_answer]) ) #Bruno + print ti #Bruno + log_line("item presented: %s" %ti) #Bruno if not self.cur: frame.after(target_display_time, lambda:self.finish_set(frame, **opts)) else: @@ -260,7 +260,14 @@ def store_results(self, frame, key, **opts): s = s.replace(',', '') s = s.split() t = [x.lower() for x in self.seen_targets] - + if single_letters==True: #add spaces if they forgot and they are single letters + for i in s: + if len(i)>1: + ind = s.index(i) + s.pop(ind) + for ii in list(i): + s.insert(ind,ii) + ind=ind+1 # Allow one typo: omission, addition, substitution of a character or # transposition of two characters. # FIXME: d(ABCD, BCDA) > d(ABCD, BACD) @@ -287,7 +294,7 @@ def store_results(self, frame, key, **opts): print " recalled:", ", ".join(s) print " correct:", correct, "out of", self.level print " " - log_line(" ") + log_line(" ") #Bruno... log_line( "trial: %s %s"% (self.phase, self.set_no)) log_line( " presented: %s " % ", ".join(t)) log_line( " recalled: %s " % ", ".join(s)) @@ -407,7 +414,7 @@ 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("########################################################") #Bruno log_line("subject number %s" %sid) log_line(datetime.datetime.now().strftime("%Y-%m-%d %H:%M")) return sid @@ -544,6 +551,11 @@ def __exit__(self, *exc_info): # max level: if len(t) < 2*max(practice_levels + levels): warn("There are very few target items. They might repeat too often.") + # Check if the targets are single letters/numbers + single_letters =True + for i in t: + if len(i)>1: + single_letters=False # In case sloppy spelling is allowed, check if the target items have # a sufficient damerau levenshtein distance to be unambiguously From aeab5f0b841d85da9f4849045362e99c78fe8959 Mon Sep 17 00:00:00 2001 From: bnicenboim <bruno.nicenboim@gmail.com> Date: Tue, 4 Feb 2014 22:32:51 +0100 Subject: [PATCH 3/3] Revert "Spaces between target items of one character are added" This reverts commit 66f19c438251a895492b11ddee3f9b624e1210aa. --- py-span-task.py | 46 +++++++++++++++++----------------------------- 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/py-span-task.py b/py-span-task.py index e2e3b94..ed4acc4 100755 --- a/py-span-task.py +++ b/py-span-task.py @@ -10,7 +10,7 @@ __license__ = "GPL v2" import sys, os, re, math, time, random -import datetime #added to save the date and time +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 @@ -130,7 +130,7 @@ def show_element(self, frame, key=None, **opts): self.times.append(time.time()) frame.set_text(element) print "equation in screen: %s" % element - log_line("equation in screen: %s" % element) #Bruno + log_line("equation in screen: %s" % element) self.number += 1 self.next = self.store_results @@ -138,8 +138,8 @@ 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]) ) #Bruno + 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) @@ -157,9 +157,9 @@ def show_results(self, frame, **opts): "total":practice_processing_items, "correct":self.correct}) print "\n total: %s ; correct: %s \n" % (practice_processing_items,self.correct ) - log_line(" ") #Bruno - log_line("total: %s ; correct: %s" % (practice_processing_items,self.correct ) ) #Bruno - log_line(" ") #Bruno + 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:])) @@ -205,16 +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 #Bruno - log_line("equation in screen: %s" % element) #Bruno + 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..." #Bruno - log_line("Time out") #Bruno + 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) @@ -235,9 +235,9 @@ def show_target(self, frame, key, **opts): 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]) ) #Bruno - print ti #Bruno - log_line("item presented: %s" %ti) #Bruno + 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: @@ -260,14 +260,7 @@ def store_results(self, frame, key, **opts): s = s.replace(',', '') s = s.split() t = [x.lower() for x in self.seen_targets] - if single_letters==True: #add spaces if they forgot and they are single letters - for i in s: - if len(i)>1: - ind = s.index(i) - s.pop(ind) - for ii in list(i): - s.insert(ind,ii) - ind=ind+1 + # Allow one typo: omission, addition, substitution of a character or # transposition of two characters. # FIXME: d(ABCD, BCDA) > d(ABCD, BACD) @@ -294,7 +287,7 @@ def store_results(self, frame, key, **opts): print " recalled:", ", ".join(s) print " correct:", correct, "out of", self.level print " " - log_line(" ") #Bruno... + log_line(" ") log_line( "trial: %s %s"% (self.phase, self.set_no)) log_line( " presented: %s " % ", ".join(t)) log_line( " recalled: %s " % ", ".join(s)) @@ -414,7 +407,7 @@ 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("########################################################") #Bruno + log_line("########################################################") log_line("subject number %s" %sid) log_line(datetime.datetime.now().strftime("%Y-%m-%d %H:%M")) return sid @@ -551,11 +544,6 @@ def __exit__(self, *exc_info): # max level: if len(t) < 2*max(practice_levels + levels): warn("There are very few target items. They might repeat too often.") - # Check if the targets are single letters/numbers - single_letters =True - for i in t: - if len(i)>1: - single_letters=False # In case sloppy spelling is allowed, check if the target items have # a sufficient damerau levenshtein distance to be unambiguously