from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import random class Description(Page): def is_displayed(self): return self.round_number == 1 def vars_for_template(self): return { 'N_rounds': self.session.vars['N_rounds'], 'Industry_1': self.player.participant.vars['industries']['Industry_1']['name'], 'Industry_2': self.player.participant.vars['industries']['Industry_2']['name'], 'treatment': self.participant.vars['treatment'], 'bonus_portfolio': c(self.session.vars['bonus']['portfolio']), 'bonus_elicit': c(self.session.vars['bonus']['elicit']) } class PortEval(Page): form_model = 'player' form_fields = ['belief_1', 'belief_2', 'choice'] def is_displayed(self): return self.participant.vars['treatment'] == 'treatment' and self.round_number <= self.session.vars['N_rounds'] def vars_for_template(self): return { 'N_rounds': self.session.vars['N_rounds'], 'round_number': self.round_number, 'N_firms': self.player.participant.vars[self.round_number]['Portfolio_1']['N_firms'], 'N_firms_pay': self.player.participant.vars[self.round_number]['Portfolio_1']['N_firms_pay'], 'bonus_elicit': c(self.session.vars['bonus']['elicit']), 'bonus_portfolio': c(self.session.vars['bonus']['portfolio']), 'winning_prob_prior': str(format( self.player.participant.vars[self.round_number]['Portfolio_1']['winning_prob_prior'], '.0f')), 'firms': list(range(1, self.player.participant.vars[self.round_number]['Portfolio_1']['N_firms']+1)), 'firms_hidden': list(range(self.player.participant.vars[self.round_number]['Portfolio_1']['N_firms']+1, self.session.vars['N_firms_max']+1)), 'P1_firms': [self.player.participant.vars[self.round_number]['Portfolio_1'][i]['industry_name'] for i in range(self.player.participant.vars[self.round_number]['Portfolio_1']['N_firms'])], 'P2_firms': [self.player.participant.vars[self.round_number]['Portfolio_2'][i]['industry_name'] for i in range(self.player.participant.vars[self.round_number]['Portfolio_2']['N_firms'])], 'select_row': self.session.vars['select_row'], 'Industry_1': self.player.participant.vars['industries']['Industry_1']['name'], 'Industry_2': self.player.participant.vars['industries']['Industry_2']['name'], 'puzzle_solution': self.player.participant.vars['industries']['puzzle_solution'] } def before_next_page(self): self.player.own = self.player.choice self.player.own_type = self.player.participant.vars[self.round_number][self.player.own]['type'] self.player.participant.vars[self.round_number]['own'] = self.player.own self.player.participant.vars[self.round_number]['Portfolio_1']['belief'] = self.player.belief_1 self.player.participant.vars[self.round_number]['Portfolio_2']['belief'] = self.player.belief_2 class Eval(Page): form_model = 'player' form_fields = ['belief_1', 'belief_2'] def is_displayed(self): return self.participant.vars['treatment'] == 'control' and self.round_number <= self.session.vars['N_rounds'] def vars_for_template(self): return { 'N_rounds': self.session.vars['N_rounds'], 'round_number': self.round_number, 'N_firms': self.player.participant.vars[self.round_number]['Portfolio_1']['N_firms'], 'N_firms_pay': self.player.participant.vars[self.round_number]['Portfolio_1']['N_firms_pay'], 'bonus_elicit': c(self.session.vars['bonus']['elicit']), 'bonus_portfolio': c(self.session.vars['bonus']['portfolio']), 'assigned': self.player.own, 'assigned_display': self.player.own.replace('_', ' '), 'winning_prob_prior': str(format( self.player.participant.vars[self.round_number]['Portfolio_1']['winning_prob_prior'], '.0f')), 'firms': list(range(1, self.player.participant.vars[self.round_number]['Portfolio_1']['N_firms']+1)), 'firms_hidden': ['x' for i in range(self.session.vars['N_firms_max'] - self.player.participant.vars[self.round_number]['Portfolio_1']['N_firms'])], 'P1_firms': [self.player.participant.vars[self.round_number]['Portfolio_1'][i]['industry_name'] for i in range(self.player.participant.vars[self.round_number]['Portfolio_1']['N_firms'])], 'P2_firms': [self.player.participant.vars[self.round_number]['Portfolio_2'][i]['industry_name'] for i in range(self.player.participant.vars[self.round_number]['Portfolio_2']['N_firms'])], 'P1_row_color': self.session.vars['select_row'] if self.player.own == 'Portfolio_1' else 'transparent', 'P2_row_color': self.session.vars['select_row'] if self.player.own == 'Portfolio_2' else 'transparent', 'Industry_1': self.player.participant.vars['industries']['Industry_1']['name'], 'Industry_2': self.player.participant.vars['industries']['Industry_2']['name'], 'puzzle_solution': self.player.participant.vars['industries']['puzzle_solution'] } def before_next_page(self): self.player.own_type = self.player.participant.vars[self.round_number][self.player.own]['type'] self.player.participant.vars[self.round_number]['own'] = self.player.own self.player.participant.vars[self.round_number]['Portfolio_1']['belief'] = self.player.belief_1 self.player.participant.vars[self.round_number]['Portfolio_2']['belief'] = self.player.belief_2 page_sequence = [ Description, PortEval, Eval ]