randomize-apps-otree

Fix to randomize apps in oTree >= 5.4.0

https://github.com/socrats/randomize-apps-otree

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
Last synced: 6 months ago · JSON representation ·

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
Created about 1 year ago · Last pushed 10 months ago
Metadata Files
Readme Changelog Contributing License Citation

README.md

DOI

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_GROUP reach 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_otree and end_randomize_apps_otree.
  • Improved Page Index Handling: _increment_index_in_pages has 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:

  1. Add the App to Your Project: Ensure that the begin-randomize-apps-otree and end-randomize-apps-otree app` are included in your oTree project directory.
  2. Add the API to Your Project: You must also add the folder randomize_apps_api, this will allow you to import the RandomizedAppPage, as explained below.
  3. Update your Pages
    • Every last page of your app, or which already overwrites the method app_after_this_page, must be a child of RandomizedAppPage and not Page.
    • See the section "how to use"
  4. Update settings.py:
    • Make sure that the begin-randomize-apps-otree is the first app in ever configuration of your SESSION_CONFIGS in your settings.py file.
    • The apps you want to randomize must be between the apps begin-randomize-apps-otree and end-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_sequence to your PARTICIPANT_FIELDS.
    • There are three example configurations in the next section.

🔧 Configuration Examples

Now, instead of using a single randomize-app-otree, there are two boundary apps:

  • begin_randomize_apps_otree
  • end_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, and test_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

  1. Configure Session Settings: Ensure that the app_sequence in the session configuration includes the apps you want to randomize between the apps begin-randomize-apps-otree and end-randomize-apps-otree. The begin-randomize-apps-otree app should be the first app in the sequence.
  2. You must use RandomAppPage instead ofPage in 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 with from randomize_apps_api.api import RandomAppPage.

  3. 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 theapp_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_apps function in begin_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_GROUP constant in begin_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_otree and end_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

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

Committers

Last synced: 7 months ago

All Time
  • Total Commits: 20
  • Total Committers: 1
  • Avg Commits per committer: 20.0
  • Development Distribution Score (DDS): 0.0
Past Year
  • Commits: 20
  • Committers: 1
  • Avg Commits per committer: 20.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
eliasfernandez S****s 20

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

requirements.txt pypi
  • otree >=5.4.0
  • psycopg2 >=2.8.4
  • sentry-sdk ==2.8.0