from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import random import datetime, json, time import math import numpy as np def question(): #question_choice = 40 question_choice = random.randint(1, 42) return question_choice def budget(): budget00000 = (0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100) return budget00000 class instruction_choice(Page): form_model = 'player' def is_displayed(self): return self.round_number == 1 def vars_for_template(self): self.player.decision_chosen = question() self.participant.vars['decision_chosen'] = self.player.decision_chosen class instruction_choice_forced(Page): form_model = 'player' def is_displayed(self): return self.round_number == 1 class forced(Page): form_model = 'player' form_fields = ['forcedchoice1', 'forcedchoice2', 'forcedchoice3', 'forcedchoice4', 'forcedchoice5', 'forcedchoice6', 'forcedchoice7', 'forcedchoice8', 'forcedchoice9', 'forcedchoice10', 'forcedchoice11', 'forcedchoice12', 'forcedchoice13', 'forcedchoice14', 'forcedchoice15', 'forcedchoice16', 'forcedchoice17', 'forcedchoice18', 'forcedchoice19', 'forcedchoice20', 'forcedchoice21'] def is_displayed(self): return self.round_number == 1 def before_next_page(self): self.participant.vars['forcedchoice1'] = self.player.forcedchoice1 self.participant.vars['forcedchoice2'] = self.player.forcedchoice2 self.participant.vars['forcedchoice3'] = self.player.forcedchoice3 self.participant.vars['forcedchoice4'] = self.player.forcedchoice4 self.participant.vars['forcedchoice5'] = self.player.forcedchoice5 self.participant.vars['forcedchoice6'] = self.player.forcedchoice6 self.participant.vars['forcedchoice7'] = self.player.forcedchoice7 self.participant.vars['forcedchoice8'] = self.player.forcedchoice8 self.participant.vars['forcedchoice9'] = self.player.forcedchoice9 self.participant.vars['forcedchoice10'] = self.player.forcedchoice10 self.participant.vars['forcedchoice11'] = self.player.forcedchoice11 self.participant.vars['forcedchoice12'] = self.player.forcedchoice12 self.participant.vars['forcedchoice13'] = self.player.forcedchoice13 self.participant.vars['forcedchoice14'] = self.player.forcedchoice14 self.participant.vars['forcedchoice15'] = self.player.forcedchoice15 self.participant.vars['forcedchoice16'] = self.player.forcedchoice16 self.participant.vars['forcedchoice17'] = self.player.forcedchoice17 self.participant.vars['forcedchoice18'] = self.player.forcedchoice18 self.participant.vars['forcedchoice19'] = self.player.forcedchoice19 self.participant.vars['forcedchoice20'] = self.player.forcedchoice20 self.participant.vars['forcedchoice21'] = self.player.forcedchoice21 class instruction_choice_podcast(Page): form_model = 'player' def is_displayed(self): return self.round_number == 1 class podcast(Page): form_model = 'player' form_fields = ['podcastchoice1', 'podcastchoice2', 'podcastchoice3', 'podcastchoice4', 'podcastchoice5', 'podcastchoice6', 'podcastchoice7', 'podcastchoice8', 'podcastchoice9', 'podcastchoice10', 'podcastchoice11', 'podcastchoice12', 'podcastchoice13', 'podcastchoice14', 'podcastchoice15', 'podcastchoice16', 'podcastchoice17', 'podcastchoice18', 'podcastchoice19', 'podcastchoice20', 'podcastchoice21'] def is_displayed(self): return self.round_number == 1 def before_next_page(self): self.participant.vars['podcastchoice1'] = self.player.podcastchoice1 self.participant.vars['podcastchoice2'] = self.player.podcastchoice2 self.participant.vars['podcastchoice3'] = self.player.podcastchoice3 self.participant.vars['podcastchoice4'] = self.player.podcastchoice4 self.participant.vars['podcastchoice5'] = self.player.podcastchoice5 self.participant.vars['podcastchoice6'] = self.player.podcastchoice6 self.participant.vars['podcastchoice7'] = self.player.podcastchoice7 self.participant.vars['podcastchoice8'] = self.player.podcastchoice8 self.participant.vars['podcastchoice9'] = self.player.podcastchoice9 self.participant.vars['podcastchoice10'] = self.player.podcastchoice10 self.participant.vars['podcastchoice11'] = self.player.podcastchoice11 self.participant.vars['podcastchoice12'] = self.player.podcastchoice12 self.participant.vars['podcastchoice13'] = self.player.podcastchoice13 self.participant.vars['podcastchoice14'] = self.player.podcastchoice14 self.participant.vars['podcastchoice15'] = self.player.podcastchoice15 self.participant.vars['podcastchoice16'] = self.player.podcastchoice16 self.participant.vars['podcastchoice17'] = self.player.podcastchoice17 self.participant.vars['podcastchoice18'] = self.player.podcastchoice18 self.participant.vars['podcastchoice19'] = self.player.podcastchoice19 self.participant.vars['podcastchoice20'] = self.player.podcastchoice20 self.participant.vars['podcastchoice21'] = self.player.podcastchoice21 class questionchosen(Page): form_model = 'player' def is_displayed(self): return self.round_number == 1 def vars_for_template(self): for i in range(0, 22): if self.participant.vars['decision_chosen'] == i: if self.participant.vars['forcedchoice' + str(i)] == str(0): self.participant.vars['treatment_assigned'] = 3 self.participant.vars['budgetdeduction'] = 0 else: self.participant.vars['treatment_assigned'] = 1 self.participant.vars['budgetdeduction'] = budget()[i-1] for i in range(22, 43): if self.participant.vars['decision_chosen'] == i: temp = i - 21 if self.participant.vars['podcastchoice' + str(temp)] == str(0): self.participant.vars['treatment_assigned'] = 2 self.participant.vars['budgetdeduction'] = 0 else: self.participant.vars['treatment_assigned'] = 1 self.participant.vars['budgetdeduction'] = budget()[temp-1] print(self.participant.vars['treatment_assigned']) return dict( budgetdeduction=self.participant.vars['budgetdeduction'], treatment_assigned=self.participant.vars['treatment_assigned'], question_chosen=self.participant.vars['decision_chosen'], forced_choose1=self.player.field_display('forcedchoice1'), forced_choose2=self.player.field_display('forcedchoice2'), forced_choose3=self.player.field_display('forcedchoice3'), forced_choose4=self.player.field_display('forcedchoice4'), forced_choose5=self.player.field_display('forcedchoice5'), forced_choose6=self.player.field_display('forcedchoice6'), forced_choose7=self.player.field_display('forcedchoice7'), forced_choose8=self.player.field_display('forcedchoice8'), forced_choose9=self.player.field_display('forcedchoice9'), forced_choose10=self.player.field_display('forcedchoice10'), forced_choose11=self.player.field_display('forcedchoice11'), forced_choose12=self.player.field_display('forcedchoice12'), forced_choose13=self.player.field_display('forcedchoice13'), forced_choose14=self.player.field_display('forcedchoice14'), forced_choose15=self.player.field_display('forcedchoice15'), forced_choose16=self.player.field_display('forcedchoice16'), forced_choose17=self.player.field_display('forcedchoice17'), forced_choose18=self.player.field_display('forcedchoice18'), forced_choose19=self.player.field_display('forcedchoice19'), forced_choose20=self.player.field_display('forcedchoice20'), forced_choose21=self.player.field_display('forcedchoice21'), podcast_choose1=self.player.field_display('podcastchoice1'), podcast_choose2=self.player.field_display('podcastchoice2'), podcast_choose3=self.player.field_display('podcastchoice3'), podcast_choose4=self.player.field_display('podcastchoice4'), podcast_choose5=self.player.field_display('podcastchoice5'), podcast_choose6=self.player.field_display('podcastchoice6'), podcast_choose7=self.player.field_display('podcastchoice7'), podcast_choose8=self.player.field_display('podcastchoice8'), podcast_choose9=self.player.field_display('podcastchoice9'), podcast_choose10=self.player.field_display('podcastchoice10'), podcast_choose11=self.player.field_display('podcastchoice11'), podcast_choose12=self.player.field_display('podcastchoice12'), podcast_choose13=self.player.field_display('podcastchoice13'), podcast_choose14=self.player.field_display('podcastchoice14'), podcast_choose15=self.player.field_display('podcastchoice15'), podcast_choose16=self.player.field_display('podcastchoice16'), podcast_choose17=self.player.field_display('podcastchoice17'), podcast_choose18=self.player.field_display('podcastchoice18'), podcast_choose19=self.player.field_display('podcastchoice19'), podcast_choose20=self.player.field_display('podcastchoice20'), podcast_choose21=self.player.field_display('podcastchoice21'), ) def js_vars(self): return { 'question_chosen': self.participant.vars['decision_chosen'], 'budgetdeduction':self.participant.vars['budgetdeduction'], } def before_next_page(self): self.player.treatment_assigned = self.participant.vars['treatment_assigned'] # Set of games: a = [[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], [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], [86, 34, 12, 15, 13, 61, 53, 52, 75, 57], [79, 35, 52, 45, 12, 64, 17, 38, 44, 11]] nonogram = [ [["4 1","1 3","1 4","3 1","2 2 3","1 2","3 2 1","1 6 1","2 2 3","1 1 2"], ["1 1 1","1 2","1 3","1 1 3 1","1 2 3","1 4 3","2 3 1","3 1 3","4 1","1 1 3"]], [["2 3", "1 1 3", "2 1 1 1", "1 1 3", "4 1 1", "1 3", "1 3 4", "1 1", "2 1 1", "1 3 1 1"], ["1 1", "3 1 2", "1 3 3", "1 1 1", "3 2 1", "1 1", "3 1", "2 4 2", "2 1 3", "1 1 2 2"]], [["2 1 1 1","3 4","3 1 2","1 2 1","1 1 3","1 3 1 1","1 2 1","5 4","1 2 1","3"], ["1 3 1","1 1 4","3 1","1 1 1 2","2 2 2","1 1","3 1 4","1 4 1","3 1 1","3 3"]] ] nonogram_sol = [ [[0, 0, 1, 1, 1, 1, 0, 1, 0, 0], [1, 0, 0, 0, 0, 0, 0, 1, 1, 1], [0, 0, 0, 1, 0, 1, 1, 1, 1, 0], [0, 0, 0, 0, 1, 1, 1, 0, 1, 0], [1, 1, 0, 0, 1, 1, 0, 1, 1, 1], [0, 0, 0, 1, 0, 1, 1, 0, 0, 0], [0, 0, 1, 1, 1, 0, 1, 1, 0, 1], [1, 0, 1, 1, 1, 1, 1, 1, 0, 1], [0, 1, 1, 0, 1, 1, 0, 1, 1, 1], [0, 1, 0, 1, 0, 1, 1, 0, 0, 0]], [[0, 1, 1, 0, 0, 0, 0, 1, 1, 1], [0, 1, 0, 0, 1, 0, 1, 1, 1, 0], [0, 1, 1, 0, 1, 0, 1, 0, 0, 1], [0, 0, 1, 0, 1, 0, 1, 1, 1, 0], [1, 1, 1, 1, 0, 1, 0, 1, 0, 0], [0, 0, 0, 0, 1, 0, 0, 1, 1, 1], [1, 0, 1, 1, 1, 0, 1, 1, 1, 1], [0, 0, 1, 0, 0, 0, 0, 0, 1, 0], [0, 1, 1, 0, 0, 0, 0, 1, 0, 1], [0, 1, 0, 1, 1, 1, 0, 1, 0, 1]], [[1, 1, 0, 0, 1, 0, 1, 0, 1, 0], [0, 0, 1, 1, 1, 0, 1, 1, 1, 1], [1, 1, 1, 0, 0, 0, 1, 0, 1, 1], [1, 0, 1, 1, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 1, 0, 1, 1, 1, 0], [0, 1, 0, 1, 1, 1, 0, 1, 0, 1], [0, 1, 0, 0, 0, 0, 1, 1, 0, 1], [1, 1, 1, 1, 1, 0, 1, 1, 1, 1], [0, 1, 0, 1, 1, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 1, 1, 1, 0, 0]] ] nono_green = [53, 50, 53] nono_gray = [47, 50, 47] # No distraction: class nodist_Instructions(Page): form_model = 'player' # timeout_seconds = 120 def vars_for_template(player): player.participant.vars['nonogram'] = nonogram player.participant.vars['nonogram_sol'] = nonogram_sol player.participant.vars['nonogram_green'] = nono_green player.participant.vars['nonogram_gray'] = nono_gray player.participant.vars['adding_numbers'] = a return dict( budgetdeduction=player.participant.vars['budgetdeduction'], ) def before_next_page(self): self.participant.vars['sssss'] = time.time() def is_displayed(self): return self.participant.vars['treatment_assigned'] == 1 and self.round_number == 1 def get_timeout_seconds(player): if player.participant.vars['treatment_assigned'] == 1: if player.round_number == 1: return 600 if player.round_number != 1: return 600 - player.participant.vars['time_spent'] class nodist_Game1(Page): form_model = 'player' form_fields = ['points', 'total_wrong', 'total_right', 'wrong_green', 'wrong_gray', 'right_green', 'right_gray', 'time_between_moves', 'board_history', 'solve_order', 'score_on_display', 'game_finished'] get_timeout_seconds = get_timeout_seconds def is_displayed(player): return player.participant.vars['treatment_assigned'] == 1 and get_timeout_seconds(player) > 0 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'] = player.participant.vars['nonogram'][i-1][0] player.participant.vars['column'] = player.participant.vars['nonogram'][i-1][1] player.participant.vars['solution_0'] = player.participant.vars['nonogram_sol'][i-1][0] player.participant.vars['solution_1'] = player.participant.vars['nonogram_sol'][i-1][1] player.participant.vars['solution_2'] = player.participant.vars['nonogram_sol'][i-1][2] player.participant.vars['solution_3'] = player.participant.vars['nonogram_sol'][i-1][3] player.participant.vars['solution_4'] = player.participant.vars['nonogram_sol'][i-1][4] player.participant.vars['solution_5'] = player.participant.vars['nonogram_sol'][i-1][5] player.participant.vars['solution_6'] = player.participant.vars['nonogram_sol'][i-1][6] player.participant.vars['solution_7'] = player.participant.vars['nonogram_sol'][i-1][7] player.participant.vars['solution_8'] = player.participant.vars['nonogram_sol'][i-1][8] player.participant.vars['solution_9'] = player.participant.vars['nonogram_sol'][i-1][9] 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)], ) def js_vars(self): if self.round_number == 1: return { 'score': 0, } if self.round_number != 1: return { 'score': self.participant.vars['points'], } def before_next_page(self): self.participant.vars['points'] = self.player.score_on_display self.player.time_spent = math.floor(time.time() - self.participant.vars['sssss']) self.participant.vars['time_spent'] = self.player.time_spent for i in range(1, 4): if self.player.round_number == i: self.player.total_green = self.participant.vars['nonogram_green'][i-1] self.player.total_gray = self.participant.vars['nonogram_gray'][i-1] class nodist_blank(Page): form_model = 'player' timeout_seconds = 0.01 def is_displayed(player): return player.participant.vars['treatment_assigned'] == 1 and player.round_number != 3 class nodist_adding_numbers_instructions(Page): form_model = 'player' timeout_seconds = 1 def is_displayed(player): return player.participant.vars['treatment_assigned'] == 1 and player.round_number == 3 def before_next_page(self): self.participant.vars['add1_start'] = time.time() class nodist_Adding_numbers1(Page): form_model = 'player' form_fields = ['adding_numbers1_correct'] timeout_seconds = 60 def is_displayed(player): return player.participant.vars['treatment_assigned'] == 1 and player.round_number == 3 def vars_for_template(self): self.participant.vars['add1'] = self.participant.vars['adding_numbers'][0] return dict( n=[self.participant.vars['add1'][h] for h in range(0, 10)], ) def before_next_page(self): self.player.adding_numbers1_time_spent = math.floor(time.time() - self.participant.vars['add1_start']) self.participant.vars['add2_start'] = time.time() def js_vars(self): return { 'n': [self.participant.vars['add1'][h] for h in range(0, 10)], } class nodist_Adding_numbers2(Page): form_model = 'player' form_fields = ['adding_numbers2_correct'] timeout_seconds = 60 def is_displayed(player): return player.participant.vars['treatment_assigned'] == 1 and player.round_number == 3 def vars_for_template(self): self.participant.vars['add2'] = self.participant.vars['adding_numbers'][1] return dict( n=[self.participant.vars['add2'][h] for h in range(0, 10)], ) def before_next_page(self): self.player.adding_numbers2_time_spent = math.floor(time.time() - self.participant.vars['add2_start']) self.participant.vars['add3_start'] = time.time() def js_vars(self): return { 'n': [self.participant.vars['add2'][h] for h in range(0, 10)], } class nodist_Adding_numbers3(Page): form_model = 'player' form_fields = ['adding_numbers3_correct'] timeout_seconds = 60 def is_displayed(player): return player.participant.vars['treatment_assigned'] == 1 and player.round_number == 3 def vars_for_template(self): self.participant.vars['add3'] = self.participant.vars['adding_numbers'][2] return dict( n=[self.participant.vars['add3'][h] for h in range(0, 10)], ) def before_next_page(self): self.player.adding_numbers3_time_spent = math.floor(time.time() - self.participant.vars['add3_start']) self.participant.vars['add4_start'] = time.time() def js_vars(self): return { 'n': [self.participant.vars['add3'][h] for h in range(0, 10)], } class nodist_Adding_numbers4(Page): form_model = 'player' form_fields = ['adding_numbers4_correct'] timeout_seconds = 60 def is_displayed(player): return player.participant.vars['treatment_assigned'] == 1 and player.round_number == 3 def vars_for_template(self): self.participant.vars['add4'] = self.participant.vars['adding_numbers'][3] return dict( n=[self.participant.vars['add4'][h] for h in range(0, 10)], ) def before_next_page(self): self.player.adding_numbers4_time_spent = math.floor(time.time() - self.participant.vars['add4_start']) self.participant.vars['add5_start'] = time.time() def js_vars(self): return { 'n': [self.participant.vars['add4'][h] for h in range(0, 10)], } class nodist_Adding_numbers5(Page): form_model = 'player' form_fields = ['adding_numbers5_correct'] timeout_seconds = 60 def is_displayed(player): return player.participant.vars['treatment_assigned'] == 1 and player.round_number == 3 def vars_for_template(self): self.participant.vars['add5'] = self.participant.vars['adding_numbers'][4] return dict( n=[self.participant.vars['add5'][h] for h in range(0, 10)], ) def before_next_page(self): self.player.adding_numbers5_time_spent = math.floor(time.time() - self.participant.vars['add5_start']) def js_vars(self): return { 'n': [self.participant.vars['add5'][h] for h in range(0, 10)], } class nodist_results(Page): form_model = 'player' #timeout_seconds = 60 def is_displayed(player): return player.participant.vars['treatment_assigned'] == 1 and player.round_number == 3 def vars_for_template(self): self.participant.vars['nonogram_points_no_distraction'] = self.participant.vars['points'] if self.player.adding_numbers1_correct == 1: self.participant.vars['add1_correct'] = 1 else: self.participant.vars['add1_correct'] = 0 if self.player.adding_numbers2_correct == 1: self.participant.vars['add2_correct'] = 1 else: self.participant.vars['add2_correct'] = 0 if self.player.adding_numbers3_correct == 1: self.participant.vars['add3_correct'] = 1 else: self.participant.vars['add3_correct'] = 0 if self.player.adding_numbers4_correct == 1: self.participant.vars['add4_correct'] = 1 else: self.participant.vars['add4_correct'] = 0 if self.player.adding_numbers5_correct == 1: self.participant.vars['add5_correct'] = 1 else: self.participant.vars['add5_correct'] = 0 self.participant.vars['total_correct_adding_no_distraction'] = self.participant.vars['add1_correct'] + self.participant.vars['add2_correct'] \ + self.participant.vars['add3_correct'] + self.participant.vars['add4_correct'] + self.participant.vars['add5_correct'] self.player.total_wrong_adding_no_distraction = 5 - self.participant.vars['total_correct_adding_no_distraction'] self.participant.vars['total_wrong_adding_no_distraction'] = self.player.total_wrong_adding_no_distraction self.participant.vars['point_deduction_adding_no_distraction'] = 5*self.participant.vars['total_wrong_adding_no_distraction'] self.participant.vars['final_points_no_distraction'] = self.participant.vars['points'] - \ 5 * (5-self.participant.vars['total_correct_adding_no_distraction'])\ - self.participant.vars['budgetdeduction'] if self.participant.vars['final_points_no_distraction'] > 0: self.player.final_payoff_no_distraction = self.participant.vars['final_points_no_distraction'] / 10 if self.participant.vars['final_points_no_distraction'] <= 0: self.player.final_payoff_no_distraction = 0 self.participant.vars['final_payoff_no_distraction'] = self.player.final_payoff_no_distraction self.player.final_payoff_choice = self.participant.vars['final_payoff_no_distraction'] self.participant.vars['final_payoff_choice'] = self.player.final_payoff_choice return dict( point_deduction_adding_no_distraction=self.participant.vars['point_deduction_adding_no_distraction'], nonogram_points_no_distraction=self.participant.vars['nonogram_points_no_distraction'], final_points_no_distraction=self.participant.vars['final_points_no_distraction'], total_correct_adding_no_distraction = self.participant.vars['total_correct_adding_no_distraction'], budgetdeduction=self.participant.vars['budgetdeduction'], final_payoff_no_distraction = self.participant.vars['final_payoff_no_distraction'], ) def js_vars(self): for i in range(1, 4): if self.round_number == i: return { 'point_deduction_adding_no_distraction': self.participant.vars['point_deduction_adding_no_distraction'], 'nonogram_points_no_distraction': self.participant.vars['nonogram_points_no_distraction'], 'final_points_no_distraction': self.participant.vars['final_points_no_distraction'], 'total_correct_adding_no_distraction': self.participant.vars['total_correct_adding_no_distraction'], 'final_payoff_no_distraction': self.participant.vars['final_payoff_no_distraction'], 'budgetdeduction': self.participant.vars['budgetdeduction'], } class podcast_Instructions(Page): form_model = 'player' #timeout_seconds = 120 def vars_for_template(player): player.participant.vars['nonogram'] = nonogram player.participant.vars['nonogram_sol'] = nonogram_sol player.participant.vars['nonogram_green'] = nono_green player.participant.vars['nonogram_gray'] = nono_gray player.participant.vars['adding_numbers'] = a def before_next_page(self): self.participant.vars['sssss'] = time.time() def is_displayed(self): return self.participant.vars['treatment_assigned'] == 2 and self.round_number == 1 def get_timeout_seconds_podcast(player): if player.participant.vars['treatment_assigned'] == 2: if player.round_number == 1: return 600 if player.round_number != 1: return 600 - player.participant.vars['time_spent_podcast'] class podcast_Game1(Page): form_model = 'player' form_fields = ['points_podcast', 'total_wrong_podcast', 'total_right_podcast', 'wrong_green_podcast', 'wrong_gray_podcast', 'right_green_podcast', 'right_gray_podcast', 'time_between_moves_podcast', 'board_history_podcast', 'solve_order_podcast', 'score_on_display_podcast', 'game_finished_podcast'] get_timeout_seconds = get_timeout_seconds_podcast def is_displayed(player): return player.participant.vars['treatment_assigned'] == 2 and get_timeout_seconds_podcast(player) > 0 def vars_for_template(player): for i in range(1, 4): if player.round_number == i: player.participant.vars['audio_time'] = 600 - get_timeout_seconds_podcast(player) player.participant.vars['game_number'] = i player.participant.vars['row'] = player.participant.vars['nonogram'][i-1][0] player.participant.vars['column'] = player.participant.vars['nonogram'][i-1][1] player.participant.vars['solution_0'] = player.participant.vars['nonogram_sol'][i-1][0] player.participant.vars['solution_1'] = player.participant.vars['nonogram_sol'][i-1][1] player.participant.vars['solution_2'] = player.participant.vars['nonogram_sol'][i-1][2] player.participant.vars['solution_3'] = player.participant.vars['nonogram_sol'][i-1][3] player.participant.vars['solution_4'] = player.participant.vars['nonogram_sol'][i-1][4] player.participant.vars['solution_5'] = player.participant.vars['nonogram_sol'][i-1][5] player.participant.vars['solution_6'] = player.participant.vars['nonogram_sol'][i-1][6] player.participant.vars['solution_7'] = player.participant.vars['nonogram_sol'][i-1][7] player.participant.vars['solution_8'] = player.participant.vars['nonogram_sol'][i-1][8] player.participant.vars['solution_9'] = player.participant.vars['nonogram_sol'][i-1][9] return dict( audio_time=player.participant.vars['audio_time'], 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)], ) def js_vars(self): if self.round_number == 1: return { 'score': 0, 'audio_time': self.participant.vars['audio_time'], } if self.round_number != 1: return { 'score': self.participant.vars['points_podcast'], 'audio_time': self.participant.vars['audio_time'], } def before_next_page(self): self.participant.vars['points_podcast'] = self.player.score_on_display_podcast self.player.time_spent_podcast = math.floor(time.time() - self.participant.vars['sssss']) self.participant.vars['time_spent_podcast'] = self.player.time_spent_podcast for i in range(1, 4): if self.player.round_number == i: self.player.total_green_podcast = self.participant.vars['nonogram_green'][i-1] self.player.total_gray_podcast = self.participant.vars['nonogram_gray'][i-1] class podcast_blank(Page): form_model = 'player' timeout_seconds = 0.01 def is_displayed(player): return player.participant.vars['treatment_assigned'] == 2 and player.round_number != 3 class podcast_adding_numbers_instructions(Page): form_model = 'player' timeout_seconds = 1 def is_displayed(player): return player.participant.vars['treatment_assigned'] == 2 and player.round_number == 3 def before_next_page(self): self.participant.vars['add1_start'] = time.time() class podcast_Adding_numbers1(Page): form_model = 'player' form_fields = ['adding_numbers1_correct_podcast'] timeout_seconds = 60 def is_displayed(player): return player.participant.vars['treatment_assigned'] == 2 and player.round_number == 3 def vars_for_template(self): self.participant.vars['add1'] = self.participant.vars['adding_numbers'][0] return dict( n=[self.participant.vars['add1'][h] for h in range(0, 10)], ) def before_next_page(self): self.player.adding_numbers1_time_spent_podcast = math.floor(time.time() - self.participant.vars['add1_start']) self.participant.vars['add2_start'] = time.time() def js_vars(self): return { 'n': [self.participant.vars['add1'][h] for h in range(0, 10)], } class podcast_Adding_numbers2(Page): form_model = 'player' form_fields = ['adding_numbers2_correct_podcast'] timeout_seconds = 60 def is_displayed(player): return player.participant.vars['treatment_assigned'] == 2 and player.round_number == 3 def vars_for_template(self): self.participant.vars['add2'] = self.participant.vars['adding_numbers'][1] return dict( n=[self.participant.vars['add2'][h] for h in range(0, 10)], ) def before_next_page(self): self.player.adding_numbers2_time_spent_podcast = math.floor(time.time() - self.participant.vars['add2_start']) self.participant.vars['add3_start'] = time.time() def js_vars(self): return { 'n': [self.participant.vars['add2'][h] for h in range(0, 10)], } class podcast_Adding_numbers3(Page): form_model = 'player' form_fields = ['adding_numbers3_correct_podcast'] timeout_seconds = 60 def is_displayed(player): return player.participant.vars['treatment_assigned'] == 2 and player.round_number == 3 def vars_for_template(self): self.participant.vars['add3'] = self.participant.vars['adding_numbers'][2] return dict( n=[self.participant.vars['add3'][h] for h in range(0, 10)], ) def before_next_page(self): self.player.adding_numbers3_time_spent_podcast = math.floor(time.time() - self.participant.vars['add3_start']) self.participant.vars['add4_start'] = time.time() def js_vars(self): return { 'n': [self.participant.vars['add3'][h] for h in range(0, 10)], } class podcast_Adding_numbers4(Page): form_model = 'player' form_fields = ['adding_numbers4_correct_podcast'] timeout_seconds = 60 def is_displayed(player): return player.participant.vars['treatment_assigned'] == 2 and player.round_number == 3 def vars_for_template(self): self.participant.vars['add4'] = self.participant.vars['adding_numbers'][3] return dict( n=[self.participant.vars['add4'][h] for h in range(0, 10)], ) def before_next_page(self): self.player.adding_numbers4_time_spent_podcast = math.floor(time.time() - self.participant.vars['add4_start']) self.participant.vars['add5_start'] = time.time() def js_vars(self): return { 'n': [self.participant.vars['add4'][h] for h in range(0, 10)], } class podcast_Adding_numbers5(Page): form_model = 'player' form_fields = ['adding_numbers5_correct_podcast'] timeout_seconds = 60 def is_displayed(player): return player.participant.vars['treatment_assigned'] == 2 and player.round_number == 3 def vars_for_template(self): self.participant.vars['add5'] = self.participant.vars['adding_numbers'][4] return dict( n=[self.participant.vars['add5'][h] for h in range(0, 10)], ) def before_next_page(self): self.player.adding_numbers5_time_spent_podcast = math.floor(time.time() - self.participant.vars['add5_start']) def js_vars(self): return { 'n': [self.participant.vars['add5'][h] for h in range(0, 10)], } class podcast_results(Page): form_model = 'player' #timeout_seconds = 60 def is_displayed(player): return player.participant.vars['treatment_assigned'] == 2 and player.round_number == 3 def vars_for_template(self): self.participant.vars['nonogram_points_podcast'] = self.participant.vars['points_podcast'] if self.player.adding_numbers1_correct_podcast == 1: self.participant.vars['add1_correct'] = 1 else: self.participant.vars['add1_correct'] = 0 if self.player.adding_numbers2_correct_podcast == 1: self.participant.vars['add2_correct'] = 1 else: self.participant.vars['add2_correct'] = 0 if self.player.adding_numbers3_correct_podcast == 1: self.participant.vars['add3_correct'] = 1 else: self.participant.vars['add3_correct'] = 0 if self.player.adding_numbers4_correct_podcast == 1: self.participant.vars['add4_correct'] = 1 else: self.participant.vars['add4_correct'] = 0 if self.player.adding_numbers5_correct_podcast == 1: self.participant.vars['add5_correct'] = 1 else: self.participant.vars['add5_correct'] = 0 self.participant.vars['total_correct_adding_podcast'] = self.participant.vars['add1_correct'] + self.participant.vars['add2_correct'] \ + self.participant.vars['add3_correct'] + self.participant.vars['add4_correct'] + self.participant.vars['add5_correct'] self.player.total_wrong_adding_podcast = 5 - self.participant.vars['total_correct_adding_podcast'] self.participant.vars['total_wrong_adding_podcast'] = self.player.total_wrong_adding_podcast self.participant.vars['point_deduction_adding_podcast'] = 5*self.participant.vars['total_wrong_adding_podcast'] self.participant.vars['final_points_podcast'] = self.participant.vars['points_podcast'] - 5 * (5-self.participant.vars['total_correct_adding_podcast']) self.player.final_points_podcast = self.participant.vars['final_points_podcast'] if self.participant.vars['final_points_podcast'] > 0: self.player.final_payoff_podcast = self.participant.vars['final_points_podcast'] / 10 if self.participant.vars['final_points_podcast'] <= 0: self.player.final_payoff_podcast = 0 self.participant.vars['final_payoff_podcast'] = self.player.final_payoff_podcast self.player.final_payoff_choice = self.participant.vars['final_payoff_podcast'] self.participant.vars['final_payoff_choice'] = self.player.final_payoff_choice return dict( point_deduction_adding_podcast=self.participant.vars['point_deduction_adding_podcast'], nonogram_points_podcast=self.participant.vars['nonogram_points_podcast'], final_points_podcast=self.participant.vars['final_points_podcast'], total_correct_adding_podcast=self.participant.vars['total_correct_adding_podcast'], final_payoff_podcast=self.participant.vars['final_payoff_podcast'], ) def js_vars(self): for i in range(1, 4): if self.round_number == i: return { 'point_deduction_adding_podcast': self.participant.vars['point_deduction_adding_podcast'], 'nonogram_points_podcast': self.participant.vars['nonogram_points_podcast'], 'final_points_podcast': self.participant.vars['final_points_podcast'], 'total_correct_adding_podcast': self.participant.vars['total_correct_adding_podcast'], 'final_payoff_podcast': self.participant.vars['final_payoff_podcast'], } # Forced interruption: def interruption_time(): #test = [595, 590, 585, 580, 570] test = [500, 412, 333, 200, 120] 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 forced_Instructions(Page): form_model = 'player' #timeout_seconds = 120 def is_displayed(self): return self.participant.vars['treatment_assigned'] == 3 and self.round_number == 1 def vars_for_template(player): player.participant.vars['interruption_time'] = interruption_time() player.participant.vars['nonogram'] = nonogram player.participant.vars['nonogram_sol'] = nonogram_sol player.participant.vars['nonogram_green'] = nono_green player.participant.vars['nonogram_gray'] = nono_gray player.participant.vars['adding_numbers'] = a def before_next_page(self): self.participant.vars['start_game1'] = time.time() class forced_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*5 def is_displayed(self): return self.participant.vars['treatment_assigned'] == 3 and self.round_number == 1 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, 8)], 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, 8)], '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 forced_blank1(Page): form_model = 'player' timeout_seconds = 0.5 def is_displayed(self): return self.participant.vars['treatment_assigned'] == 3 and self.round_number == 1 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:6] 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, 5): 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 forced_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*5) def is_displayed(self): return self.participant.vars['treatment_assigned'] == 3 and self.round_number == 1 and 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, 8)], interruption_time=player.participant.vars['interruption_time'], ) 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, 8)], '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 forced_blank2(Page): form_model = 'player' timeout_seconds = 0.5 def is_displayed(self): return self.participant.vars['treatment_assigned'] == 3 and self.round_number == 1 and 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:6] 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, 5): 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 forced_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*5) def is_displayed(self): return self.participant.vars['treatment_assigned'] == 3 and self.round_number == 1 and 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, 8)], interruption_time=player.participant.vars['interruption_time'], ) 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, 8)], '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, 5): 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 forced_blank3(Page): form_model = 'player' timeout_seconds = 0.5 def is_displayed(self): return self.participant.vars['treatment_assigned'] == 3 and self.round_number == 1 and 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 forced_results(Page): form_model = 'player' #timeout_seconds = 60 def is_displayed(self): return self.participant.vars['treatment_assigned'] == 3 and self.round_number == 1 def vars_for_template(self): self.participant.vars['total_correct_adding_forced'] = 5 - 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'] / 10 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 self.player.final_payoff_choice = self.participant.vars['final_payoff_forced'] self.participant.vars['final_payoff_choice'] = self.player.final_payoff_choice 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'], } page_sequence = [ instruction_choice, instruction_choice_forced, forced, instruction_choice_podcast, podcast, questionchosen, nodist_Instructions, nodist_Game1, nodist_blank, nodist_adding_numbers_instructions, nodist_Adding_numbers1, nodist_Adding_numbers2, nodist_Adding_numbers3, nodist_Adding_numbers4, nodist_Adding_numbers5, nodist_results, podcast_Instructions, podcast_Game1, podcast_blank, podcast_adding_numbers_instructions, podcast_Adding_numbers1, podcast_Adding_numbers2, podcast_Adding_numbers3, podcast_Adding_numbers4, podcast_Adding_numbers5, podcast_results, forced_Instructions, forced_Game1, forced_blank1, forced_Game2, forced_blank2, forced_Game3, forced_blank3, forced_results, ]