from otree.api import * class C(BaseConstants): NAME_IN_URL = 'test' PLAYERS_PER_GROUP = 3 NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass def creating_session(subsession: Subsession): session = subsession.session session.treat = session.config['treat'] for player in subsession.get_players(): player.participant.progress = 4 player.participant.is_dropout = False class Group(BaseGroup): pass class Player(BasePlayer): 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() def role_assignment(group): if group.round_number == 1: players = group.get_players() num_players = len(players) if num_players == C.PLAYERS_PER_GROUP: # Shuffle the players import random random.shuffle(players) # Assign the first four players as "Citizen" for i in range(num_players - 1): players[i].participant.type = "Citizen" # Assign the last player as "Dictator" players[-1].participant.type = "Dictator" class GroupWaitPage(WaitPage): @staticmethod def is_displayed(player): return player.round_number == 1 group_by_arrival_time = True after_all_players_arrive = role_assignment 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 Intro(Page): @staticmethod def before_next_page(player, timeout_happened): import time participant = player.participant participant.progress = 5 print(participant.progress) # Record time in participant field for waitpage on grouping_waitpage app participant.wait_page_arrival = time.time() print(time.time()) page_sequence = [GroupWaitPage, Strategy, Intro]