#1 by Thair_Ahmad
Let's say there is a survey with a couple of pages, and I want to allow enumerators to fill it out as many times as they can within a time limit. If I use rounds to repeat the survey, how to ensure that timeout (say 30 mins) is spanned out across the rounds?
#2
by
BonnEconLab
https://otree.readthedocs.io/en/latest/timeouts.html#timeouts-that-span-multiple-pages describes in detail how to achieve what you intend to do.
#3
by
BonnEconLab
Here is some example code that implements what is described on https://otree.readthedocs.io/en/latest/timeouts.html#timeouts-that-span-multiple-pages:
In the file settings.py, you have to include
SESSION_CONFIGS = [
dict(
name = 'multiround_timeout',
app_sequence = ['multiround_timeout'],
num_demo_participants = 2 # > 1 so we can check that the timeout is indeed player-specific
),
]
PARTICIPANT_FIELDS = [
'expiry',
]
Here are the contents of the file multiround_timeout/__init__.py:
from otree.api import *
import time
doc = """
An app to illustrate a countdown that spans multiple rounds.
"""
class C(BaseConstants):
NAME_IN_URL = 'multiround_timeout'
PLAYERS_PER_GROUP = None
NUM_ROUNDS = 5 # Set to the desired number of rounds
TIMEOUT_SECONDS_TOTAL = 83 # Set to the desired total timeout, e.g., 30 * 60 for 30 minutes
class Subsession(BaseSubsession):
pass
class Group(BaseGroup):
pass
class Player(BasePlayer):
pass
# PAGES
class Start(Page):
@staticmethod
def is_displayed(player):
return player.round_number == 1
@staticmethod
def before_next_page(player, timeout_happened):
player.participant.expiry = C.TIMEOUT_SECONDS_TOTAL + time.time()
# Remember to add 'expiry' to PARTICIPANT_FIELDS in settings.py
class MyPage(Page):
timer_text = 'Time left to complete this section:'
@staticmethod
def get_timeout_seconds(player):
return player.participant.expiry - time.time()
page_sequence = [
Start,
MyPage,
]
This assumes that the associated HTML templates are called Start.html and MyPage.html.
The app that implements this minimal working example is attached as a ZIP archive.
#4 by Thair_Ahmad
Thank you so much.