from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random import re author = 'Magnus Strobel' doc = """ Instructions """ class Constants(BaseConstants): name_in_url = 'instructions' players_per_group = None num_rounds = 1 class Subsession(BaseSubsession): def creating_session(self): if self.round_number == 1: for p in self.get_players(): assigned_treatment_group_1 = random.choices(population=['treatment_1', 'control_1'], weights=[0.5, 0.5], k=1)[0] p.participant.vars['treatment_group_1'] = assigned_treatment_group_1 p.treatment_group_1 = assigned_treatment_group_1 if p.treatment_group_1 == 'treatment_1': assigned_treatment_group_2 = random.choices(population=['treatment_2', 'control_2'], weights=[0.5, 0.5], k=1)[0] p.participant.vars['treatment_group_2'] = assigned_treatment_group_2 p.treatment_group_2 = assigned_treatment_group_2 else: p.participant.vars['treatment_group_2'] = 'control_2' p.treatment_group_2 = 'control_2' class Group(BaseGroup): pass class Player(BasePlayer): treatment_group_1 = models.StringField() treatment_group_2 = models.StringField()