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_01' players_per_group = None num_rounds = 30 # Set: Time for argument collecting argument_collecting_time = 1200 class Subsession(BaseSubsession): def get_current_timestamp(self): # Return: Current timestamp return time() class Group(BaseGroup): pass class Player(BasePlayer): # What is the number of this argument in the table? ARGUMENT_NUMBER = models.IntegerField(min=1, max=30, blank=True) # Screen: CollectArguments ARGUMENT_TYPE = models.StringField(max_length=6, blank=True) PRO_ARG_TEXT = models.LongStringField(max_length=10000, blank=True) CON_ARG_TEXT = models.LongStringField(max_length=10000, 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