oTree Forum >

Set the number of rounds in configure session

#1 by rafaelcharris

Hello, 

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

thanks

#2 by felmola

Hello there Rafa.

According to this thread, you cannot.
https://groups.google.com/g/otree/c/0RdBAOl53N8
If you are working on an app that stops playing after a random number of rounds this might work for you:
https://s3.amazonaws.com/otreehub/browsable_source/1e38462b-46c7-4ca1-bca5-536462f90131/random_num_rounds_multiplayer/index.html

I hope this helps.
Best,
Felipe

#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.

Thanks,
=-Chris

#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

#8 by Trontatuma

This approach might give problems in combination with def creating_session(subsession: Subsession): because it executes the creating_session function NUM_ROUNDS times it seems.

Write a reply

Set forum username