from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import csv import random import time import xlrd # for reading XLS-files import math import random # import xlsxwriter module import xlsxwriter ########### ALL INSTRUCTION PAGES class A_Consent_Form(Page): form_model = 'player' form_fields = ['tab_consent'] def is_displayed(self): return self.round_number == 1 # only display in the first round def vars_for_template(self): loc = ("Correlation_Neglect/data/A_ConsentForm.xlsx") # To open Workbook wb = xlrd.open_workbook(loc) sheet = wb.sheet_by_index(0) # Get all titles & paragraphs title = sheet.cell_value(1, Constants.language_code) warning = sheet.cell_value(2, Constants.language_code) subtitle1 = sheet.cell_value(3, Constants.language_code) paragraph1 = sheet.cell_value(4, Constants.language_code) subtitle2 = sheet.cell_value(5, Constants.language_code) paragraph2 = sheet.cell_value(6, Constants.language_code) subtitle3 = sheet.cell_value(7, Constants.language_code) paragraph3 = sheet.cell_value(8, Constants.language_code) subtitle4 = sheet.cell_value(9, Constants.language_code) paragraph4 = sheet.cell_value(10, Constants.language_code) subtitle5 = sheet.cell_value(11, Constants.language_code) paragraph5 = sheet.cell_value(12, Constants.language_code) subtitle6 = sheet.cell_value(13, Constants.language_code) paragraph6 = sheet.cell_value(14, Constants.language_code) subtitle7 = sheet.cell_value(15, Constants.language_code) paragraph7 = sheet.cell_value(16, Constants.language_code) consent = sheet.cell_value(17, Constants.language_code) confirm = sheet.cell_value(18, Constants.language_code) return dict( title=title, warning=warning, subtitle1=subtitle1, subtitle2=subtitle2, subtitle3=subtitle3, subtitle4=subtitle4, subtitle5=subtitle5, subtitle6=subtitle6, subtitle7=subtitle7, paragraph1=paragraph1, paragraph2=paragraph2, paragraph3=paragraph3, paragraph4=paragraph4.format(showup_fee = Constants.showup_fee, currency_real = Constants.currency_real, currency = Constants.currency), paragraph5=paragraph5, paragraph6=paragraph6, paragraph7=paragraph7, consent=consent, confirm=confirm ) class B_Instructions1(Page): form_model = 'player' def is_displayed(self): return self.round_number == 1 class B_Instructions2(Page): form_model = 'player' def is_displayed(self): return self.round_number == 1 class B_Control_Questions1(Page): form_model = 'player' form_fields = ['ControlQuestion1', 'ControlQuestion2'] def is_displayed(self): return self.round_number == 1 class B_Instructions3(Page): form_model = 'player' def is_displayed(self): return self.round_number == 1 class B_Control_Questions2(Page): form_model = 'player' form_fields = ['ControlQuestion5_output','ControlQuestion5'] def is_displayed(self): return self.round_number == 1 class B_Instructions4(Page): form_model = 'player' def is_displayed(self): return self.round_number == 1 class B_Control_Questions3(Page): form_model = 'player' form_fields = ['ControlQuestion3', 'ControlQuestion4', 'ControlQuestion6', 'ControlQuestion7', 'ControlQuestion8'] def is_displayed(self): return self.round_number == 1 class B_Instructions5(Page): form_model = 'player' def is_displayed(self): return self.round_number == 1 class WaitAll(WaitPage): def is_displayed(self): return self.round_number == 1 # only display in the first round wait_for_all_groups = True title_text = "We are waiting for all participants to read the instructions and answer the control questions. This may take a while." body_text = "Then, we will proceed to the beginning of the study." class D_Correct_Assignment(Page): form_model = 'player' def is_displayed(self): return self.round_number == 1 # only display in the first round def vars_for_template(self): loc = ("Correlation_Neglect/data/D_Correct_Assignment.xlsx") # To open Workbook wb = xlrd.open_workbook(loc) sheet = wb.sheet_by_index(0) # Get all titles & paragraphs title = sheet.cell_value(1, Constants.language_code) paragraph1 = sheet.cell_value(2, Constants.language_code) confirm = sheet.cell_value(3, Constants.language_code) return dict( title=title, paragraph1=paragraph1.format(showup_fee=Constants.showup_fee ,currency=Constants.currency,currency_real=Constants.currency_real,XR=Constants.XR), confirm=confirm ) class D_Intro_Types(Page): form_model = 'player' def is_displayed(self): return self.round_number == 1 and self.player.id_in_group==1 # only display in the first round def vars_for_template(self): loc = ("Correlation_Neglect/data/C_Intro_Types.xlsx") # To open Workbook wb = xlrd.open_workbook(loc) sheet = wb.sheet_by_index(0) # Get all titles & paragraphs title = sheet.cell_value(1, Constants.language_code) paragraph1 = sheet.cell_value(2, Constants.language_code) confirm = sheet.cell_value(3, Constants.language_code) return dict( title=title, paragraph1=paragraph1.format(PRINCIPAL_ROLE=Constants.PRINCIPAL_ROLE), confirm=confirm, ) class D_Intro_Types2(Page): form_model = 'player' def is_displayed(self): return self.round_number == 1 and self.player.id_in_group==2 # only display in the first round def vars_for_template(self): loc = ("Correlation_Neglect/data/C_Intro_Types2.xlsx") # To open Workbook wb = xlrd.open_workbook(loc) sheet = wb.sheet_by_index(0) # Get all titles & paragraphs title = sheet.cell_value(1, Constants.language_code) paragraph1 = sheet.cell_value(2, Constants.language_code) confirm = sheet.cell_value(3, Constants.language_code) return dict( title=title, paragraph1=paragraph1.format(AGENT1_ROLE=Constants.AGENT1_ROLE), confirm=confirm, ) class D_Intro_Types3(Page): form_model = 'player' def is_displayed(self): return self.round_number == 1 and self.player.id_in_group==3 # only display in the first round def vars_for_template(self): loc = ("Correlation_Neglect/data/C_Intro_Types3.xlsx") # To open Workbook wb = xlrd.open_workbook(loc) sheet = wb.sheet_by_index(0) # Get all titles & paragraphs title = sheet.cell_value(1, Constants.language_code) paragraph1 = sheet.cell_value(2, Constants.language_code) confirm = sheet.cell_value(3, Constants.language_code) return dict( title=title, paragraph1=paragraph1.format(AGENT2_ROLE=Constants.AGENT2_ROLE), confirm=confirm, ) class E_Intro_Title_GREEN(Page): form_model = 'player' def is_displayed(self): return self.player.id_in_group==1 # only display in the first round def before_next_page(self): current_round = self.round_number def vars_for_template(self): current_round = self.round_number loc = "Correlation_Neglect/data/D_Intro_Title_Part1.xlsx" # To open Workbook wb = xlrd.open_workbook(loc) sheet = wb.sheet_by_index(0) # Get all titles & paragraphs title = sheet.cell_value(1, Constants.language_code) paragraph1 = sheet.cell_value(2, Constants.language_code) confirm = sheet.cell_value(2, Constants.language_code) return dict( title=title.format(current_round=current_round, High_Payment=Constants.High_Payment, Low_Payment=Constants.Low_Payment, Payoff_Green_Right=Constants.Payoff_Green_Right), confirm=confirm.format(current_round=current_round), ) class E_Intro_Title_LIGHT(Page): form_model = 'player' def is_displayed(self): return self.player.id_in_group==2 # only display in the first round def before_next_page(self): current_round = self.round_number def vars_for_template(self): current_round = self.round_number loc = "Correlation_Neglect/data/D_Intro_Title_Part2.xlsx" # To open Workbook wb = xlrd.open_workbook(loc) sheet = wb.sheet_by_index(0) # Get all titles & paragraphs title = sheet.cell_value(1, Constants.language_code) paragraph1 = sheet.cell_value(2, Constants.language_code) confirm = sheet.cell_value(2, Constants.language_code) return dict( title=title.format(current_round=current_round, High_Payment=Constants.High_Payment, Specific_Project_Light=Constants.Specific_Project_Light, Low_Payment=Constants.Low_Payment), confirm=confirm.format(current_round=current_round), ) class E_Intro_Title_DARK(Page): form_model = 'player' def is_displayed(self): return self.player.id_in_group==3 # only display in the first round def before_next_page(self): current_round = self.round_number def vars_for_template(self): current_round = self.round_number loc = "Correlation_Neglect/data/D_Intro_Title_Part3.xlsx" # To open Workbook wb = xlrd.open_workbook(loc) sheet = wb.sheet_by_index(0) # Get all titles & paragraphs title = sheet.cell_value(1, Constants.language_code) paragraph1 = sheet.cell_value(2, Constants.language_code) confirm = sheet.cell_value(2, Constants.language_code) return dict( title=title.format(current_round=current_round, High_Payment=Constants.High_Payment,Specific_Project_Dark=Constants.Specific_Project_Dark, Low_Payment=Constants.Low_Payment), confirm=confirm.format(current_round=current_round), ) class I_Question(Page): form_model = 'group' form_fields = ['Decision_Principal', 'Decision_Principal_Explanation'] def is_displayed(self): return self.player.id_in_group == 1 def error_message(self, values): explanation = (values.get('Decision_Principal_Explanation') or '').strip() if self.round_number == 1 and not explanation: return 'Please briefly explain what you considered when choosing the cutoff in this round.' def before_next_page(self): self.group.OC() self.group.GR() def vars_for_template(self): return dict(current_round=self.round_number) class I_Question2(Page): form_model = 'group' form_fields = ['Effort_Light', 'Effort_Light_Explanation'] def is_displayed(self): return self.player.id_in_group == 2 def error_message(self, values): explanation = (values.get('Effort_Light_Explanation') or '').strip() if self.round_number == 1 and not explanation: return 'Please briefly explain what you considered when choosing your effort in this round.' def vars_for_template(self): current_round = self.round_number return dict(current_round=current_round) class I_Question3(Page): form_model = 'group' form_fields = ['Effort_Dark', 'Effort_Dark_Explanation'] def is_displayed(self): return self.player.id_in_group == 3 def error_message(self, values): explanation = (values.get('Effort_Dark_Explanation') or '').strip() if self.round_number == 1 and not explanation: return 'Please briefly explain what you considered when choosing your effort in this round.' def vars_for_template(self): current_round = self.round_number return dict( current_round=current_round ) class I_Question2_Belief(Page): form_model = 'group' form_fields = ['Belief_Light_Principal', 'Belief_Light_Principal_Confidence', 'Belief_Light_Dark'] def is_displayed(self): return self.player.id_in_group == 2 def vars_for_template(self): return dict(current_round=self.round_number) class I_Question3_Belief(Page): form_model = 'group' form_fields = ['Belief_Dark_Principal', 'Belief_Dark_Principal_Confidence', 'Belief_Dark_Light'] def is_displayed(self): return self.player.id_in_group == 3 def vars_for_template(self): return dict(current_round=self.round_number) class J_Random_Number(Page): form_model = 'group' def is_displayed(self): return self.player.id_in_group == 2 # only display in the first round def vars_for_template(self): loc = ("Correlation_Neglect/data/K_Random_Number.xlsx") # To open Workbook wb = xlrd.open_workbook(loc) sheet = wb.sheet_by_index(0) # Get all titles & paragraphs title = sheet.cell_value(1, Constants.language_code) paragraph1 = sheet.cell_value(2, Constants.language_code) confirm = sheet.cell_value(3, Constants.language_code) return dict( title=title, paragraph1=paragraph1.format(Specific_Project_Light=Constants.Specific_Project_Light), confirm=confirm, ) class J_Random_NumberB(Page): form_model = 'group' def is_displayed(self): return self.player.id_in_group == 2 # only display in the first round def vars_for_template(self): self.group.set_Random_Light() def before_next_page(self): self.group.WOL() self.group.ECL() class J_Random_Number2(Page): form_model = 'group' def is_displayed(self): return self.player.id_in_group == 3 # only display in the first round def vars_for_template(self): loc = ("Correlation_Neglect/data/K_Random_Number2.xlsx") # To open Workbook wb = xlrd.open_workbook(loc) sheet = wb.sheet_by_index(0) # Get all titles & paragraphs title = sheet.cell_value(1, Constants.language_code) paragraph1 = sheet.cell_value(2, Constants.language_code) confirm = sheet.cell_value(3, Constants.language_code) return dict( title=title, paragraph1=paragraph1.format(Specific_Project_Dark=Constants.Specific_Project_Dark), confirm=confirm, ) class J_Random_Number2B(Page): form_model = 'group' def is_displayed(self): return self.player.id_in_group == 3 # only display in the first round def vars_for_template(self): self.group.set_Random_Dark() def before_next_page(self): self.group.WOD() self.group.ECD() class J_Wait_Green(WaitPage): def is_displayed(self): return self.player.id_in_group == 1 # only display in the first round title_text = "We are waiting for LIGHT BLUE and DARK BLUE players to make their decision." body_text = "Then, you will proceed to your decision page." class J_Wait_Light(WaitPage): def is_displayed(self): return self.player.id_in_group == 2 title_text = "We are waiting for the DARK BLUE and GREEN players to make their decision." body_text = "Then, we will proceed." def vars_for_template(self): self.group.WOL() class J_Wait_Dark(WaitPage): def is_displayed(self): return self.player.id_in_group == 3 title_text = "We are waiting for the LIGHT BLUE and GREEN players to make their decision." body_text = "Then, we will proceed." class J_Wait_Group(WaitPage): title_text = "We are waiting for all participants to finish this round." body_text = "Then, next round will start with a new group formation." class K_End(Page): form_model = 'player' def is_displayed(self): return self.player.id_in_group == 1 ##################################################################################### def vars_for_template(self): player_in_all_rounds = self.player.in_all_rounds() self.group.GR() self.group.PGR() self.player.PGRO() current_round = self.round_number return dict( player_in_all_rounds=player_in_all_rounds, #B_high = self.participant.vars['B_high_indifferent'] current_round=current_round ) class K_End2(Page): form_model = 'player' def is_displayed(self): return self.player.id_in_group == 2 def vars_for_template(self): self.group.PLR() self.player.PLRO() self.group.WODiff() self.group.WOH() current_round = self.round_number player_in_all_rounds = self.player.in_all_rounds() return dict( player_in_all_rounds=player_in_all_rounds, current_round=current_round, ) class K_End3(Page): form_model = 'player' def is_displayed(self): return self.player.id_in_group == 3 def vars_for_template(self): player_in_all_rounds = self.player.in_all_rounds() self.group.PDR() self.player.PDRO() self.group.WODiff() self.group.WOH() current_round = self.round_number return dict( player_in_all_rounds=player_in_all_rounds, current_round=current_round ) class L_ENDEND1(Page): form_model = 'player' def is_displayed(self): return self.round_number == Constants.num_rounds #only display in the last round ##################################################################################### def vars_for_template(self): player_in_all_rounds = self.player.in_all_rounds() self.player.calculate_total_payoff() return dict( player_in_all_rounds=player_in_all_rounds, ) class M_FeedBack(Page): form_model = 'player' form_fields = ['FeedBack', 'Belief_Light', 'Belief_Dark'] def is_displayed(self): ##return self.round_number == 1 # only display in the last round return self.round_number == Constants.num_rounds # only display in the last round class L_ENDEND2(Page): form_model = 'player' def is_displayed(self): return self.round_number == Constants.num_rounds def vars_for_template(self): player_in_all_rounds = self.player.in_all_rounds() self.player.calculate_total_payoff() self.player.set_belief_bonus() show_belief_bonus = self.player.id_in_group in [2, 3] belief_bonus_round = None belief_bonus = 0 belief_guess = None belief_true_threshold = None belief_distance = None belief_confidence = None if self.player.id_in_group == 2: self.player.Total_Payoffs_Light += self.player.Belief_Selected_Bonus belief_bonus_round = self.player.Belief_Selected_Round belief_bonus = self.player.Belief_Selected_Bonus belief_guess = self.player.Belief_Selected_Guess belief_true_threshold = self.player.Belief_Selected_True_Threshold belief_distance = self.player.Belief_Selected_Distance belief_confidence = self.player.Belief_Selected_Confidence elif self.player.id_in_group == 3: self.player.Total_Payoffs_Dark += self.player.Belief_Selected_Bonus belief_bonus_round = self.player.Belief_Selected_Round belief_bonus = self.player.Belief_Selected_Bonus belief_guess = self.player.Belief_Selected_Guess belief_true_threshold = self.player.Belief_Selected_True_Threshold belief_distance = self.player.Belief_Selected_Distance belief_confidence = self.player.Belief_Selected_Confidence self.player.calculate_total_payoff2() return dict( player_in_all_rounds=player_in_all_rounds, show_belief_bonus=show_belief_bonus, belief_bonus_round=belief_bonus_round, belief_bonus=belief_bonus, belief_guess=belief_guess, belief_true_threshold=belief_true_threshold, belief_distance=belief_distance, belief_confidence=belief_confidence, ) page_sequence = [ B_Instructions1, B_Instructions2, B_Control_Questions1, B_Instructions3, B_Control_Questions2, B_Instructions4, B_Control_Questions3, B_Instructions5, WaitAll, D_Correct_Assignment, D_Intro_Types, D_Intro_Types2, D_Intro_Types3, E_Intro_Title_GREEN, E_Intro_Title_LIGHT, E_Intro_Title_DARK, I_Question2, I_Question3, J_Random_Number, J_Random_NumberB, J_Random_Number2, J_Random_Number2B, J_Wait_Green, I_Question, I_Question2_Belief, I_Question3_Belief, J_Wait_Light, J_Wait_Dark, J_Wait_Group, K_End, K_End2, K_End3, L_ENDEND2, ]