Control number of participants for each session

253 views
Skip to first unread message

Hakan Pusmaz

unread,
Apr 15, 2021, 10:47:33 AM4/15/21
to oTree help & discussion
Hello everyone,

I have implemented an experiment with 12 treatments. So I have 12 sessions where i would like to control the number of participants. A session should be closed when a certain number of participants have finished it (worked the session to the end). Ideally, after closing, when more participants try to join, a message like "thank you for your interest, the experiment is already closed" should appear. Is there any way to realize something like that?

Best regards 
Hakan

Chris @ oTree

unread,
Apr 15, 2021, 10:58:33 AM4/15/21
to oTree help & discussion
You can implement this logic in your app. Define a session field called num_participants_finished, set it to 0 initially, then each time a participant finishes, increment it by 1.
On the first page, you can block participants from proceeding if the session is full:

class SorryFull(Page):
  @staticmethod
  def is_displayed(player):
    session = player.session
    return session.num_participants_finished > 20

The template for that page would just have a message that tells them the session is full.

Hakan Pusmaz

unread,
Apr 17, 2021, 5:30:43 AM4/17/21
to oTree help & discussion

Hi Chris, 

thank you very much for your help! Unfortunately, I don't know where to define the session field. I have tried it directly in session.py with this statement "SESSION_FIELDS = ['num_participants_finished']" and also in the SESSION_CONFIGS. But it doesn't work. I'm getting the error "Session has no field "num_participants_finished". May you tell me were I have to define the session fields?

Best regards
Hakan

Chris @ oTree

unread,
Apr 17, 2021, 5:48:33 AM4/17/21
to oTree help & discussion
Can you show the code where you are trying to set this field, and the error traceback?

Chris @ oTree

unread,
Apr 17, 2021, 5:50:09 AM4/17/21
to oTree help & discussion
Also, what version of oTree? SESSION_FIELDS is new in oTree 5.

Hakan Pusmaz

unread,
Apr 17, 2021, 5:52:53 AM4/17/21
to oTree help & discussion
I'm coding with version 3.3.11. 

Chris @ oTree

unread,
Apr 17, 2021, 5:55:28 AM4/17/21
to oTree help & discussion
for oTree 3, you should use this version of the docs: https://otree.readthedocs.io/en/self/
see the note at the top of each page.

Hakan Pusmaz

unread,
Apr 17, 2021, 5:58:43 AM4/17/21
to oTree help & discussion
Thank you, Chris! I will try it with session.vars. 

Hakan Pusmaz

unread,
Apr 18, 2021, 3:48:43 AM4/18/21
to oTree help & discussion

Hi Chris, 

I implemented the participant control as you recommended. Thank you very much!

Best regards 
Hakan
Reply all
Reply to author
Forward
0 new messages