This module extends oTree to allow for randomized app sequencing, wait pages, and partial app randomization in oTree >= 5.4.0.
- Support for Wait Pages: Participants will wait on a wait page until
PLAYERS_PER_GROUPreach that wait page through different randomly assigned apps. - Support for Mixed Randomization: You can specify which apps should be randomized by placing them between
begin_randomize_apps_otreeandend_randomize_apps_otree. - Improved Page Index Handling:
_increment_index_in_pageshas been overridden to iterate through all pages correctly, ensuring that the next app is selected even if it appears earlier in oTree’s internal page index.
To integrate the randomize-apps-otree app into your oTree project, follow these steps:
- Add the App to Your Project:
Ensure that the
begin-randomize-apps-otreeandend-randomize-apps-otreeapp` are included in your oTree project directory. - Add the API to Your Project:
You must also add the folder
randomize_apps_api, this will allow you to import theRandomizedAppPage, as explained below. - Update your Pages
- Every last page of your app, or which already overwrites the method
app_after_this_page, must be a child ofRandomizedAppPageand notPage. - See the section "how to use"
- Every last page of your app, or which already overwrites the method
- Update
settings.py:- Make sure that the
begin-randomize-apps-otreeis the first app in ever configuration of yourSESSION_CONFIGSin yoursettings.pyfile. - The apps you want to randomize must be between the apps
begin-randomize-apps-otreeandend-randomize-apps-otree. - It is possible to define apps you don't want to randomize. But, they must come after the apps that will be randomized. Unfortunately, the other way around is not possible at the moment.
- You must add
randomized_app_sequenceto yourPARTICIPANT_FIELDS. - There are three example configurations in the next section.
- Make sure that the
Now, instead of using a single randomize-app-otree, there are two boundary apps:
begin_randomize_apps_otreeend_randomize_apps_otree
These markers define which apps in app_sequence should be randomized. Below are three example configurations:
{
'name': 'randomize_apps',
'display_name': "Randomize Apps",
'num_demo_participants': 4,
'app_sequence': ['begin_randomize_apps_otree', 'test_app1', 'test_app2', 'test_app3', 'end_randomize_apps_otree'],
}🔹All test apps inside the markers (test_app1, test_app2, test_app3) will be randomized.
{
'name': 'randomize_apps_with_wait_page',
'display_name': "Randomize Apps with a WaitPage",
'num_demo_participants': 4,
'app_sequence': ['begin_randomize_apps_otree', 'test_app1', 'test_app2', 'test_app4', 'end_randomize_apps_otree'],
}🔹 test_app4 Includes a Wait Page.
{
'name': 'mix_randomize_apps',
'display_name': "Randomize Only Some Apps",
'num_demo_participants': 4,
'app_sequence': ['begin_randomize_apps_otree', 'test_app1', 'test_app2', 'test_app3',
'end_randomize_apps_otree', 'test_app5'],
}🔹 Only test_app1, test_app2, and test_app3 will be randomized, while test_app5 remains in a fixed position.
- There are five test apps:
test_app1,test_app2,test_app3,test_app4, andtest_app5. - The system ensures proper iteration through pages, even if the next app in the sequence appears earlier in oTree’s internal indexing.
- Wait pages are now supported, ensuring that participants wait until enough players reach the page before proceeding.
-
Configure Session Settings: Ensure that the
app_sequencein the session configuration includes the apps you want to randomize between the appsbegin-randomize-apps-otreeandend-randomize-apps-otree. Thebegin-randomize-apps-otreeapp should be the first app in the sequence. -
You must use
RandomAppPageinstead ofPagein every page that might exit an app (e.g, the past page of the app, or a page with an exiting condition). All you need to do is to import it withfrom randomize_apps_api.api import RandomAppPage. -
Modify App Pages: In each app that you want to randomize, ensure that the last page or any page with a condition to exit the app includes the
app_after_this_pagemethod. This method should return the next app in the randomized sequence. For example:
from typing import List
from randomize_apps_api.api import *
class SomePage(RandomAppPage):
@staticmethod
def app_after_this_page(player: Player, upcoming_apps: List[str]):
try:
upcoming_app = upcoming_apps[0]
except IndexError:
upcoming_app = upcoming_apps
return upcoming_app- If you need to adapt the randomisation mechanism, all you need to do is to modify the
randomize_appsfunction inbegin_randomize_apps_otree/__init__.py. - If you would like to randomize per group of participants, then you might need to make some changes to the
C.PLAYERS_PER_GROUPconstant inbegin_randomize_apps_otree/__init__.py, and add a WaitPage, so that participants are grouped in your desired way. - DO NOT modify the name of the apps
begin_randomize_apps_otreeandend_randomize_apps_otree.
This repository comes with 3 test configurations so that you can see how the app works, and make any necessary
modifications to adapt it to your needs. All you need to do is run the otree development server with
otree devserver.
Important: To be able to run the test you must set the OTREE_ADMIN_PASSWORD and OTREE_SECRET_KEY
environmental variables, or change them directly in the settings.py file. DO NOT commit these variables to a
public repository!
If you find any issue(s), please report it (them) on the issues page. And feel free to make a pull request with any improvements you make (you'll appear as a collaborator on the repository in this case).
Make sure to describe concisely what happened, and provide enough information to reproduce the issue.
If you find this repository useful, please star it on Github, and cite it in your articles with BibTeX:
@software{elias_fernandez_2025_14763626,
author = {Fernández Domingos, Elias},
title = {randomize-apps-otree: Randomized App Sequencing for oTree},
month = jan,
year = 2025,
publisher = {Zenodo},
version = {v0.1.0},
doi = {10.5281/zenodo.14763626},
url = {https://doi.org/10.5281/zenodo.14763626},
}or in text format:
Fernández Domingos, E. (2025). randomize-apps-otree: Randomized App Sequencing for oTree (v0.1.0) [Computer software]. Zenodo. https://doi.org/10.5281/zenodo.14763626