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 class Update(Page): form_model = 'player' form_fields = ['belief_first_1', 'belief_first_2'] def is_displayed(self): return 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'], 'first_profit_1': 'profit' if self.player.participant.vars[self.round_number]['Portfolio_1'][0]['profit'] else 'loss', 'first_profit_2': 'profit' if self.player.participant.vars[self.round_number]['Portfolio_2'][0]['profit'] else 'loss', 'bonus_elicit': c(self.session.vars['bonus']['elicit']), 'own': self.player.participant.vars[self.round_number]['own'], '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.participant.vars[self.round_number]['own'] == 'Portfolio_1' else 'transparent', 'P2_row_color': self.session.vars['select_row'] if self.player.participant.vars[self.round_number]['own'] == 'Portfolio_2' else 'transparent', 'belief_1': self.player.participant.vars[self.round_number]['Portfolio_1']['belief'], 'belief_2': self.player.participant.vars[self.round_number]['Portfolio_2']['belief'], '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.participant.vars[self.round_number]['Portfolio_1']['belief_first'] = self.player.belief_first_1 self.player.participant.vars[self.round_number]['Portfolio_2']['belief_first'] = self.player.belief_first_2 class End(Page): def is_displayed(self): return self.round_number == self.session.vars['N_rounds'] page_sequence = [ Description, Update, End ]