randomize-apps-otree
Fix to randomize apps in oTree >= 5.4.0
Science Score: 67.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 8 DOI reference(s) in README -
✓Academic publication links
Links to: zenodo.org -
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (9.5%) to scientific vocabulary
Repository
Fix to randomize apps in oTree >= 5.4.0
Basic Info
- Host: GitHub
- Owner: Socrats
- License: apache-2.0
- Language: Python
- Default Branch: main
- Size: 61.5 KB
Statistics
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 1
Metadata Files
README.md
Randomized App Sequencing for oTree
This module extends oTree to allow for randomized app sequencing, wait pages, and partial app randomization in oTree >= 5.4.0.
🚀 Features
- 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.
✅ Integration with oTree
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
🔧 Configuration Examples
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:
1️⃣ Randomizing All Apps
python
{
'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.
2️⃣ Randomizing Apps with a Wait Page
python
{
'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.
3️⃣ Partially Randomizing Apps
python
{
'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.
📝 Notes
- 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.
How to use
- 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:
```python from typing import List from randomizeappsapi.api import *
class SomePage(RandomAppPage): @staticmethod def appafterthispage(player: Player, upcomingapps: List[str]): try: upcomingapp = upcomingapps[0] except IndexError: upcomingapp = upcomingapps return upcoming_app ```
Modify the randomisation
- 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.
Test
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!
Report issues
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.
Acknowledgements
If you find this repository useful, please star it on Github, and cite it in your articles with BibTeX:
TeX
@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
Owner
- Name: Elias Fernandez
- Login: Socrats
- Kind: user
- Location: Brussels, Belgium
- Company: Université Libre de Bruxelles
- Twitter: esocrats
- Repositories: 6
- Profile: https://github.com/Socrats
Postdoctoral Researcher at MLG and @vub-ai-lab. Interested in machine learning, reinforcement learning, evolutionary game theory and human behavior
Citation (CITATION.cff)
cff-version: 1.2.0
title: 'randomize-apps-otree: Randomized App Sequencing for oTree'
abstract: >-
This module extends oTree to allow for randomized app sequencing, wait pages,
and partial app randomization in oTree >= 5.4.0.
message: >-
Please cite this software using the metadata from 'preferred-citation'.
type: software
authors:
- family-names: "Fernández Domingos"
given-names: "Elias"
orcid: "https://orcid.org/0000-0002-4717-7984"
affiliation: "AI Lab, Vrije Universiteit Brussel"
email: "elias.fernandez.domingos@vub.be"
keywords:
- oTree
- Behavioural Experiments
version: 0.1.0
doi: "10.5281/zenodo.14763626"
date-released: "2025-01-29"
url: "https://github.com/Socrats/randomize-apps-otree"
license: "Apache-2.0"
preferred-citation:
type: article
authors:
- family-names: "Fernández Domingos"
given-names: "Elias"
orcid: "https://orcid.org/0000-0002-4717-7984"
title: "randomize-apps-otree: Randomized App Sequencing for oTree"
publisher: "Zenodo"
date-released: "2025-01-29"
version: "0.1.0"
url: "https://doi.org/10.5281/zenodo.14763626"
GitHub Events
Total
- Release event: 2
- Watch event: 3
- Push event: 14
- Create event: 3
Last Year
- Release event: 2
- Watch event: 3
- Push event: 14
- Create event: 3
Issues and Pull Requests
Last synced: 7 months ago
All Time
- Total issues: 0
- Total pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Total issue authors: 0
- Total pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels
Dependencies
- otree >=5.4.0
- psycopg2 >=2.8.4
- sentry-sdk ==2.8.0