How to use the otree.api.BaseConstants function in otree

To help you get started, we’ve selected a few otree examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github oTree-org / oTree / cournot / models.py View on Github external
BaseSubsession,
    BaseGroup,
    BasePlayer,
    Currency as c,
    currency_range,
)


doc = """
In Cournot competition, firms simultaneously decide the units of products to
manufacture. The unit selling price depends on the total units produced. In
this implementation, there are 2 firms competing for 1 period.
"""


class Constants(BaseConstants):
    name_in_url = 'cournot'
    players_per_group = 2
    num_rounds = 1

    instructions_template = 'cournot/instructions.html'

    # Total production capacity of all players
    total_capacity = 60
    max_units_per_player = int(total_capacity / players_per_group)


class Subsession(BaseSubsession):
    pass


class Group(BaseGroup):
github Leeps-Lab / high_frequency_trading / hft / models.py View on Github external
import copy
from otree.common_internal import random_chars_8
from . import utility
from .trader import TraderFactory
from .trade_session import TradeSessionFactory
from .market import MarketFactory
from .cache import initialize_model_cache, set_market_id_table, get_market_id_table
from .exogenous_event import ExogenousEventModelFactory
from . import market_environments
from django.utils import timezone

from .dispatcher import DispatcherFactory

log = logging.getLogger(__name__)

class Constants(BaseConstants):
    name_in_url = 'hft'
    players_per_group = None
    num_rounds = 3


class Subsession(BaseSubsession):
    model_name = models.StringField(initial='subsession')
    auction_format = models.StringField()
    session_duration = models.IntegerField()
    batch_length = models.IntegerField(initial=0)
    code = models.CharField(default=random_chars_8)

    def creating_session(self):
        def create_trade_session(session_format):
            trade_session_cls = TradeSessionFactory.get_session(session_format)
            dispatcher = DispatcherFactory.get_dispatcher(session_format)
github oTree-org / oTree / guess_two_thirds / models.py View on Github external
BasePlayer,
    Currency,
)


doc = """
a.k.a. Keynesian beauty contest.

Players all guess a number; whoever guesses closest to
2/3 of the average wins.

See https://en.wikipedia.org/wiki/Guess_2/3_of_the_average
"""


class Constants(BaseConstants):
    players_per_group = 3
    num_rounds = 3
    name_in_url = 'guess_two_thirds'

    jackpot = Currency(100)
    guess_max = 100

    instructions_template = 'guess_two_thirds/instructions.html'


class Subsession(BaseSubsession):
    pass


class Group(BaseGroup):
    two_thirds_avg = models.FloatField()
github oTree-org / oTree / public_goods_simple / models.py View on Github external
from otree.api import (
    models,
    widgets,
    BaseConstants,
    BaseSubsession,
    BaseGroup,
    BasePlayer,
    Currency as c,
    currency_range,
)


class Constants(BaseConstants):
    name_in_url = 'public_goods_simple'
    players_per_group = 3
    num_rounds = 1

    endowment = c(100)
    multiplier = 1.8


class Subsession(BaseSubsession):
    pass


class Group(BaseGroup):
    total_contribution = models.CurrencyField()
    individual_share = models.CurrencyField()
github WZBSocialScienceCenter / otreeutils / otreeutils_example2 / models.py View on Github external
from otree.api import (
    models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer,
    Currency as c, currency_range
)

from otreeutils.surveys import create_player_model_for_survey, generate_likert_field, generate_likert_table


author = 'Markus Konrad'

doc = """
Example 2 for usage of the otreeutils package.
"""


class Constants(BaseConstants):
    name_in_url = 'otreeutils_example2'
    players_per_group = None
    num_rounds = 1


class Subsession(BaseSubsession):
    def creating_session(self):
        for i, p in enumerate(self.get_players()):
            p.treatment = (i % 2) + 1   # every second player gets treatment 2


class Group(BaseGroup):
    pass


# some pre-defined choices
github WZBSocialScienceCenter / otree_custom_models / example_decisions / models.py View on Github external
from otree.api import (
    models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer,
    Currency as c, currency_range
)

from otree.db.models import Model, ForeignKey


author = 'Markus Konrad'

doc = """
Custom models example: Arbitrary number of complex decisions per player.
"""


class Constants(BaseConstants):
    name_in_url = 'example_decisions'
    players_per_group = None
    num_rounds = 3
    num_decisions_per_round = 5


class Subsession(BaseSubsession):
    def before_session_starts(self):   # called each round
        """For each player, create a fixed number of "decision stubs" with random values to be decided upon later."""
        for p in self.get_players():
            p.generate_decision_stubs()


class Group(BaseGroup):
    pass
github oTree-org / oTree / public_goods / models.py View on Github external
widgets,
    BaseConstants,
    BaseSubsession,
    BaseGroup,
    BasePlayer,
    Currency as c,
    currency_range,
)


doc = """
This is a one-period public goods game with 3 players.
"""


class Constants(BaseConstants):
    name_in_url = 'public_goods'
    players_per_group = 3
    num_rounds = 1

    instructions_template = 'public_goods/instructions.html'

    # """Amount allocated to each player"""
    endowment = c(100)
    multiplier = 2


class Subsession(BaseSubsession):
    def vars_for_admin_report(self):
        contributions = [
            p.contribution for p in self.get_players() if p.contribution != None
        ]
github oTree-org / oTree / payment_info / models.py View on Github external
BaseConstants,
    BaseSubsession,
    BaseGroup,
    BasePlayer,
    Currency as c,
    currency_range,
)


doc = """
This application provides a webpage instructing participants how to get paid.
Examples are given for the lab and Amazon Mechanical Turk (AMT).
"""


class Constants(BaseConstants):
    name_in_url = 'payment_info'
    players_per_group = None
    num_rounds = 1


class Subsession(BaseSubsession):
    pass


class Group(BaseGroup):
    pass


class Player(BasePlayer):
    pass
github oTree-org / oTree / common_value_auction / models.py View on Github external
Currency as c,
    currency_range,
)


doc = """
In a common value auction game, players simultaneously bid on the item being
auctioned.<br>
Prior to bidding, they are given an estimate of the actual value of the item.
This actual value is revealed after the bidding.<br>
Bids are private. The player with the highest bid wins the auction, but
payoff depends on the bid amount and the actual value.<br>
"""


class Constants(BaseConstants):
    name_in_url = 'common_value_auction'
    players_per_group = None
    num_rounds = 1

    instructions_template = 'common_value_auction/instructions.html'

    min_allowable_bid = c(0)
    max_allowable_bid = c(10)

    # Error margin for the value estimates shown to the players
    estimate_error_margin = c(1)


class Subsession(BaseSubsession):
    def creating_session(self):
        for g in self.get_groups():
github oTree-org / oTree / bertrand / models.py View on Github external
BasePlayer,
    Currency as c,
    currency_range,
)


doc = """
2 firms complete in a market by setting prices for homogenous goods.

See "Kruse, J. B., Rassenti, S., Reynolds, S. S., & Smith, V. L. (1994).
Bertrand-Edgeworth competition in experimental markets.
Econometrica: Journal of the Econometric Society, 343-371."
"""


class Constants(BaseConstants):
    players_per_group = 2
    name_in_url = 'bertrand'
    num_rounds = 1

    instructions_template = 'bertrand/instructions.html'

    maximum_price = c(100)


class Subsession(BaseSubsession):
    pass


class Group(BaseGroup):
    winning_price = models.CurrencyField()