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["ipts_total_time"] = 0 timeSinceStart = (current_time - player.in_round(1).timePlaceholder) player.showScreen = (timeSinceStart < Constants.allowedTime + player.participant.vars["ipts_total_time"]) or (self.round_number <= 30) if player.showScreen: try: import random x = random.choice(player.participant.vars['mainList']) player.barcodeThisRound = x (player.participant.vars['mainList']).remove(x) except: player.showScreen = False if player.participant.vars['whichHalf'] == 2: for i in player.participant.vars['ipts_list']: if i <= timeSinceStart <= (i + 65): (player.participant.vars['ipts_list']).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, rn = self.round_number + player.participant.vars['rn'] ) 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'] += player.mistakesThisRound player.participant.vars['correctsTally'] += player.correctsThisRound player.participant.vars['mistakesTallyLast'] += player.mistakesThisRound player.participant.vars['correctsTallyLast'] += player.correctsThisRound pos = player.correctsThisRound * Constants.piece_rate neg = player.mistakesThisRound * Constants.penalty_rate player.earningThisRound = round(( pos - neg),2) player.participant.vars['earningFromTask'] += round(( pos - neg),2) player.participant.vars['earningFromTask'] = round(player.participant.vars['earningFromTask'], 2) pos_alt = player.correctsThisRound * Constants.piece_rate_alt neg_alt = player.mistakesThisRound * Constants.penalty_rate_alt player.participant.vars['earningFromTask_alt'] += round(( pos_alt - neg_alt),2) player.participant.vars['earningFromTask_alt'] = round(player.participant.vars['earningFromTask_alt'], 2) player.correctsTally = player.participant.vars['correctsTally'] player.mistakesTally = player.participant.vars['mistakesTally'] player.earningFromTask = player.participant.vars['earningFromTask'] player.earningFromTask_alt = player.participant.vars['earningFromTask_alt'] # intervals if (current_time - player.in_round(1).timePlaceholder) <= ((10 * Constants.unit) + player.participant.vars["ipts_total_time"]): player.participant.vars['interval4'] = self.round_number player.participant.vars["barcodesInterval4"] = player.participant.vars['interval4'] player.participant.vars['error4'] = player.participant.vars['mistakesTally'] player.participant.vars["errorInterval4"] = player.participant.vars['error4'] player.participant.vars['correct4'] = player.participant.vars['correctsTally'] player.participant.vars["correctInterval4"] = player.participant.vars['correct4'] elif (current_time - player.in_round(1).timePlaceholder) <= ((20 * Constants.unit) + player.participant.vars["ipts_total_time"]): player.participant.vars['interval5'] = self.round_number player.participant.vars["barcodesInterval5"] = player.participant.vars['interval5'] - player.participant.vars['interval4'] player.participant.vars['error5'] = player.participant.vars['mistakesTally'] player.participant.vars["errorInterval5"] = player.participant.vars['error5'] - player.participant.vars['error4'] player.participant.vars['correct5'] = player.participant.vars['correctsTally'] player.participant.vars["correctInterval5"] = player.participant.vars['correct5'] - player.participant.vars['correct4'] else: player.participant.vars['interval6'] = self.round_number player.participant.vars["barcodesInterval6"] = player.participant.vars['interval6'] - player.participant.vars['interval5'] player.participant.vars['error6'] = player.participant.vars['mistakesTally'] player.participant.vars["errorInterval6"] = player.participant.vars['error6'] - player.participant.vars['error5'] player.participant.vars['correct6'] = player.participant.vars['correctsTally'] player.participant.vars["correctInterval6"] = player.participant.vars['correct6'] - player.participant.vars['correct5'] 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 image = "task/"+ str( player.barcodeThisRound ) +".png" return dict( image = image, rn = self.round_number + player.participant.vars['rn'] ) ###---------------------------------------------------------------------------------------------------### 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) player.participant.vars["ipts_total_time"] += player.timeOnInterruption if player.interruptionResponse == player.participant.vars['emailResponse'][0]: player.participant.vars['earningFromInterruptions'] += 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, ex = player.participant.vars['earningFromInterruptions'], rn = self.round_number + player.participant.vars['rn'] ) 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'] += player.mistakesThisRound player.participant.vars['correctsTally'] += player.correctsThisRound player.participant.vars['mistakesTallyLast'] += player.mistakesThisRound player.participant.vars['correctsTallyLast'] += player.correctsThisRound pos = player.correctsThisRound * Constants.piece_rate neg = player.mistakesThisRound * Constants.penalty_rate player.earningThisRound = round(( pos - neg),2) player.participant.vars['earningFromTask'] += round(( pos - neg),2) player.participant.vars['earningFromTask'] = round(player.participant.vars['earningFromTask'], 2) pos_alt = player.correctsThisRound * Constants.piece_rate_alt neg_alt = player.mistakesThisRound * Constants.penalty_rate_alt player.participant.vars['earningFromTask_alt'] += round(( pos_alt - neg_alt),2) player.participant.vars['earningFromTask_alt'] = round(player.participant.vars['earningFromTask_alt'], 2) player.correctsTally = player.participant.vars['correctsTally'] player.mistakesTally = player.participant.vars['mistakesTally'] player.earningFromTask = player.participant.vars['earningFromTask'] player.earningFromTask_alt = player.participant.vars['earningFromTask_alt'] # intervals if (current_time - player.in_round(1).timePlaceholder) <= ((10 * Constants.unit) + player.participant.vars["ipts_total_time"]): player.participant.vars['interval4'] = self.round_number player.participant.vars["barcodesInterval4"] = player.participant.vars['interval4'] player.participant.vars['error4'] = player.participant.vars['mistakesTally'] player.participant.vars["errorInterval4"] = player.participant.vars['error4'] player.participant.vars['correct4'] = player.participant.vars['correctsTally'] player.participant.vars["correctInterval4"] = player.participant.vars['correct4'] elif (current_time - player.in_round(1).timePlaceholder) <= ((20 * Constants.unit) + player.participant.vars["ipts_total_time"]): player.participant.vars['interval5'] = self.round_number player.participant.vars["barcodesInterval5"] = player.participant.vars['interval5'] - player.participant.vars['interval4'] player.participant.vars['error5'] = player.participant.vars['mistakesTally'] player.participant.vars["errorInterval5"] = player.participant.vars['error5'] - player.participant.vars['error4'] player.participant.vars['correct5'] = player.participant.vars['correctsTally'] player.participant.vars["correctInterval5"] = player.participant.vars['correct5'] - player.participant.vars['correct4'] else: player.participant.vars['interval6'] = self.round_number player.participant.vars["barcodesInterval6"] = player.participant.vars['interval6'] - player.participant.vars['interval5'] player.participant.vars['error6'] = player.participant.vars['mistakesTally'] player.participant.vars["errorInterval6"] = player.participant.vars['error6'] - player.participant.vars['error5'] player.participant.vars['correct6'] = player.participant.vars['correctsTally'] player.participant.vars["correctInterval6"] = player.participant.vars['correct6'] - player.participant.vars['correct5'] player.actualCorrectAnswer = 'C' + player.actualCorrectAnswer player.barcodeInput = 'B' + player.barcodeInput page_sequence = [Task, Task_Interruption_1, Interruption_1, Task_Interruption_2]