from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) from time import time author = 'David Lucius' doc = """ created by: David Lucius (david.lucius@posteo.de) """ class Constants(BaseConstants): name_in_url = 'TREATMENT_02' players_per_group = None num_rounds = 50 # Set: Time for argument collecting argument_collecting_time = 1200 class Subsession(BaseSubsession): def creating_session(self): # Set: Group Structure self.set_group_matrix(self.session.vars['treatment_app_group_structure']) def get_current_timestamp(self): # Return: Current timestamp return time() class Group(BaseGroup): pass class Player(BasePlayer): # Who sent the argument? ARGUMENT_FROM_PLAYER = models.StringField(max_length=3, blank=True) # What is the number of this argument in the table? ARGUMENT_NUMBER = models.IntegerField(blank=True) # Screen: CollectArguments ARGUMENT_TYPE = models.StringField(max_length=7, blank=True) PRO_ARG_TEXT = models.LongStringField(blank=True) CON_ARG_TEXT = models.LongStringField(blank=True) # Screen: MostConvincingArguments # Attention! If you want the fields not blank, you have to do it with jQuery! MOST_CONV_PRO_ARG = models.IntegerField(min=1, max=Constants.num_rounds, blank=True) MOST_CONV_CON_ARG = models.IntegerField(min=1, max=Constants.num_rounds, blank=True) def get_arguments_for_template(self): # Initialize: Dictionary for row loop in template table = dict() # Initialize: Counter for pro and contra arguments pro_counter = 0 con_counter = 0 # Loop: All possible table rows for i in list(range(0, self.session.config['max_num_arguments_table_rows'])): # Add: Row number as key and an empty dictionary for the arguments table[i] = dict() # Initialize: Arguments display numbers table[i]['number'] = list() # Add: Arguments display numbers table[i]['number'].append(i * 2 + 1) table[i]['number'].append(i * 2 + 2) # Loop: All ended rounds for i in list(range(0, self.subsession.round_number)): # Check: Is the argument in this round a pro argument? if self.in_round(i + 1).ARGUMENT_TYPE == 'PRO': # Add: Pro argument to dictionary table[pro_counter]['pro'] = self.in_round(i + 1).PRO_ARG_TEXT # Increase: Pro counter pro_counter += 1 # Check: Is the argument in this round a contra argument? elif self.in_round(i + 1).ARGUMENT_TYPE == 'CONTRA': # Add: Contra argument to pro list table[con_counter]['con'] = self.in_round(i + 1).CON_ARG_TEXT # Increase: Contra counter con_counter += 1 return table def set_next_player_to_argument_collector(self): # Get: Number of players in treatment 2 number_of_players_in_group = len(self.group.get_players()) # Get: Next argument collectors group id next_argument_collectors_group_id = self.id_in_group + 1 if number_of_players_in_group > self.id_in_group else 1 # Set: Next argument collector to true for the next player self.group.get_player_by_id(next_argument_collectors_group_id).participant.vars[ 'is_next_argument_collector'] = True