from otree.api import * from decimal import * class C(BaseConstants): NAME_IN_URL = 'random_num_rounds_multiplayer_end' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 EXCHANGE_RATE = 0.1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): earning_game = models.FloatField() earnings_waitpage = models.FloatField() earnings_participation = models.IntegerField() total_earnings = models.FloatField() avgcontr1 = models.IntegerField(min=-4, max=10) avgcontr2 = models.IntegerField(min=-8, max=10) avgcontr3 = models.IntegerField(min=-12, max=10) avgcontr4 = models.IntegerField(min=-16, max=10) avgcontr5 = models.IntegerField(min=-20, max=10) avgcontr6 = models.IntegerField(min=-24, max=10) avgcontr7 = models.IntegerField(min=-28, max=10) avgcontr8 = models.IntegerField(min=-32, max=10) avgcontr9 = models.IntegerField(min=-36, max=10) avgcontr10 = models.IntegerField(min=-40, max=10) contribution2 = models.CurrencyField(min=0, max=10) q2factors = models.IntegerField( label="Which of the below factors influenced your decision to transfer Points to the group account the most:", widget=widgets.RadioSelect, choices=[ [1, 'The number of Points transferred by other Participants of Type A.'], [2, "The effect of Participant B's decision on the group account."], [3, 'The size of the group account at the end of the round.'], [4, 'I did not base my decisions on any of these three factors.'] ] ) q2dicfactors = models.IntegerField( label="On which of the below objectives did you base your decisions on:", widget=widgets.RadioSelect, choices=[ [1, 'I wanted to maximise my own personal payoff in each round.'], [2, 'I wanted to achieve the maximum payoff for everyone in my group'], [3, 'I wanted all participants in the group (including myself) to receive similar payoffs.'], [4, 'I wanted to be perceived as fair or nice by the other participants.'], [5, 'I made my decisions without a specific reason.'] ] ) q2dicstrategy = models.LongStringField() comments = models.LongStringField(blank=True) # Functions def set_payoffs(player): p = player p.earning_game = float(p.participant.income_game) * C.EXCHANGE_RATE p.earnings_waitpage = p.participant.waiting_earnings * 0.05 p.earnings_participation = 1 p.total_earnings = p.earning_game + p.earnings_waitpage + p.earnings_participation class Strategy(Page): form_model = 'player' @staticmethod def get_form_fields(player): if player.participant.type == 'Citizen': return ['avgcontr1', 'avgcontr2', 'avgcontr3', 'avgcontr4', 'avgcontr5', 'avgcontr6', 'avgcontr7', 'avgcontr8', 'avgcontr9', 'avgcontr10', 'avgcontr3', 'q2factors', 'comments'] else: return ['avgcontr1', 'avgcontr2', 'avgcontr3', 'avgcontr4', 'avgcontr5', 'avgcontr6', 'avgcontr7', 'avgcontr8', 'avgcontr9', 'avgcontr10', 'q2dicfactors', 'q2dicstrategy', 'comments'] @staticmethod def vars_for_template(player): # Calculate the values for the points dynamically points_values = [i * 4 + 4 for i in range(10)] # Calculate the negative values for the sliders negative_values = [-value for value in points_values] # Pass both lists to the template return {'points_values': points_values, 'negative_values': negative_values} class PayOff(Page): @staticmethod def vars_for_template(player): set_payoffs(player) return dict( earning=format(Decimal(player.earning_game), '.2f'), earnings_waitpage=format(Decimal(player.earnings_waitpage), '.2f'), earnings_participation=format(Decimal(player.earnings_participation), '.2f'), total=format(Decimal(player.total_earnings), '.2f') ) class ThankYou(Page): @staticmethod def js_vars(player): return dict( completionlink=player.subsession.session.config['completionlink'] ) page_sequence = [Strategy, PayOff, ThankYou]