0

oTree 的新手,所以如果这是一个非常微不足道的问题,我深表歉意。我试图弄清楚如何将我的参与者.var 变量传递到管理员和导出的数据字段中。

我的 model.py 子会话类具有以下内容:

def creating_session(self):
     # randomize treatments
     if self.round_number == 1:
          for p in self.get_players():
               p.participant.vars['treatment'] = random.choice(['no_info', 'full_info', 'info_choice'])

我的球员班有

treatment = models.StringField()

participant_vars_treatment = models.LongStringField()

def treatment_allocation(self):
     self.player.participant_vars_treatment = str(self.participant.vars['treatment'])

这不会在新变量中产生随机处理participant_vars_treatment。有人能指出我正确的方向吗?任何帮助都会很棒!

4

1 回答 1

0

解决方案:

在子会话类中:

def creating_session(self):
     # randomize treatments
     import itertools
          treatments = itertools.cycle(['no_info', 'full_info', 'info_choice'])
          if self.round_number == 1:
               for p in self.get_players():
                    p.participant.vars['treatment'] = next(treatments)
                    treatment = next(treatments)
                    p.participant.vars['treatment'] = treatment
                    p.treatment = treatment

然后在 play 类中进行以下操作:

treatment = models.StringField()
于 2020-05-18T21:18:42.300 回答