- Duration: 16 Academic Hours
 
  - No programming experience required
 
              - Recommended: Basic Python knowledge and oTree tutorials
 
              
              
              ๐น๏ธ Example Code
              
              ๐งช Demos
              
              ๐ง oTree Tools and Projects
              
      
      
      
          ๐ Guides and Tutorials
          
      
  
              
      
  
  
  
      
          
      
  
  
  
      
          
              
              Programming Experiments Overview
  
              
      
  
  
  
      
          
              
              Popular Platforms for Experimentation
  
              
      
  
  
  
      
          
              
              
  
  
  
  | Platform | 
  Launch | 
  Core Components | 
  Languages | 
  Key Features | 
  
  
  
  
  | oTree | 
  2013 | 
  Django, Starlette | 
  Python, JS | 
  N-players, real-time, custom UI | 
  
  
  | zTree | 
  1998 | 
  Client-server | 
  Pascal-like | 
  Own simple exp language | 
  
  
  | Qualtrics | 
  2002 | 
  Survey engine, js-friendly | 
  No coding | 
  Advanced surveys, branching logic, self-hosting | 
  
  
  | PsychoPy/jsPsych | 
  2003/2012 | 
  Python/JS /assets/html/export/libs | 
  Python/JavaScript | 
  Precise timing, visual stimuli, online/offline experiments | 
  
  
  | G.Forms | 
  2008 | 
  Google Cloud | 
  No coding | 
  Basic surveys, easy integration | 
  
  
  
   
  Some others: Lioness; Sofi(PHP), etc.
  
              
      
  
  
  
      
          
              
              Core Concepts of Coding Experiments
  
              
      
  
  
  
      
          
              
              Any experiment consists of two basic actions:
  
  1. Show something (stimulus)
  2. Collect reaction (response)
  
  
  โโโโโโโโโโโโโโโโ     โโโโโโโโโโโโโโโโ
  โ   STIMULUS   โ     โ   RESPONSE   โ
  โ  Show info   โ --> โ   Collect    โ
  โ  Display UI  โ     โ   reaction   โ
  โโโโโโโโโโโโโโโโ     โโโโโโโโโโโโโโโโ
          โฒ                    โ
          โโโโโโโโโโโโโโโโโโโโโโ
          Next iteration
  
  
  E.G. show kitten image and ask happiness level
  Implementation methods:
  
  - Pen and paper (+engagement, -UI)
 
  - Web server (stimulus) โ Browser (response)
 
  - oTree = web framework for this cycle
 
  
   
              
      
  
  
  
      
          
              
              Web Application Architecture
  
  
              
      
              
  
  
      
          
              
              oTree overview (MVC Framework)
  
  - Models: Core logic and database (Starlette, SQLite/PostgreSQL)
 
  - Controller: Page logic, function call order, and event sequence (Starlette, called pages in Django).
 
  - Views/Templates: Front-end structure
  
  - HTML
 
  - CSS (Bootstrap)
 
  - JavaScript
 
  
   
  
  
              
      
  
  
  
      
          
              
              Platform Comparison
  
  
  
  
  | Feature | 
  oTree | 
  zTree | 
  Qualtrics | 
  jsPsych | 
  g.forms | 
  
  
  
  
  | Games | 
  โ | 
  โ | 
  โ | 
  ! | 
  โ | 
  
  
  | N-players | 
  โ | 
  โ | 
  โ | 
  โ | 
  โ | 
  
  
  | Online | 
  โ | 
  ! | 
  โ | 
  โ | 
  โ | 
  
  
  | Code Req. | 
  โ | 
  โ | 
  ! | 
  โ | 
  โ | 
  
  
  | Custom UI | 
  โ | 
  ! | 
  ! | 
  โ | 
  โ | 
  
  
  | Free | 
  โ | 
  ! | 
  โ | 
  โ | 
  โ | 
  
  
  | Surveys | 
  โ | 
  ! | 
  โ | 
  ! | 
  โ | 
  
  
  | Mobile | 
  โ | 
  โ | 
  โ | 
  โ | 
  โ | 
  
  
  | Self-host | 
  ! | 
  โ | 
  โ | 
  โ | 
  โ | 
  
  
  | Active community | 
  โ | 
  โ | 
  โ | 
  โ | 
  โ | 
  
  
  
  
  | Legend: | 
  โ Full | 
  ! Limited | 
  โ None | 
  
  
  
   
              
      
  
  
  
      
          
              
              oTree: Conceptual Overview
  
              
      
  
  
  
      
          
              
              oTree Admin Panel
  
  
  
  - Session Monitor: Real-time participant progress tracking
 
  - Data: Live data viewing and CSV/Excel export
 
  - Links: Participant access URLs (demo/study modes)
 
  - Payments: Payment calculations and reports
 
  - Sessions: Create and manage experiment sessions
 
  
   
  Demo: https://otree-more-demos.herokuapp.com/demo
  
              
      
  
  
  
      
          
              
              oTree: webapp (server) and template
  
  
  
  
  | About | 
  Features & Options | 
  
  
  
  
  | Platform | 
  โข Standard web server (like Instagram)   โข  Multiplayer strategy games โข Can integrate what other web can | 
  
  
  | Development | 
  โข Standard: Python + text editor โข No-code: oTree Studio โข Rich documentation & demos | 
  
  
  | Technology | 
  โข Python, Django/Starlette backend โข JS/Bootstrap  frontend   โข SQLite/PostgreSQL | 
  
  
  | Deployment | 
  โข Local server for lab โข Cloud hosting (Heroku) โข oTree Hub integration | 
  
  
  
   
              
      
  
  
  
      
          
              
              Sample experiment: Guessing Game
  Simple game demonstrating core oTree concepts (models, pages, templates)
  Repository structure:
  otree_workshop/
  โโโ guessing_game/            # Example game
      โโโ _static/              # Static files
      โโโ _templates/           # Global templates
      โโโ guessing_app/         # Game application
      โ   โโโ __init__.py      # Game logic
      โ   โโโ Instructions.html # Game pages
      โ   โโโ MyPage.html
      โ   โโโ Results.html
      โโโ settings.py           # Project settings
  
  Code: github.com/gregory-ch/otree_workshop
  
              
      
  
  
  
      
          
              
              Guess Game: Description
  
  - A player has an endowment
 
  - Random number is generated within certain limits
 
  - A player has to guess. The closer is the guess to a real number the larger is the profit
 
  - Two fields:
  
  - what is guessed
 
  - a player's decision
 
  
   
  - Three screens:
  
  - Intro: instructions
 
  - Decision with instructions
 
  - Results
 
  
   
  
  
              
      
  
  
  
      
          
              
              Guessing Game: Instructions Page
  
              
      
  
  
  
      
          
              
              Guessing Game: Decision Page
  
              
      
  
  
  
      
          
              
              Guessing Game: Results Page:
  
              
      
  
  
  
      
          
              
              Introduction to the Model-View-Controller (MVC) framework
  
              
      
  
  
  
      
          
              
              oTree 3 vs oTree 5 (Lite)
  
  
  
  - oTree 3:
  
  - Django-based
 
  - Slower, more complex
 
  - Better documented
 
  - More examples available
 
  - Some custom moduls available:
  
  
 
  
   
  
   
  
  
  - oTree 5:
  
  - Starlette-based (no-self)
 
  - Faster, simpler (No redis, no second dynos)
 
  - Better performance
 
  
   
  
   
              
      
  
  
  
      
          
              
              oTree: Object Hierarchy
  
  Session = Event where participants play games/tasks
  
  - Example: "Lab session with public goods game + questionnaire"
 
  - Includes payments, configurations, participant management
 
  
  
  
   
              
      
  
  
  
      
          
              
              Structure of oTree App
  
  
  - 
  
Pages (Display Logic)
  
  - Page classes (Instructions, Game, Results)
 
  - page_sequence (order of pages)
 
  - Templates (HTML files)
 
  
   
  - 
  
Models (Data Processing)
  
  - Constants: game parameters
 
  - Player (individual);
  Group (interaction); 
Subsession (session-level data & methods) 
  - Functions (calculation of payoffs 
 and other properties based on input) 
  
   
  - 
  
Configuration
  
   
  
   
              
      
  
  
  
      
          
              
              oTree: Initialization Sequence
  
   
  
  - 
  
Session Creation (by Admin)
  
  - Admin creates session (room/demo/single-use link)
 
  - Session configs applied
 
  - Session variables initialized
 
  - Participants slots created
 
  - creating_session() runs:
  
  - Can initialize participant.vars
 
  - Can set participant.label
 
  - Can set initial participant.payoff
 
  
   
  - Subsessions, Groups, Players created
 
  
   
  - 
  
Waiting for Participants
  
  - Links generated and distributed
 
  - Participants slots with pre-initialized vars wait
 
  
   
  
   
   
  
  - 
  
Participant Joins
  
  - Participant opens link
 
  - Gets assigned to pre-created slot
 
  - Accesses their pre-initialized variables
 
  - Starts first page in page_sequence
 
  
   
  - 
  
Page Flow
  
  - 
  
Pages execute in order from page_sequence
   
  - 
  
For each page:
  
  is_displayed() # (should return 
  # True if page is to be shown)
  vars_for_template()
  
  
  before_next_page()
  app_after_this_page()
  
   
  
   
  
   
   
              
      
  
  
  
      
          
              
              oTree: Models Object Hierarchy
  
  Session
      โโโ Subsession
          โโโ Group
              โโโ Player
  
  Access pattern (bottom-up):
  player.participant  # Access participant from player
  player.group       # Access group from player
  player.subsession  # Access subsession from player
  group.subsession   # Access subsession from group
  
   
              
      
  
  
  
      
          
              
              oTree: Players vs Participants
  
  
  Participant = Person playing the experiment
  - Stays constant throughout session
  - Has unique participant code
  - Tracks progress through all games
  
Player = Role in specific subsession
  
  - New player instance for each subsession
 
  - Can have different roles/groups
 
  - Stores game-specific data