from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants from otree.api import Currency as c, currency_range from ._builtin import Page from .models import Constants import datetime, json, time import random import math import numpy as np #change to 4: def paying_round(): #choice3 = 2 choice3 = random.randint(1, 4) return choice3 def treatment_order(): ord = [3, 2, 1] #random.shuffle(ord) return ord #to tell if podcast is useful or not: def podcast_announce(): yes = random.randint(0, 1) return yes nonogram = [ [[["2 1 1 1","1 1","1 2 3","2 6","1 1 1 1","1 2 1 1","4 5","1 2 2","4 1 1","1 5"], ["1 1 4","1 1 1 2","2 2 1","3 3 2","1 3","5 1","4 1 1","2 2 2","3 2","1 1 3"]], [["2 1 2","2 5","3 1 1","2","1 4 1","3 3 1","1 5 2","1 1 1","5 2","1 2 1"], ["3 2 1","3 1 2","1 3 1","1 1 1","3 3 2","1 6","2 3","5 2","1 3","3"]], [["1 2","1 1 1","1 7","4 1 2","1 1 2 1","2 1","1 1 1 1","5 2 1","1 2 2","1 1 1 2"], ["2 1 1","2 3","3 1 1 1","7","1 2","3 1 1","3 2","1 1 1","1 5 2","2 1 2"]]], #round 1 [[["1 1 1 3", "1 4 2", "3 1 2", "1 1 6", "1 1 1", "1 1", "1 4 2", "2 1 2", "5 1 1", "1 2"], ["2 1 1", "1 3", "1 4 3", "2 1 1", "1 1 3", "4 1 1", "1 1 4", "1 2 1", "4 2 1", "5 1"]], [["1 4 1", "5 1", "1 3", "4 3 1", "1 1 1 1 1", "1 2 2", "1 1 5", "2 1 1 1", "5 1 1", "1 2 1"], ["2 2 3", "1 1 4", "2 2 1", "4 1 1", "2 1 2", "1 2 3 1", "5 1", "1 2 2", "3 1", "1 1 3 1"]], [["1 1 1 1","2 1 2","2 2","2 4 1","1 2 1","2 3 1","2 7","1 1 2","2 2","2 3"], ["1 1 2","3 2 2","6 3","1 1","1 2","1 2 1","1 1 2 1","1 1 4","2 3","7"]]], #round 2 [[["1 1 2 1","3 3 1","7 1","1 2 1","1 1 2","3 2","2 2 1","3 1 4","3 1 3","2 3 1"], ["2 1 3","3 4","2 1 3","1 2 1 1","2 1 3","2 2 1","6 1 1","1 2 3","1 3","1 2 3"]], [["5 2","1 1 1","1 4 2","4 2","2 2","1 1 2","1 2 1 3","3 1 1","2 2 3","1 4"], ["2 1 1","1 3 2","1 2 2","1 2 5","1 2 1","2 1 1","4 1 1","1 2 1 2","3 5","1 2 1"]], [["1 2 1","2 1","3 1 1","1 1","2 2 2","2 1 2 2","4 1","1 2 3","1 1 2 1","2 3 2"], ["5 1","1 1 3 2","1 1","2 6","2 1 1 1","1 1 2","4 2","1 1 1","1 1 3 1","1 2"]]] #round 3 ] nonogram_sol = [ [[[1, 1, 0, 1, 0, 0, 1, 0, 0, 1], [0, 0, 0, 1, 0, 0, 1, 0, 0, 0], [1, 0, 1, 1, 0, 0, 1, 1, 1, 0], [0, 1, 1, 0, 1, 1, 1, 1, 1, 1], [1, 0, 0, 1, 0, 1, 0, 0, 1, 0], [1, 0, 1, 1, 0, 1, 0, 1, 0, 0], [1, 1, 1, 1, 0, 1, 1, 1, 1, 1], [1, 0, 0, 0, 1, 1, 0, 0, 1, 1], [0, 1, 1, 1, 1, 0, 0, 1, 0, 1], [0, 1, 0, 1, 1, 1, 1, 1, 0, 0]], [[1, 1, 0, 0, 1, 0, 1, 1, 0, 0], [1, 1, 0, 1, 1, 1, 1, 1, 0, 0], [1, 1, 1, 0, 1, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 1, 0], [0, 0, 1, 0, 1, 1, 1, 1, 0, 1], [1, 1, 1, 0, 1, 1, 1, 0, 0, 1], [1, 0, 1, 1, 1, 1, 1, 0, 1, 1], [0, 1, 0, 0, 0, 1, 0, 0, 1, 0], [0, 1, 1, 1, 1, 1, 0, 1, 1, 0], [1, 0, 0, 0, 1, 1, 0, 1, 0, 0]], [[0, 0, 0, 0, 0, 1, 0, 0, 1, 1], [0, 0, 1, 0, 0, 1, 0, 0, 0, 1], [1, 0, 1, 1, 1, 1, 1, 1, 1, 0],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[56, 54, 51], [54, 59, 52], [57, 55, 50]] nono_gray = [[44, 46, 49], [46, 41, 48], [43, 45, 50]] adding_numbers = [ [[61, 49, 34, 35, 19, 24, 28, 46, 36, 26], [58, 24, 36, 37, 43, 26, 44, 11, 19, 14], [82, 16, 29, 43, 57, 39, 31, 35, 56, 13], [74, 23, 47, 43, 48, 56, 28, 57, 49, 25], [51, 26, 24, 35, 14, 34, 23, 39, 22, 17], [74, 62, 16, 37, 9, 23, 51, 59, 52, 17], [62, 13, 23, 17, 31, 33, 15, 48, 49, 46], [87, 13, 32, 18, 25, 34, 73, 65, 74, 29], [86, 34, 12, 15, 13, 61, 53, 52, 75, 57], [79, 35, 52, 45, 12, 64, 17, 38, 44, 11]], #no distraction [[78, 46, 13, 67, 65, 25, 34, 15, 47, 62], [68, 15, 42, 29, 27, 41, 19, 23, 36, 33], [76, 51, 48, 11, 47, 15, 65, 39, 35, 63], [91, 75, 69, 44, 64, 16, 35, 62, 33, 49], [93, 65, 58, 32, 79, 77, 31, 71, 76, 17], [91, 69, 25, 17, 55, 26, 13, 75, 22, 72], [55, 21, 17, 33, 26, 9, 41, 27, 34, 23], [68, 16, 17, 49, 14, 22, 41, 57, 19, 21], [84, 41, 72, 46, 26, 48, 35, 32, 49, 28], [85, 23, 54, 72, 42, 62, 49, 58, 38, 69]], #podcast [[94, 27, 52, 69, 78, 68, 22, 57, 55, 39], [86, 12, 38, 27, 24, 28, 51, 25, 58, 54], [89, 55, 12, 23, 14, 72, 48, 66, 33, 68], [62, 23, 29, 15, 38, 14, 36, 24, 17, 28], [84, 17, 55, 68, 43, 39, 59, 46, 25, 37], [58, 42, 39, 25, 13, 34, 14, 16, 36, 41], [54, 36, 19, 15, 11, 39, 28, 38, 23, 27], [98, 87, 9, 86, 82, 21, 89, 15, 17, 43], [61, 28, 19, 38, 46, 15, 34, 24, 9, 44], [97, 44, 12, 32, 53, 66, 41, 15, 79, 71]] ] class introduction_multitasking(Page): form_model = 'player' def vars_for_template(self): self.player.paying_round = paying_round() self.player.podcast_announce = podcast_announce() self.participant.vars['paying_round'] = self.player.paying_round self.participant.vars['podcast_announce'] = self.player.podcast_announce self.participant.vars['treatment_order'] = treatment_order() self.player.treatment_order = ', '.join(str(e) for e in self.player.participant.vars['treatment_order']) self.participant.vars['round1_nonogram'] = nonogram[0] self.participant.vars['round1_nonogram_sol'] = nonogram_sol[0] self.participant.vars['round1_nonogram_green'] = nono_green[0] self.participant.vars['round1_nonogram_gray'] = nono_gray[0] self.participant.vars['round1_adding_numbers'] = adding_numbers[0] self.participant.vars['round2_nonogram'] = nonogram[1] self.participant.vars['round2_nonogram_sol'] = nonogram_sol[1] self.participant.vars['round2_nonogram_green'] = nono_green[1] self.participant.vars['round2_nonogram_gray'] = nono_gray[1] self.participant.vars['round2_adding_numbers'] = adding_numbers[1] self.participant.vars['round3_nonogram'] = nonogram[2] self.participant.vars['round3_nonogram_sol'] = nonogram_sol[2] self.participant.vars['round3_nonogram_green'] = nono_green[2] self.participant.vars['round3_nonogram_gray'] = nono_gray[2] self.participant.vars['round3_adding_numbers'] = adding_numbers[2] return dict( paying_round=self.player.paying_round, treatment_order=self.participant.vars['treatment_order'], ) class bank_account(Page): form_model = 'player' form_fields = ['bank_account'] class disclaimer(Page): form_model = 'player' class pre_questionnaire(Page): form_model = 'player' def is_displayed(self): return self.round_number == 1 class questionnaire1(Page): form_model = 'player' form_fields = ['h2', 'h10', 'h13', 'h16', 'h20', 'h23'] def is_displayed(self): return self.round_number == 1 class questionnaire2(Page): form_model = 'player' form_fields = ['h3', 'h5', 'h9', 'h17', 'h21', 'h24'] def is_displayed(self): return self.round_number == 1 class questionnaire3(Page): form_model = 'player' form_fields = ['h1', 'h6', 'h7', 'h12', 'h18', 'h22', 'h25'] def is_displayed(self): return self.round_number == 1 class questionnaire4(Page): form_model = 'player' form_fields = ['h4', 'h8', 'h11', 'h14', 'h15', 'h19', 'h26', 'h27'] def is_displayed(self): return self.round_number == 1 class general_instructions(Page): form_model = 'player' def before_next_page(self): self.participant.vars['sssss'] = time.time() a =[[ ["1 1 1","1 2 1 1","2 2 1","1 6","1 2 1 2","3 3 2","2 1 1","3 2 1","1 2 2 1","2 1 1 2"], ["2 5","2 3 1","3 2 3","1 2 1","2 1 1 1","2 3","2 3 2","2 1 1","3 1","1 2 3"] ]] a_sol = [[ [1, 0, 1, 0, 0, 0, 1, 0, 0, 0], [1, 0, 1, 1, 0, 0, 1, 0, 0, 1], [0, 1, 1, 0, 1, 1, 0, 1, 0, 0], [0, 1, 0, 1, 1, 1, 1, 1, 1, 0], [1, 0, 1, 1, 0, 0, 1, 0, 1, 1], [1, 1, 1, 0, 1, 1, 1, 0, 1, 1], [1, 1, 0, 0, 0, 1, 0, 1, 0, 0], [1, 1, 1, 0, 1, 1, 0, 0, 0, 1], [1, 0, 1, 1, 0, 0, 1, 1, 0, 1], [0, 1, 1, 0, 1, 0, 1, 0, 1, 1], ]] green = 56 gray = 44 class practice_game(Page): form_model = 'player' timeout_seconds = 600 form_fields = ['points', 'total_wrong', 'total_right', 'wrong_green', 'wrong_gray', 'right_green', 'right_gray', 'time_between_moves', 'board_history', 'solve_order', 'total_green', 'total_gray', 'game_finished'] def vars_for_template(player): player.participant.vars['a'] = a player.participant.vars['a_sol'] = a_sol for i in range(1, 4): if player.round_number == i: player.participant.vars['game_number'] = i player.participant.vars['row'] = player.participant.vars['a'][i-1][0] player.participant.vars['column'] = player.participant.vars['a'][i-1][1] player.participant.vars['solution_0'] = player.participant.vars['a_sol'][i-1][0] player.participant.vars['solution_1'] = player.participant.vars['a_sol'][i-1][1] player.participant.vars['solution_2'] = player.participant.vars['a_sol'][i-1][2] player.participant.vars['solution_3'] = player.participant.vars['a_sol'][i-1][3] player.participant.vars['solution_4'] = player.participant.vars['a_sol'][i-1][4] player.participant.vars['solution_5'] = player.participant.vars['a_sol'][i-1][5] player.participant.vars['solution_6'] = player.participant.vars['a_sol'][i-1][6] player.participant.vars['solution_7'] = player.participant.vars['a_sol'][i-1][7] player.participant.vars['solution_8'] = player.participant.vars['a_sol'][i-1][8] player.participant.vars['solution_9'] = player.participant.vars['a_sol'][i-1][9] player.participant.vars['total_green'] = green player.participant.vars['total_gray'] = gray return dict( game_number=player.participant.vars['game_number'], r=[player.participant.vars['row'][h] for h in range(0, 10)], c=[player.participant.vars['column'][h] for h in range(0, 10)], sol_0=[player.participant.vars['solution_0'][h] for h in range(0, 10)], sol_1=[player.participant.vars['solution_1'][h] for h in range(0, 10)], sol_2=[player.participant.vars['solution_2'][h] for h in range(0, 10)], sol_3=[player.participant.vars['solution_3'][h] for h in range(0, 10)], sol_4=[player.participant.vars['solution_4'][h] for h in range(0, 10)], sol_5=[player.participant.vars['solution_5'][h] for h in range(0, 10)], sol_6=[player.participant.vars['solution_6'][h] for h in range(0, 10)], sol_7=[player.participant.vars['solution_7'][h] for h in range(0, 10)], sol_8=[player.participant.vars['solution_8'][h] for h in range(0, 10)], sol_9=[player.participant.vars['solution_9'][h] for h in range(0, 10)], total_green=player.participant.vars['total_green'], total_gray=player.participant.vars['total_gray'], ) def js_vars(player): if player.round_number == 1: return { 'total_green': player.participant.vars['total_green'], 'total_gray': player.participant.vars['total_gray'], } def before_next_page(self): self.participant.vars['points'] = self.player.points self.player.time_spent = math.floor(time.time() - self.participant.vars['sssss']) class finish_practice(Page): form_model = 'player' class general_instructions_adding(Page): form_model = 'player' practice = [ [94, 31, 56, 71, 72, 62, 16, 42, 63, 39], [88, 19, 22, 55, 35, 24, 23, 64, 76, 49], [79, 44, 12, 34, 21, 52, 13, 27, 57, 68], ] class practice_game_adding1(Page): form_model = 'player' form_fields = ['correct_adding1'] timeout_seconds = 60 def vars_for_template(self): self.participant.vars['set'] = practice return dict( n=[self.participant.vars['set'][0][h] for h in range(0, 10)], ) def js_vars(self): return { 'n': [self.participant.vars['set'][0][h] for h in range(0, 10)], } class practice_game_adding2(Page): form_model = 'player' form_fields = ['correct_adding2'] timeout_seconds = 60 def vars_for_template(self): self.participant.vars['set'] = practice return dict( n=[self.participant.vars['set'][1][h] for h in range(0, 10)], ) def js_vars(self): return { 'n': [self.participant.vars['set'][1][h] for h in range(0, 10)], } class practice_game_adding3(Page): form_model = 'player' form_fields = ['correct_adding3'] timeout_seconds = 60 def vars_for_template(self): self.participant.vars['set'] = practice return dict( n=[self.participant.vars['set'][2][h] for h in range(0, 10)], ) def js_vars(self): return { 'n': [self.participant.vars['set'][2][h] for h in range(0, 10)], } class finish_practice_adding(Page): form_model = 'player' class instructions_earnings(Page): form_model = 'player' def app_after_this_page(self, upcoming_apps): if self.participant.vars['treatment_order'][0] == 1: return 'multitasking_no_distraction' if self.participant.vars['treatment_order'][0] == 2: return 'multitasking_podcast' else: return 'multitasking_interruption_forced' page_sequence = [ introduction_multitasking, bank_account, pre_questionnaire, questionnaire1, questionnaire2, questionnaire3, questionnaire4, general_instructions, practice_game, finish_practice, general_instructions_adding, practice_game_adding1, practice_game_adding2, practice_game_adding3, finish_practice_adding, instructions_earnings, ]