oTree Forum >

Set the number of rounds in configure session

#1 by rafaelcharris


Is there a way of setting an experiment's number of rounds from the configure session section tab?


#2 by felmola

Hello there Rafa.

According to this thread, you cannot.
If you are working on an app that stops playing after a random number of rounds this might work for you:

I hope this helps.

#3 by rafaelcharris

Thank you, Pipe

#4 by ccrabbe ,

Hi Rafael -

The way that I handle this situation is to set Constants.num_rounds=100 (or a number bigger than I will ever run but more realistically a much smaller number based on the session I'm running) and then there's two ways of only showing the number of rounds you want to.  Mainly, I add a session.config variable (which is settable when starting a session)... something like max_rounds=N, in settings.py:

(1) use if player.round_number > player.session.config['max_rounds']: return False for every page in your app - this way you can set session.config.max_rounds from the session tab and every page past the value set there is passed up in is_displayed

(2) use app_after_this_page in before_next_page on the last Page in your page_sequence for rounds past the value of player.session.config['max_rounds']

There's less code for (2) but (!) might be clearer for others to interpret your code later.


#5 by rafaelcharris

Thank you for this, Chris

#6 by AndreL ,

I used a similar approach to (1), only using the parameter at participant (not session) level.

The main disadvantage is that the database becomes very large, very fast, when you have a lot of player.vars, which could lead to some performance issues if many players are suddenly sending queries to every page to check for the condition.

Something similar to (2) improved performance somehow on a stress test in Heroku.

#7 by rafaelcharris

Thank you for this information, AndreL.
I haven't implemented this. I will come back when I do to let you know what was best.
- Rafa

Write a reply

Set forum username