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 import sys def interruption_time(): #test = [595, 590, 585, 580, 575, 570, 565, 560, 555, 550] test = [580, 537, 483, 455, 400, 352, 285, 215, 143, 100] return test # inter = np.sort(np.random.randint(10, 590, size=8)) # this_number = inter[0:7] # next_number = inter[1:8] # difference = next_number - this_number # while np.all(difference > 10) == False: # inter = np.sort(np.random.randint(10, 590, size=8)) # this_number = inter[0:7] # next_number = inter[1:8] # difference = next_number - this_number # inter = -np.sort(-inter) # inter = np.ndarray.tolist(inter) # return inter class Instructions(Page): form_model = 'player' #timeout_seconds = 120 def vars_for_template(player): player.participant.vars['interruption_time'] = interruption_time() if player.participant.vars['treatment_order'][0] == 1 and player.participant.vars['treatment_order'][1] == 2: player.participant.vars['round'] = 2 player.participant.vars['nonogram'] = player.participant.vars['round2_nonogram'] player.participant.vars['nonogram_sol'] = player.participant.vars['round2_nonogram_sol'] player.participant.vars['nonogram_green'] = player.participant.vars['round2_nonogram_green'] player.participant.vars['nonogram_gray'] = player.participant.vars['round2_nonogram_gray'] player.participant.vars['adding_numbers'] = player.participant.vars['round2_adding_numbers'] if player.participant.vars['treatment_order'][0] == 2 and player.participant.vars['treatment_order'][1] == 1: player.participant.vars['round'] = 1 player.participant.vars['nonogram'] = player.participant.vars['round1_nonogram'] player.participant.vars['nonogram_sol'] = player.participant.vars['round1_nonogram_sol'] player.participant.vars['nonogram_green'] = player.participant.vars['round1_nonogram_green'] player.participant.vars['nonogram_gray'] = player.participant.vars['round1_nonogram_gray'] player.participant.vars['adding_numbers'] = player.participant.vars['round1_adding_numbers'] return dict( round=player.participant.vars['round'], ) def js_vars(self): return { 'round': self.participant.vars['round'], } def before_next_page(self): self.participant.vars['start_game1'] = time.time() class Game1(Page): form_model = 'player' form_fields = ['gap_history1', 'points1', 'total_wrong1', 'total_right1', 'wrong_green1', 'wrong_gray1', 'score_on_display1', 'right_green1', 'right_gray1', 'time_between_moves1', 'board_history1', 'solve_order1', 'game1_finished'] timeout_seconds = 600+60*10 def vars_for_template(player): player.participant.vars['game_number'] = 1 player.participant.vars['row'] = player.participant.vars['nonogram'][player.participant.vars['game_number']-1][0] player.participant.vars['column'] = player.participant.vars['nonogram'][player.participant.vars['game_number']-1][1] player.participant.vars['solution_0'] = player.participant.vars['nonogram_sol'][player.participant.vars['game_number']-1][0] player.participant.vars['solution_1'] = player.participant.vars['nonogram_sol'][player.participant.vars['game_number']-1][1] player.participant.vars['solution_2'] = player.participant.vars['nonogram_sol'][player.participant.vars['game_number']-1][2] player.participant.vars['solution_3'] = player.participant.vars['nonogram_sol'][player.participant.vars['game_number']-1][3] player.participant.vars['solution_4'] = player.participant.vars['nonogram_sol'][player.participant.vars['game_number']-1][4] player.participant.vars['solution_5'] = player.participant.vars['nonogram_sol'][player.participant.vars['game_number']-1][5] player.participant.vars['solution_6'] = player.participant.vars['nonogram_sol'][player.participant.vars['game_number']-1][6] player.participant.vars['solution_7'] = player.participant.vars['nonogram_sol'][player.participant.vars['game_number']-1][7] player.participant.vars['solution_8'] = player.participant.vars['nonogram_sol'][player.participant.vars['game_number']-1][8] player.participant.vars['solution_9'] = player.participant.vars['nonogram_sol'][player.participant.vars['game_number']-1][9] player.participant.vars['set1'] = player.participant.vars['adding_numbers'] return dict( #round_number=player.participant.vars['round_number'], 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)], n=[player.participant.vars['set1'][j]for j in range(0, 10)], interruption_time=player.participant.vars['interruption_time'], ) def js_vars(self): return { 'score': 0, 'n': [self.participant.vars['set1'][h] for h in range(0, 10)], 'interruption_time': self.participant.vars['interruption_time'], } def before_next_page(self): self.participant.vars['score_on_display1'] = self.player.score_on_display1 self.participant.vars['score_on_display'] = self.player.score_on_display1 self.player.time_spent_total1 = math.floor(time.time() - self.participant.vars['start_game1']) self.participant.vars['time_spent_total1'] = self.player.time_spent_total1 hist = self.player.gap_history1 hist1 = hist.split(',') hist1 = hist1[1:] #hist1 = [i for i in hist1 if int(i)!=0] self.participant.vars['gap_history1'] = [int(i) for i in hist1] self.player.gap_history1 = ', '.join(str(e) for e in self.participant.vars['gap_history1']) self.participant.vars['gap_history'] = [int(i) for i in hist1] self.player.total_green1 = self.participant.vars['nonogram_green'][self.participant.vars['game_number']-1] self.player.total_gray1 = self.participant.vars['nonogram_gray'][self.participant.vars['game_number']-1] self.player.interruption_time = ', '.join(str(e) for e in interruption_time()) class blank1(Page): form_model = 'player' timeout_seconds = 0.5 def vars_for_template(player): def time_spent_nono(): length = len(player.participant.vars['gap_history1']) interruption_time1 = player.participant.vars['interruption_time'][0:length] interruption_time2 = player.participant.vars['interruption_time'][length:11] time_spent_nono1 = player.participant.vars['time_spent_total1'] - np.sum(player.participant.vars['gap_history1'][0:]) timer_game2 = 600 - time_spent_nono1 return time_spent_nono1, timer_game2, interruption_time2, interruption_time1 time_spent_nono = time_spent_nono() player.participant.vars['time_spent_nono1'] = time_spent_nono[0] player.participant.vars['timer_game2'] = time_spent_nono[1] player.participant.vars['interruption_time2'] = time_spent_nono[2] player.participant.vars['interruption_time1'] = time_spent_nono[3] return dict( gap_history1=player.participant.vars['gap_history1'], time_spent_nono1=player.participant.vars['time_spent_nono1'], timer_game2=player.participant.vars['timer_game2'], interruption_time1=player.participant.vars['interruption_time1'], interruption_time2=player.participant.vars['interruption_time2'], ) def before_next_page(self): if int(self.player.participant.vars['timer_game2']) > 0: self.player.time_spent_nono1 = float(self.player.participant.vars['time_spent_nono1']) self.player.interruption_time1 = ', '.join(str(e) for e in self.player.participant.vars['interruption_time1']) self.player.interruption_time2 = ', '.join(str(e) for e in self.player.participant.vars['interruption_time2']) self.player.participant.vars['start_game2'] = time.time() if int(self.player.participant.vars['timer_game2']) <= 3: hist = self.participant.vars['gap_history'] total_wrong_adding_forced = 0 # CHANGE TO 5 FOR REAL GAME!!!!!!!!!!! 5 INTERRUPTIONS!!!!!!!!!! for i in range(0, 10): if hist[i] >= 60: total_wrong_adding_forced = total_wrong_adding_forced + 1 self.player.total_wrong_adding_forced = total_wrong_adding_forced self.player.participant.vars['total_wrong_adding_forced'] = self.player.total_wrong_adding_forced self.player.participant.vars['final_points_forced'] = self.player.participant.vars['score_on_display'] - total_wrong_adding_forced * 5 self.player.participant.vars['timer_game3'] = 0 class Game2(Page): form_model = 'player' form_fields = ['gap_history2', 'points2', 'total_wrong2', 'total_right2', 'wrong_green2', 'wrong_gray2', 'score_on_display2', 'right_green2', 'right_gray2', 'time_between_moves2', 'board_history2', 'solve_order2', 'game2_finished'] def get_timeout_seconds(self): return int(self.player.participant.vars['timer_game2'] + 60*10) def is_displayed(self): return int(self.player.participant.vars['timer_game2']) > 3 def vars_for_template(player): player.participant.vars['game_number'] = 2 player.participant.vars['row'] = player.participant.vars['nonogram'][player.participant.vars['game_number']-1][0] player.participant.vars['column'] = player.participant.vars['nonogram'][player.participant.vars['game_number']-1][1] player.participant.vars['solution_0'] = player.participant.vars['nonogram_sol'][player.participant.vars['game_number']-1][0] player.participant.vars['solution_1'] = player.participant.vars['nonogram_sol'][player.participant.vars['game_number']-1][1] player.participant.vars['solution_2'] = player.participant.vars['nonogram_sol'][player.participant.vars['game_number']-1][2] player.participant.vars['solution_3'] = player.participant.vars['nonogram_sol'][player.participant.vars['game_number']-1][3] player.participant.vars['solution_4'] = player.participant.vars['nonogram_sol'][player.participant.vars['game_number']-1][4] player.participant.vars['solution_5'] = player.participant.vars['nonogram_sol'][player.participant.vars['game_number']-1][5] player.participant.vars['solution_6'] = player.participant.vars['nonogram_sol'][player.participant.vars['game_number']-1][6] player.participant.vars['solution_7'] = player.participant.vars['nonogram_sol'][player.participant.vars['game_number']-1][7] player.participant.vars['solution_8'] = player.participant.vars['nonogram_sol'][player.participant.vars['game_number']-1][8] player.participant.vars['solution_9'] = player.participant.vars['nonogram_sol'][player.participant.vars['game_number']-1][9] player.participant.vars['set1'] = player.participant.vars['adding_numbers'] 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)], n=[player.participant.vars['set1'][j]for j in range(0, 10)], interruption_time=player.participant.vars['interruption_time'], interruption_time2=player.participant.vars['interruption_time2'], ) def js_vars(self): return { 'gap_history1': self.participant.vars['gap_history1'], 'timer_game2': int(self.player.participant.vars['timer_game2']), 'score': self.participant.vars['score_on_display1'], 'n': [self.participant.vars['set1'][h] for h in range(0, 10)], 'interruption_time': self.participant.vars['interruption_time'], } def before_next_page(self): self.participant.vars['score_on_display2'] = self.player.score_on_display2 self.participant.vars['score_on_display'] = self.player.score_on_display2 self.player.time_spent_total2 = math.floor(time.time() - self.participant.vars['start_game2']) self.participant.vars['time_spent_total2'] = self.player.time_spent_total2 hist1 = self.player.gap_history1 hist11 = hist1.split(',') hist2 = self.player.gap_history2 hist22 = hist2.split(',') hist22 = hist22[1:] self.participant.vars['gap_history2'] = [int(i) for i in hist22] #self.player.gap_history1 = '' if (hist11!=['']): self.participant.vars['gap_history'] = [int(i) for i in hist11] + [int(i) for i in hist22] #self.participant.vars['gap_history1'] = [int(i) for i in hist11] #self.player.gap_history1 = ', '.join(str(e) for e in self.participant.vars['gap_history1']) else: self.participant.vars['gap_history'] = [int(i) for i in hist22] self.player.gap_history2 = ', '.join(str(e) for e in self.participant.vars['gap_history2']) self.player.total_green2 = self.participant.vars['nonogram_green'][self.participant.vars['game_number']-1] self.player.total_gray2 = self.participant.vars['nonogram_gray'][self.participant.vars['game_number']-1] class blank2(Page): form_model = 'player' timeout_seconds = 0.5 def is_displayed(self): return int(self.player.participant.vars['timer_game2']) > 3 def vars_for_template(player): def time_spent_nono(): length = len(player.participant.vars['gap_history']) length1 = len(player.participant.vars['gap_history1']) length2 = len(player.participant.vars['gap_history2']) interruption_time1 = player.participant.vars['interruption_time'][0:length1] interruption_time2 = player.participant.vars['interruption_time'][length1:length] interruption_time3 = player.participant.vars['interruption_time'][length:10] time_spent_nono2 = player.participant.vars['time_spent_total2'] - np.sum(player.participant.vars['gap_history2'][0:]) timer_game3 = 600 - time_spent_nono2 - player.participant.vars['time_spent_nono1'] return time_spent_nono2, timer_game3, interruption_time2, interruption_time1, interruption_time3 time_spent_nono = time_spent_nono() player.participant.vars['time_spent_nono2'] = time_spent_nono[0] player.participant.vars['timer_game3'] = time_spent_nono[1] player.participant.vars['interruption_time2'] = time_spent_nono[2] player.participant.vars['interruption_time1'] = time_spent_nono[3] player.participant.vars['interruption_time3'] = time_spent_nono[4] return dict( gap_history1=player.participant.vars['gap_history1'], gap_history2=player.participant.vars['gap_history2'], gap_history=player.participant.vars['gap_history'], time_spent_nono1=player.participant.vars['time_spent_nono1'], time_spent_nono2=player.participant.vars['time_spent_nono2'], timer_game3=player.participant.vars['timer_game3'], interruption_time1=player.participant.vars['interruption_time1'], interruption_time2=player.participant.vars['interruption_time2'], interruption_time3=player.participant.vars['interruption_time3'], ) def before_next_page(self): self.player.time_spent_nono2 = float(self.player.participant.vars['time_spent_nono2']) self.player.interruption_time2 = ', '.join(str(e) for e in self.player.participant.vars['interruption_time2']) self.player.interruption_time3 = ', '.join(str(e) for e in self.player.participant.vars['interruption_time3']) self.player.participant.vars['start_game3'] = time.time() if int(self.player.participant.vars['timer_game3']) <= 3: hist = self.participant.vars['gap_history'] total_wrong_adding_forced = 0 # CHANGE TO 5 FOR REAL GAME!!!!!!!!!!! 5 INTERRUPTIONS!!!!!!!!!! for i in range(0, 10): if hist[i] >= 60: total_wrong_adding_forced = total_wrong_adding_forced + 1 self.player.total_wrong_adding_forced = total_wrong_adding_forced self.participant.vars['total_wrong_adding_forced'] = self.player.total_wrong_adding_forced self.participant.vars['final_points_forced'] = self.participant.vars['score_on_display'] - total_wrong_adding_forced * 5 class Game3(Page): form_model = 'player' form_fields = ['gap_history3', 'points3', 'total_wrong3', 'total_right3', 'wrong_green3', 'wrong_gray3', 'score_on_display3', 'right_green3', 'right_gray3', 'time_between_moves3', 'board_history3', 'solve_order3', 'game3_finished'] def get_timeout_seconds(self): return int(self.player.participant.vars['timer_game3'] + 60*10) def is_displayed(self): return int(self.player.participant.vars['timer_game3']) > 3 def vars_for_template(player): player.participant.vars['game_number'] = 3 player.participant.vars['row'] = player.participant.vars['nonogram'][player.participant.vars['game_number']-1][0] player.participant.vars['column'] = player.participant.vars['nonogram'][player.participant.vars['game_number']-1][1] player.participant.vars['solution_0'] = player.participant.vars['nonogram_sol'][player.participant.vars['game_number']-1][0] player.participant.vars['solution_1'] = player.participant.vars['nonogram_sol'][player.participant.vars['game_number']-1][1] player.participant.vars['solution_2'] = player.participant.vars['nonogram_sol'][player.participant.vars['game_number']-1][2] player.participant.vars['solution_3'] = player.participant.vars['nonogram_sol'][player.participant.vars['game_number']-1][3] player.participant.vars['solution_4'] = player.participant.vars['nonogram_sol'][player.participant.vars['game_number']-1][4] player.participant.vars['solution_5'] = player.participant.vars['nonogram_sol'][player.participant.vars['game_number']-1][5] player.participant.vars['solution_6'] = player.participant.vars['nonogram_sol'][player.participant.vars['game_number']-1][6] player.participant.vars['solution_7'] = player.participant.vars['nonogram_sol'][player.participant.vars['game_number']-1][7] player.participant.vars['solution_8'] = player.participant.vars['nonogram_sol'][player.participant.vars['game_number']-1][8] player.participant.vars['solution_9'] = player.participant.vars['nonogram_sol'][player.participant.vars['game_number']-1][9] player.participant.vars['set1'] = player.participant.vars['adding_numbers'] 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)], n=[player.participant.vars['set1'][j]for j in range(0, 10)], interruption_time=player.participant.vars['interruption_time'], interruption_time2=player.participant.vars['interruption_time2'], interruption_time3=player.participant.vars['interruption_time3'], ) def js_vars(self): return { 'timer_game3': int(self.player.participant.vars['timer_game3']), 'score': self.participant.vars['score_on_display2'], 'n': [self.participant.vars['set1'][h] for h in range(0, 10)], 'interruption_time': self.participant.vars['interruption_time'], } def before_next_page(self): self.participant.vars['score_on_display3'] = self.player.score_on_display3 self.participant.vars['score_on_display'] = self.player.score_on_display3 self.player.time_spent_total3 = math.floor(time.time() - self.participant.vars['start_game3']) self.participant.vars['time_spent_total3'] = self.player.time_spent_total3 hist1 = self.player.gap_history1 hist11 = hist1.split(',') hist2 = self.player.gap_history2 hist22 = hist2.split(',') hist3 = self.player.gap_history3 hist33 = hist3.split(',') hist33 = hist33[1:] self.participant.vars['gap_history3'] = [int(i) for i in hist33] if (hist11 != ['']) & (hist22 != ['']): self.participant.vars['gap_history'] = [int(i) for i in hist11] + [int(i) for i in hist22] + [int(i) for i in hist33] if (hist11 != ['']) & (hist22 == ['']): self.participant.vars['gap_history'] = [int(i) for i in hist11] + [int(i) for i in hist33] if (hist11 == ['']) & (hist22 != ['']): self.participant.vars['gap_history'] = [int(i) for i in hist22] + [int(i) for i in hist33] if (hist11 == ['']) & (hist22 == ['']): self.participant.vars['gap_history'] = [int(i) for i in hist33] self.player.gap_history3 = ', '.join(str(e) for e in self.participant.vars['gap_history3']) self.player.gap_history = ', '.join(str(e) for e in self.participant.vars['gap_history']) hist = self.participant.vars['gap_history'] total_wrong_adding_forced = 0 #CHANGE TO 5 FOR REAL GAME!!!!!!!!!!! 5 INTERRUPTIONS!!!!!!!!!! for i in range(0, 10): if hist[i] >= 60: total_wrong_adding_forced = total_wrong_adding_forced + 1 self.player.total_wrong_adding_forced = total_wrong_adding_forced self.participant.vars['total_wrong_adding_forced'] = self.player.total_wrong_adding_forced self.participant.vars['final_points_forced'] = self.player.score_on_display3 - total_wrong_adding_forced * 5 self.player.total_green3 = self.participant.vars['nonogram_green'][self.participant.vars['game_number']-1] self.player.total_gray3 = self.participant.vars['nonogram_gray'][self.participant.vars['game_number']-1] class blank3(Page): form_model = 'player' timeout_seconds = 0.5 def is_displayed(self): return int(self.player.participant.vars['timer_game3']) > 3 def vars_for_template(player): return dict( total_wrong_adding_forced=player.participant.vars['total_wrong_adding_forced'], ) def before_next_page(self): self.player.participant.vars['time_spent_nono3'] = self.player.participant.vars['time_spent_total3'] - np.sum(self.player.participant.vars['gap_history3'][0:]) self.player.time_spent_nono3 = float(self.player.participant.vars['time_spent_nono3']) class results(Page): form_model = 'player' #timeout_seconds = 60 def vars_for_template(self): self.participant.vars['total_correct_adding_forced'] = 10 - self.participant.vars['total_wrong_adding_forced'] self.player.final_points_forced = self.participant.vars['final_points_forced'] self.participant.vars['point_deduction_adding_forced'] = 5*self.participant.vars['total_wrong_adding_forced'] self.player.gap_history = ', '.join(str(e) for e in self.participant.vars['gap_history']) if self.participant.vars['final_points_forced'] > 0: self.player.final_payoff_forced = self.participant.vars['final_points_forced'] / 20 if self.participant.vars['final_points_forced'] <= 0: self.player.final_payoff_forced = 0 self.participant.vars['final_payoff_forced'] = self.player.final_payoff_forced return dict( nonogram_points_forced=self.participant.vars['score_on_display'], point_deduction_adding_forced=self.participant.vars['point_deduction_adding_forced'], final_points_forced=self.participant.vars['final_points_forced'], total_correct_adding_forced = self.participant.vars['total_correct_adding_forced'], final_payoff_forced=self.participant.vars['final_payoff_forced'], ) def js_vars(self): return { 'nonogram_points_forced': self.participant.vars['score_on_display'], 'point_deduction_adding_forced': self.participant.vars['point_deduction_adding_forced'], 'final_points_forced': self.participant.vars['final_points_forced'], 'total_correct_adding_forced': self.participant.vars['total_correct_adding_forced'], 'final_payoff_forced': self.participant.vars['final_payoff_forced'], } class survey(Page): form_model = 'player' form_fields = ['q1', 'q2', 'q3', 'q4', 'q5', 'q6'] def app_after_this_page(self, upcoming_apps): if self.participant.vars['treatment_order'][0] == 1 and self.participant.vars['treatment_order'][1] == 2: return 'multitasking_prolific_payment_info' if self.participant.vars['treatment_order'][0] == 2 and self.participant.vars['treatment_order'][1] == 1: return 'multitasking_prolific_no_distraction_a' page_sequence = [ Instructions, Game1, blank1, Game2, blank2, Game3, blank3, results, survey, ]