class Rating(): def __init__(self, win, description, labels, rating_file): self.win = win self.rating_file = rating_file self.description = TextStim(win, text=description, height=0.05, pos=(0, 0.5), units='norm', color=(0, 0, 0), colorSpace='rgb255') if len(labels) == 7: self.rating_scale = RatingScale(win, scale=None, labels=labels, tickMarks=[1, 2, 3, 4, 5, 6, 7], pos=(0, 0), stretch=3, textSize=0.8, textColor='Black', lineColor='Black', showValue=False, showAccept=False) else: self.rating_scale = RatingScale(win, scale=None, labels=labels, pos=(0, 0), stretch=3, textSize=0.8, textColor='Black', lineColor='Black', showValue=False, showAccept=False) self.button = Button(win, (0, -0.5), width=0.1, height=0.05, name='button_rating', text='确认') def run(self): while self.button.state != self.button.END: self.description.draw() self.rating_scale.draw() self.button.process() self.button.draw() self.win.flip() def save(self): self.rating_file.write('Rating: ' + str(self.rating_scale.getRating()) + '\n') self.rating_file.write('Decision Time: ' + str(self.rating_scale.getRT()) + '\n') choice_history = self.rating_scale.getHistory() self.rating_file.write('Choice History:\n(choice\ttime)\n') for i in choice_history: self.rating_file.write(str(i[0]) + '\t' + str(i[1]) + '\n') self.rating_file.write('\n')
def test_getRating_RT_history(self): # 1139-43 r = copy.copy(self.r) r.status = FINISHED r.noResponse = True r.timedOut = True assert r.getRT() == r.maxTime r.timedOut = False assert r.getRT() is None r.noResponse = False assert r.getRT() == r.decisionTime r.reset() # --------------- r.noResponse = True r.markerPlacedAt = 0 r.status = FINISHED assert r.getRating() is None r.status = FINISHED + 1 assert r.getRating() == 1 r.precision = 1 r.choices = ['a', 'b'] assert r.getRating() == 'b' r = RatingScale(self.win, singleClick=True, autoLog=False) r.draw() core.wait(.001, 0) r.acceptKeys = r.allKeys = ['1'] r.beyondMinTime = True event._onPygletKey(symbol='1', modifiers=0, emulated=True) r.draw() h = r.getHistory() assert h[0] == (None, 0) assert h[-1][0] == 1 if _vmTesting: assert 0.001 < h[-1][1] < 0.05 # virtual machines not usually great else: assert 0.001 < h[-1][1] < 0.03
def test_getRating_RT_history(self): # 1139-43 r = copy.copy(self.r) r.status = FINISHED r.noResponse = True r.timedOut = True assert r.getRT() == r.maxTime r.timedOut = False assert r.getRT() is None r.noResponse = False assert r.getRT() == r.decisionTime r.reset() # --------------- r.noResponse = True r.markerPlacedAt = 0 r.status = FINISHED assert r.getRating() is None r.status = FINISHED + 1 assert r.getRating() == 1 r.precision = 1 r.choices = ['a', 'b'] assert r.getRating() == 'b' r = RatingScale(self.win, singleClick=True, autoLog=False) r.draw() core.wait(.001, 0) r.acceptKeys = r.allKeys = ['1'] r.beyondMinTime = True event._onPygletKey(symbol='1', modifiers=0, emulated=True) r.draw() h = r.getHistory() assert h[0] == (None, 0) assert h[-1][0] == 1 if _travisTesting: assert 0.001 < h[-1][1] < 0.05 # travis virtual machines not great else: assert 0.001 < h[-1][1] < 0.03
def test_getRating_RT_history(self): # 1139-43 r = copy.copy(self.r) r.status = FINISHED r.noResponse = True r.timedOut = True assert r.getRT() == r.maxTime r.timedOut = False assert r.getRT() is None r.noResponse = False assert r.getRT() == r.decisionTime r.reset() # --------------- r.noResponse = True r.markerPlacedAt = 0 r.status = FINISHED assert r.getRating() is None r.status = FINISHED + 1 assert r.getRating() == 1 r.precision = 1 r.choices = ["a", "b"] assert r.getRating() == "b" r = RatingScale(self.win, singleClick=True, autoLog=False) r.draw() core.wait(0.001, 0) r.acceptKeys = r.allKeys = ["1"] r.beyondMinTime = True event._onPygletKey(symbol="1", modifiers=None, emulated=True) r.draw() h = r.getHistory() assert h[0] == (None, 0) assert h[-1][0] == 1 assert 0.001 < h[-1][1] < 0.03
def test_getRating_RT_history(self): # 1139-43 r = RatingScale(self.win) r.status = FINISHED r.noResponse = True r.timedOut = True assert r.getRT() == r.maxTime r.timedOut = False assert r.getRT() == None r.noResponse = False assert r.getRT() == r.decisionTime r = RatingScale(self.win, precision=10) r.noResponse = True r.markerPlacedAt = 0 r.status = FINISHED assert r.getRating() == False r.status = FINISHED + 1 assert r.getRating() == 1 r.precision = 1 r.choices = ['a', 'b'] assert r.getRating() == 'b' r = RatingScale(self.win, singleClick=True) r.draw() core.wait(.001, 0) r.acceptKeys = r.allKeys = ['1'] r.beyondMinTime = True event._onPygletKey(symbol='1', modifiers=None, emulated=True) r.draw() h = r.getHistory() assert h[0] == (None, 0) assert h[-1][0] == 1 assert 0.001 < h[-1][1] < 0.03