from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants class Task(Page): form_model='player' form_fields =['barcodeInput'] timeout_seconds = 60 def is_displayed(self): player = self.player import time current_time = time.time() if player.timePlaceholder == 0: player.timePlaceholder = round(current_time, 4) if self.round_number == 1: player.participant.vars['earningFromTask_second'] = 0 player.participant.vars['mistakesTally_second'] = 0 player.participant.vars['correctsTally_second'] = 0 timeSinceStart = (current_time - player.in_round(1).timePlaceholder) player.showScreen = timeSinceStart < (Constants.allowedTime+player.participant.vars['extraDurationInTask2']) or (self.round_number <= 15) if player.showScreen: try: import random x = random.choice(player.participant.vars['secondList']) player.barcodeThisRound = x (player.participant.vars['secondList']).remove(x) except: player.showScreen = False if player.participant.vars['showInterruptionsInTask2'] == 'Yes': for i in player.participant.vars['ipts_list_second']: if i <= timeSinceStart <= (i + 65): (player.participant.vars['ipts_list_second']).remove(i) player.showInterruption = True player.interruptionResponse = "" break return player.showScreen and not(player.showInterruption) def vars_for_template(self): player = self.player image = "task/"+ str( player.barcodeThisRound ) +".png" return dict( image = image ) def before_next_page(self): player = self.player import time current_time = time.time() player.timeThisRound = round(current_time - player.timePlaceholder, 2) userInput = player.barcodeInput answerKey = Constants.correctArray[ player.barcodeThisRound ] player.actualCorrectAnswer = answerKey player.mistakesThisRound, player.correctsThisRound = player.CountMistakes(userInput, answerKey) player.participant.vars['mistakesTally_second'] += player.mistakesThisRound player.participant.vars['correctsTally_second'] += player.correctsThisRound pos = player.correctsThisRound * Constants.piece_rate neg = player.mistakesThisRound * Constants.penalty_rate player.earningThisRound = round(( pos - neg),2) player.participant.vars['earningFromTask_second'] += round(( pos - neg),2) player.participant.vars['earningFromTask_second'] = round(player.participant.vars['earningFromTask_second'], 2) player.correctsTally = player.participant.vars['correctsTally_second'] player.mistakesTally = player.participant.vars['mistakesTally_second'] player.earningFromTask = player.participant.vars['earningFromTask_second'] player.actualCorrectAnswer = 'C' + player.actualCorrectAnswer player.barcodeInput = 'B' + player.barcodeInput ###---------------------------------------------------------------------------------------------------### class Task_Interruption_1(Page): form_model='player' form_fields =['barcodeInput'] timeout_seconds = 20 def is_displayed(self): player = self.player return player.showScreen and player.showInterruption def vars_for_template(self): player = self.player import random x = random.choice(player.participant.vars['secondList']) player.barcodeThisRound = x (player.participant.vars['secondList']).remove(x) image = "task/"+ str(x) +".png" return dict( image = image ) ###---------------------------------------------------------------------------------------------------### class Interruption_1(Page): form_model='player' form_fields =['interruptionResponse'] timeout_seconds = 30 def is_displayed(self): player = self.player return player.showScreen and player.showInterruption def vars_for_template(self): player = self.player if player.timeOnInterruption == 0: import time player.timeOnInterruption = time.time() return dict( message = player.participant.vars['emailMessages'][0], response=player.participant.vars['emailResponse'][0] ) def before_next_page(self): player = self.player import time player.timeOnInterruption = round(time.time() - player.timeOnInterruption, 2) if player.interruptionResponse == player.participant.vars['emailResponse'][0]: player.participant.vars['earningFromInterruptions_2'] += 1 del player.participant.vars['emailMessages'][0] del player.participant.vars['emailResponse'][0] ###---------------------------------------------------------------------------------------------------### class Task_Interruption_2(Page): form_model='player' form_fields =['barcodeInput'] timeout_seconds = 40 def is_displayed(self): player = self.player return player.showScreen and player.showInterruption def vars_for_template(self): player = self.player x = player.barcodeThisRound image = "task/"+ str(x) +".png" return dict( image = image ) def before_next_page(self): player = self.player import time current_time = time.time() duration = (current_time - player.timePlaceholder) - player.timeOnInterruption player.timeThisRound = round(duration, 2) userInput = player.barcodeInput answerKey = Constants.correctArray[ player.barcodeThisRound ] player.actualCorrectAnswer = answerKey player.mistakesThisRound, player.correctsThisRound = player.CountMistakes(userInput, answerKey) player.participant.vars['mistakesTally_second'] += player.mistakesThisRound player.participant.vars['correctsTally_second'] += player.correctsThisRound pos = player.correctsThisRound * Constants.piece_rate neg = player.mistakesThisRound * Constants.penalty_rate player.earningThisRound = round(( pos - neg),2) player.participant.vars['earningFromTask_second'] += round(( pos - neg),2) player.participant.vars['earningFromTask_second'] = round(player.participant.vars['earningFromTask_second'], 2) player.correctsTally = player.participant.vars['correctsTally_second'] player.mistakesTally = player.participant.vars['mistakesTally_second'] player.earningFromTask = player.participant.vars['earningFromTask_second'] player.actualCorrectAnswer = 'C' + player.actualCorrectAnswer player.barcodeInput = 'B' + player.barcodeInput page_sequence = [Task, Task_Interruption_1, Interruption_1, Task_Interruption_2]