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 Introduction(Page): # timeout_seconds = 600 def is_displayed(self): return self.round_number == 1 # form_model = models.Player # form_fields = ['test_question_{}'.format(ii) for ii in range(1, 5)] # # def test_question_1_error_message(self, value): # if not (value == 'FALSE'): # return 'Incorrect Answer' # # def test_question_2_error_message(self, value): # if not (value == 'TRUE'): # return 'Incorrect Answer' # # def test_question_3_error_message(self, value): # if not (value == 'FALSE'): # return 'Incorrect Answer' # # def test_question_4_error_message(self, value): # if not (value == 'TRUE'): # return 'Incorrect Answer' class Final(Page): def is_displayed(self): return self.round_number == Constants.num_rounds def vars_for_template(self): self.player.round_to_pay() # self.player.calculate_final_payout() def after_all_players_arrive(self): self.player.round_to_pay() # self.player.calculate_final_payout() 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 = ['amount_offered'] def after_all_players_arrive(self): self.group.set_responder_identity() 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.session.config['treatment'] == 'strategy' if self.session.config['order'] == 'soc_first': if self.round_number <= (Constants.num_rounds/2): self.group.soc_or_no = 'Social' if self.group.current_opponent == 'triangle': return {'image_path': 'my_ultimatum_3cond_block/TRIANGLE_SOC.png'} elif self.group.current_opponent == 'circle': return {'image_path': 'my_ultimatum_3cond_block/CIRCLE_SOC.png'} elif self.group.current_opponent == 'square': return {'image_path': 'my_ultimatum_3cond_block/SQUARE_SOC.png'} elif self.round_number > (Constants.num_rounds/2): self.group.soc_or_no = 'Non-social' if self.group.current_opponent == 'triangle': return {'image_path': 'my_ultimatum_3cond_block/TRIANGLE_COMP.png'} elif self.group.current_opponent == 'circle': return {'image_path': 'my_ultimatum_3cond_block/CIRCLE_COMP.png'} elif self.group.current_opponent == 'square': return {'image_path': 'my_ultimatum_3cond_block/SQUARE_COMP.png'} elif self.session.config['order'] == 'comp_first': if self.round_number > (Constants.num_rounds / 2): self.group.soc_or_no = 'Social' if self.group.current_opponent == 'triangle': return {'image_path': 'my_ultimatum_3cond_block/TRIANGLE_SOC.png'} elif self.group.current_opponent == 'circle': return {'image_path': 'my_ultimatum_3cond_block/CIRCLE_SOC.png'} elif self.group.current_opponent == 'square': return {'image_path': 'my_ultimatum_3cond_block/SQUARE_SOC.png'} elif self.round_number <= (Constants.num_rounds / 2): self.group.soc_or_no = 'Non-social' if self.group.current_opponent == 'triangle': return {'image_path': 'my_ultimatum_3cond_block/TRIANGLE_COMP.png'} elif self.group.current_opponent == 'circle': return {'image_path': 'my_ultimatum_3cond_block/CIRCLE_COMP.png'} elif self.group.current_opponent == 'square': return {'image_path': 'my_ultimatum_3cond_block/SQUARE_COMP.png'} class ResultsWaitPage(WaitPage): pass class Results(Page): def vars_for_template(self): self.group.set_payoffs() # self.group.set_responder_identity() # self.session.config['treatment'] == 'strategy' if self.session.config['order'] == 'soc_first': if self.round_number <= (Constants.num_rounds / 2): self.group.soc_or_no = 'Social' if self.group.current_opponent == 'triangle': return {'image_path': 'my_ultimatum_3cond_block/TRIANGLE_SOC.png'} elif self.group.current_opponent == 'circle': return {'image_path': 'my_ultimatum_3cond_block/CIRCLE_SOC.png'} elif self.group.current_opponent == 'square': return {'image_path': 'my_ultimatum_3cond_block/SQUARE_SOC.png'} elif self.round_number > (Constants.num_rounds / 2): self.group.soc_or_no = 'Non-social' if self.group.current_opponent == 'triangle': return {'image_path': 'my_ultimatum_3cond_block/TRIANGLE_COMP.png'} elif self.group.current_opponent == 'circle': return {'image_path': 'my_ultimatum_3cond_block/CIRCLE_COMP.png'} elif self.group.current_opponent == 'square': return {'image_path': 'my_ultimatum_3cond_block/SQUARE_COMP.png'} elif self.session.config['order'] == 'comp_first': if self.round_number > (Constants.num_rounds / 2): self.group.soc_or_no = 'Social' if self.group.current_opponent == 'triangle': return {'image_path': 'my_ultimatum_3cond_block/TRIANGLE_SOC.png'} elif self.group.current_opponent == 'circle': return {'image_path': 'my_ultimatum_3cond_block/CIRCLE_SOC.png'} elif self.group.current_opponent == 'square': return {'image_path': 'my_ultimatum_3cond_block/SQUARE_SOC.png'} elif self.round_number <= (Constants.num_rounds / 2): self.group.soc_or_no = 'Non-social' if self.group.current_opponent == 'triangle': return {'image_path': 'my_ultimatum_3cond_block/TRIANGLE_COMP.png'} elif self.group.current_opponent == 'circle': return {'image_path': 'my_ultimatum_3cond_block/CIRCLE_COMP.png'} elif self.group.current_opponent == 'square': return {'image_path': 'my_ultimatum_3cond_block/SQUARE_COMP.png'} def after_all_players_arrive(self): self.group.set_payoffs() page_sequence = [Introduction, Offer, Results, Final ]