简体   繁体   中英

How to add participant.var to data set

New to oTree, so I apologize if this is a super trivial question. I was trying to figure out how to pass my participant.var variable into the admin and exported data fields.

My model.py subsession class has the following:

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

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 . Could someone point me in the right direction? Any help would be great!

Solved solution:

In the subsession 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:

treatment = models.StringField()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM