from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from . import models from .models import Constants import itertools import numpy as np from sklearn.utils import shuffle class Age_page(Page): def is_displayed(self): # return self.round_number == 1 and self.session.config['introduction'] == 'soc' and self.session.config['explicit'] == 'implicit' return self.round_number == 1 form_model = models.Player form_fields = ['sub_num'] class Introduction(Page): # timeout_seconds = 600 def is_displayed(self): # return self.round_number == 1 and self.session.config['introduction'] == 'soc' and self.session.config['explicit'] == 'implicit' return self.round_number == 1 # form_model = models.Player # form_fields = ['test_question_{}'.format(ii) for ii in range(1, 9)] form_model = models.Player tmp = ['test_question_{}'.format(ii) for ii in range(1, 9)] # ff = ['age', 'gender'] # form_fields = tmp + ff form_fields = tmp def error_message(self, values): if values['test_question_1'] == 'TRUE' or values['test_question_2'] == 'FALSE' or values[ 'test_question_3'] == 'TRUE' or values['test_question_4'] == 'FALSE' or values[ 'test_question_5'] == 'TRUE' or values['test_question_6'] == 'FALSE' or values[ 'test_question_7'] == 'NON-SOCIAL' or values['test_question_8'] == 'SOCIAL': return 'One or more test questions is incorrect, please either re-read instructions or alert researcher for explanation of rules' class Explicit_Introduction(Page): # timeout_seconds = 600 def is_displayed(self): # return self.round_number == 1 and self.session.config['introduction'] == 'soc' and self.session.config['explicit'] == 'explicit' return self.round_number == 1 form_model = models.Player tmp = ['test_question_{}'.format(ii) for ii in range(1, 11)] # ff = ['age', 'gender'] # form_fields = tmp+ff # ff = ['age', 'gender'] # ff = Constants.sub_number % 4 form_fields = tmp def vars_for_template(self): self.player.set_condition() # self.player.sub_condition() def error_message(self, values): if self.player.sub_condition == 1 or self.player.sub_condition == 2: if values['test_question_1'] == 'TRUE' or values['test_question_2'] == 'FALSE' or values[ 'test_question_3'] == 'TRUE' or values['test_question_4'] == 'FALSE' or values[ 'test_question_5'] == 'TRUE' or values['test_question_6'] == 'FALSE' or values[ 'test_question_7'] == 'NON-SOCIAL' or values['test_question_8'] == 'SOCIAL'\ or not values['test_question_9'] == 'Groups of responders who received different starting endowments'\ or not values['test_question_10'] == 'Computer responses programmed to mimic responders who received different starting endowments': return 'One or more test questions is incorrect, please either re-read instructions or alert researcher for explanation of rules' elif self.player.sub_condition == 0 or self.player.sub_condition == 3: if values['test_question_1'] == 'TRUE' or values['test_question_2'] == 'FALSE' or values[ 'test_question_3'] == 'TRUE' or values['test_question_4'] == 'FALSE' or values[ 'test_question_5'] == 'TRUE' or values['test_question_6'] == 'FALSE' or values[ 'test_question_7'] == 'SOCIAL' or values['test_question_8'] == 'NON-SOCIAL'\ or not values['test_question_9'] == 'Groups of responders who received different starting endowments'\ or not values['test_question_10'] == 'Computer responses programmed to mimic responders who received different starting endowments': return 'One or more test questions is incorrect, please either re-read instructions or alert researcher for explanation of rules' class Priors_instructions(Page): def is_displayed(self): return self.round_number == 1 class Final(Page): def is_displayed(self): return self.round_number == Constants.num_rounds def vars_for_template(self): self.player.round_to_pay() def after_all_players_arrive(self): self.player.round_to_pay() def before_session_starts(self): self.round_list = range(1, self.round_number + 1) self.payout_chosen_trial = shuffle(self.round_list) self.participant.vars['payout_chosen_trial'] = self.payout_chosen_trial[0] class Offer(Page): form_model = models.Group form_fields = ['option_chosen'] def is_displayed(self): return self.player.id_in_group == 1 # timeout_seconds = 600 def vars_for_template(self): self.group.set_responder_identity() self.group.soc_or_no = 'Social' class ResultsWaitPage(WaitPage): timeout_seconds = 1 def after_all_players_arrive(self): self.group.set_payoffs() class Results(Page): def vars_for_template(self): self.group.set_payoffs() def after_all_players_arrive(self): self.group.set_payoffs() class Dictator_Instructions(Page): def is_displayed(self): return self.round_number == 1 form_model = models.Player form_fields = ['test_question_{}'.format(ii) for ii in range(11, 15)] def error_message(self, values): if values['test_question_11'] == 'That I select offer the given offer' or values[ 'test_question_12'] == 'TRUE' or values['test_question_13'] == 'FALSE' or values[ 'test_question_14'] == 'FALSE': return 'One or more test questions is incorrect, please either re-read instructions or alert researcher for explanation of rules' class Dictator_Introduction(Page): def is_displayed(self): return self.round_number == 1 form_model = models.Player form_fields = ['test_question_{}'.format(ii) for ii in range(11, 15)] def error_message(self, values): if values['test_question_11'] == 'That I select offer the given offer' or values[ 'test_question_12'] == 'TRUE' or values['test_question_13'] == 'FALSE' or values[ 'test_question_14'] == 'FALSE': return 'One or more test questions is incorrect, please either re-read instructions or alert researcher for explanation of rules' page_sequence = [Age_page, Explicit_Introduction, Dictator_Introduction, Final]