Created
December 7, 2012 16:49
-
-
Save DaniZz/4234577 to your computer and use it in GitHub Desktop.
why do I get the same time at presentation and answer?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kivy.app import App | |
from kivy.uix.widget import Widget | |
from kivy.uix.label import Label | |
from kivy.graphics import Color, Ellipse, Line | |
from kivy.graphics.instructions import Callback | |
from kivy.uix.boxlayout import BoxLayout | |
from kivy.core.window import Window | |
from kivy.interactive import InteractiveLauncher | |
from kivy.properties import NumericProperty, StringProperty | |
from kivy.event import EventDispatcher | |
import time | |
import random | |
framePoints = [150, 250, 750, 250, 750, 600, 150, 600, 150, 250] | |
CIRCLEPOSITIONS = ([200,300],[350,300],[500,300],[650,300],[200,400],[350,400],[500,400],[650,400],[200,500],[350,500],[500,500],[650,500]) | |
CIRCLESIZE = 80 | |
RED = (0.3,0.3,0.3) | |
BLUE = (.6, .8, .6) | |
WHITE = (1,1,1) | |
NTRIALS = 12 | |
TESTPHASES = ['YN','COMP'] | |
PHASES = ['name','instruct','YN1','COMP1','YN2','COMP2','greetings'] | |
itemGroups = {'YN': [[['T','TICK'],['T','POCK'],['Z','TICK'],['Z','POCK'],['M','TICK'],['M','POCK']],[['T','TICK'],['T','POCK'],['Z','TICK'],['Z','POCK'],['M','TICK'],['M','POCK']]]} | |
class Circles(object): | |
def __init__(self, posx, posy, color): | |
self.x = posx | |
self.y = posy | |
self.col = color | |
class Configuration(object): | |
def __init__(self, nred = 6, nblue = 6): | |
self.nred = nred | |
self.nblue = nblue | |
self.circles = [] | |
self.setupConf() | |
def setupConf(self): | |
circlePosz = list(CIRCLEPOSITIONS) | |
for i in range(0,self.nred): | |
coord = circlePosz.pop(0) | |
self.circles.append(Circles(coord[0],coord[1],RED)) | |
for i in range(0,self.nblue): | |
coord = circlePosz.pop(0) | |
self.circles.append(Circles(coord[0],coord[1],BLUE)) | |
class EventHandler(Widget): | |
trialDisplayed = NumericProperty(0) | |
keyPressed = StringProperty('') | |
def __init__(self, **kwargs): | |
super(EventHandler, self).__init__(**kwargs) | |
Window.bind(on_key_down=self.on_key) | |
def on_key(self, keycode, *args): | |
self.keyPressed = args[2] | |
if self.keyPressed in ['m','z']: | |
if self.trialDisplayed < NTRIALS: | |
self.trialDisplayed += 1 | |
print self.trialDisplayed | |
events = EventHandler() | |
class Trials(object): | |
def __init__(self): | |
self.setup = None | |
self.question = None | |
self.ans = None | |
self.time = None | |
self.timeStart = None | |
def evaluate (self, answer): | |
return True | |
def writeTrial (self): | |
self.time = time.time() - self.timeStart | |
self.ans = events.keyPressed | |
class Session(object): | |
def __init__(self, tyype, number): | |
self.tyype = tyype | |
self.number = number | |
self.trials = [] | |
self.makeSession() | |
def makeSession(self): | |
for group in itemGroups[self.tyype]: | |
random.shuffle(group) | |
for tr in group: | |
if tr[0] == 'T': nred = 12 | |
if tr[0] == 'Z': nred = 0 | |
if tr[0] == 'M': nred = random.randint(4,8) | |
thisTrial = Trials() | |
thisTrial.setup = Configuration(nred,12-nred) | |
thisTrial.question = tr[1] | |
self.trials.append(thisTrial) | |
# if self.tyype == 'YN': | |
# if self.tyype == 'COMPARISON': | |
class DisplayWidget(Widget): | |
def __init__(self, frame, session, **kwargs): | |
super(DisplayWidget, self).__init__(**kwargs) | |
self.trials = session.trials | |
self.frame = frame | |
# Window.clearcolor = (0.1, 0.1, 0.1, 1.) | |
self.update_drawing() | |
def update_drawing(self): | |
self.canvas.clear() | |
# gets the trial that is gonna be displayed | |
self.ntrial = events.trialDisplayed | |
# binds the trialDisplayed property to the callcall funciton to update the drawing | |
events.bind(trialDisplayed=self.callcall) | |
# writes the presentation time | |
self.trials[self.ntrial].timeStart = time.time() | |
print 'this is the start time', self.trials[self.ntrial].timeStart | |
with self.canvas: | |
Color(*WHITE) | |
Line(points=self.frame, width=2.5) | |
# draws all the circles (contained in the setup) of the current trial | |
for circle in self.trials[self.ntrial].setup.circles: | |
Color(*circle.col) | |
d = CIRCLESIZE | |
Ellipse(pos=(circle.x , circle.y), size=(d, d)) | |
self.cb = Callback(self.my_callback) | |
def my_callback (self, instr): | |
pass | |
def callcall (self, *args): | |
# updates the drawing | |
self.update_drawing() | |
# writes the time and answer for the current trial | |
self.trials[self.ntrial].writeTrial() | |
#checks it out | |
print 'this is the answer time', time.time() | |
print 'this is supposed to be the time spent in aswering', self.trials[self.ntrial].time | |
print self.trials[self.ntrial].ans | |
phaseN = 0 | |
phase = 'YN' | |
class TiktokApp(App): | |
def build(self): | |
events.bind(keyPressed=self.moveOn) | |
if phase in TESTPHASES: | |
self.session = Session('YN',1) | |
layout = BoxLayout(orientation='vertical') | |
display = DisplayWidget(frame=framePoints,session=self.session) | |
text = Label(text=self.session.trials[0].question + ' cercles sont rouges') | |
layout.add_widget(display) | |
layout.add_widget(text) | |
return layout | |
def moveOn(self, *args): | |
if events.keyPressed == 'space': | |
phaseN += 1 | |
phase = allPhases[phaseN] | |
def build_config(self, config): | |
config.setdefaults('graphics', { | |
'width': '1280', | |
'height': '1024' | |
}) | |
if __name__ == '__main__': | |
TiktokApp().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment