[英]How to add participant.var to data set
New to oTree, so I apologize if this is a super trivial question. oTree 的新手,所以如果这是一个非常微不足道的问题,我深表歉意。 I was trying to figure out how to pass my participant.var variable into the admin and exported data fields.我试图弄清楚如何将我的参与者.var 变量传递到管理员和导出的数据字段中。
My model.py subsession class has the following:我的 model.py 子会话 class 具有以下内容:
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'])
and my player class has我的播放器 class 有
treatment = models.StringField()
participant_vars_treatment = models.LongStringField()
def treatment_allocation(self):
self.player.participant_vars_treatment = str(self.participant.vars['treatment'])
This does not produce the randomized treatments into the new variable participant_vars_treatment
.这不会将随机处理生成到新变量participant_vars_treatment
中。 Could someone point me in the right direction?有人能指出我正确的方向吗? Any help would be great!任何帮助都会很棒!
Solved solution:解决方案:
In the subsession class:在子会话 class 中:
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
and then the following in the play class:然后在播放class中如下:
treatment = models.StringField()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.