How to use the otree.api.Currency 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 / public_goods_simple / tests.py View on Github external
def play_round(self):
        yield (pages.Contribute, {'contribution': c(1)})
        yield (pages.Results)
github oTree-org / oTree / trust_simple / tests.py View on Github external
from otree.api import Currency as c, currency_range, SubmissionMustFail
from . import pages
from ._builtin import Bot
from .models import Constants


class PlayerBot(Bot):
    cases = [
        {'offer': c(0), 'return': c(0), 'p1_payoff': c(10), 'p2_payoff': c(0)},
        {'offer': c(5), 'return': c(10), 'p1_payoff': c(15), 'p2_payoff': c(5)},
        {'offer': c(10), 'return': c(30), 'p1_payoff': c(30), 'p2_payoff': c(0)},
    ]

    def play_round(self):
        case = self.case
        if self.player.id_in_group == 1:
            yield (pages.Send, {"sent_amount": case['offer']})

        else:
            for invalid_return in [-1, case['offer'] * Constants.multiplier + 1]:
                yield SubmissionMustFail(
                    pages.SendBack, {'sent_back_amount': invalid_return}
                )
            yield (pages.SendBack, {'sent_back_amount': case['return']})

        if self.player.id_in_group == 1:
github oTree-org / oTree / bargaining / tests.py View on Github external
def play_round(self):

        # start
        yield (pages.Introduction)

        if self.case == 'success':
            request = c(10)
            yield (pages.Request, {"request": request})
            yield (pages.Results)
            assert self.player.payoff == request

        if self.case == 'greedy':
            yield (pages.Request, {"request": Constants.amount_shared})
            yield (pages.Results)
            assert self.player.payoff == 0
github oTree-org / oTree / volunteer_dilemma / models.py View on Github external
def set_payoffs(self):
        players = self.get_players()
        self.num_volunteers = sum([p.volunteer for p in players])
        if self.num_volunteers > 0:
            baseline_amount = Constants.general_benefit
        else:
            baseline_amount = c(0)
        for p in players:
            p.payoff = baseline_amount
            if p.volunteer:
                p.payoff -= Constants.volunteer_cost
github oTree-org / oTree / bargaining / models.py View on Github external
def set_payoffs(self):
        players = self.get_players()
        self.total_requests = sum([p.request for p in players])
        if self.total_requests <= Constants.amount_shared:
            for p in players:
                p.payoff = p.request
        else:
            for p in players:
                p.payoff = c(0)
github oTree-org / oTree / dictator / models.py View on Github external
See: Kahneman, Daniel, Jack L. Knetsch, and Richard H. Thaler. "Fairness
and the assumptions of economics." Journal of business (1986):
S285-S300.

"""


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

    instructions_template = 'dictator/instructions.html'

    # Initial amount allocated to the dictator
    endowment = c(100)


class Subsession(BaseSubsession):
    pass


class Group(BaseGroup):
    kept = models.CurrencyField(
        doc="""Amount dictator decided to keep for himself""",
        min=0,
        max=Constants.endowment,
    )

    def set_payoffs(self):
        p1 = self.get_player_by_id(1)
        p2 = self.get_player_by_id(2)
github oTree-org / oTree / common_value_auction / models.py View on Github external
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():
            import random

            item_value = random.uniform(
                Constants.min_allowable_bid, Constants.max_allowable_bid
            )
            g.item_value = round(item_value, 1)

github oTree-org / oTree / common_value_auction / models.py View on Github external
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():
            import random

            item_value = random.uniform(
                Constants.min_allowable_bid, Constants.max_allowable_bid
            )
            g.item_value = round(item_value, 1)
github oTree-org / oTree / common_value_auction / models.py View on Github external
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():
            import random

            item_value = random.uniform(
                Constants.min_allowable_bid, Constants.max_allowable_bid
            )
            g.item_value = round(item_value, 1)


class Group(BaseGroup):
    item_value = models.CurrencyField(
        doc="""Common value of the item to be auctioned, random for treatment"""
github oTree-org / oTree / volunteer_dilemma / models.py View on Github external
See: Diekmann, A. (1985). Volunteer's dilemma. Journal of Conflict
Resolution, 605-610.
"""


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

    instructions_template = 'volunteer_dilemma/instructions.html'

    num_other_players = players_per_group - 1

    # """Payoff for each player if at least one volunteers"""
    general_benefit = c(100)

    # """Cost incurred by volunteering player"""
    volunteer_cost = c(40)


class Subsession(BaseSubsession):
    pass


class Group(BaseGroup):
    num_volunteers = models.IntegerField()

    def set_payoffs(self):
        players = self.get_players()
        self.num_volunteers = sum([p.volunteer for p in players])
        if self.num_volunteers > 0: