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 def treatment_order(): ord = [1, 2] #random.shuffle(ord) return ord # # def game_order(): # choice1 = [1, 2, 3] # random.shuffle(choice1) # return choice1 # # def paying_round(): # choice3 = random.randint(1, 2) # return choice3 # class introduction_multitasking(Page): form_model = 'player' class disclaimer(Page): form_model = 'player' class general_instructions(Page): form_model = 'player' def before_next_page(self): self.participant.vars['sssss'] = time.time() a =[[ ["1 2", "4 2 1", "1 4 2", "2 4", "1 1 1", "1 5 1", "1 1 1 1", "1 3 1 1", "1 2 1 2", "3 1 2"], ["2 3 1", "1 1 2", "4 1 1", "3 4", "1 2 3", "3 3", "2 1 1 1", "1 2 1", "3 2", "3 1 2"] ]] a_sol = [[ [0, 1, 1, 1, 1, 0, 0, 0, 1, 0], [1, 0, 1, 0, 0, 1, 0, 1, 1, 0], [0, 0, 0, 1, 0, 1, 1, 1, 0, 0], [1, 0, 0, 1, 1, 0, 1, 1, 0, 0], [0, 0, 0, 1, 1, 0, 1, 1, 1, 1], [1, 1, 1, 0, 1, 1, 1, 0, 1, 0], [1, 1, 1, 1, 0, 0, 0, 0, 1, 0], [1, 0, 0, 1, 1, 0, 0, 1, 1, 1], [1, 0, 1, 0, 1, 1, 1, 1, 1, 0], [1, 0, 0, 0, 1, 1, 1, 0, 0, 1] ]] #As practice game: # a =[[ # ["1 3 1", "1 1 1 2", "1 1", "5 1 2", "1 1 3", "2 3 1", "2 2 1", "3 1 2", "2 4", "3 3 1"], # ["2 2 1", "1 5", "1 1 5", "2 1", "3 2 1", "1 5", "1 3 2", "2 1 1 1", "5 3", "1 1 1"] #as practice game on Prolific # # ]] # # # a_sol = [[ # [1, 0, 0, 0, 0, 1, 1, 1, 0, 1], # [1, 0, 1, 0, 1, 0, 0, 1, 1, 0], # [0, 0, 0, 0, 1, 0, 0, 0, 1, 0], # [1, 1, 1, 1, 1, 0, 1, 0, 1, 1], # [1, 0, 0, 1, 0, 0, 1, 1, 1, 0], # [0, 1, 1, 0, 1, 1, 1, 0, 1, 0], # [0, 1, 1, 0, 1, 1, 0, 1, 0, 0], # [0, 1, 1, 1, 0, 1, 0, 0, 1, 1], # [0, 1, 1, 0, 0, 1, 1, 1, 1, 0], # [1, 1, 1, 0, 1, 1, 1, 0, 1, 0] # # ]] # green = 52 gray = 48 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'] def vars_for_template(player): for i in range(1, 4): if player.round_number == i: player.participant.vars['game_number'] = i player.participant.vars['row'] = a[i-1][0] player.participant.vars['column'] = a[i-1][1] player.participant.vars['solution_0'] = a_sol[i-1][0] player.participant.vars['solution_1'] = a_sol[i-1][1] player.participant.vars['solution_2'] = a_sol[i-1][2] player.participant.vars['solution_3'] = a_sol[i-1][3] player.participant.vars['solution_4'] = a_sol[i-1][4] player.participant.vars['solution_5'] = a_sol[i-1][5] player.participant.vars['solution_6'] = a_sol[i-1][6] player.participant.vars['solution_7'] = a_sol[i-1][7] player.participant.vars['solution_8'] = a_sol[i-1][8] player.participant.vars['solution_9'] = 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 results(Page): form_model = 'player' class finish_practice(Page): form_model = 'player' class instructions_earnings(Page): form_model = 'player' #def before_next_page(self): #self.participant.vars['game_order'] = game_order() #self.player.game_order = ', '.join(str(e) for e in self.participant.vars['game_order']) #self.player.paying_round = paying_round() #self.participant.vars['paying_round'] = self.player.paying_round page_sequence = [ introduction_multitasking, disclaimer, general_instructions, practice_game, finish_practice, instructions_earnings, ]