How to use the otree.api.models.BooleanField 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 / 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


class Player(BasePlayer):
    volunteer = models.BooleanField(doc="""Whether player volunteers""")
github Leeps-Lab / high_frequency_trading / hft_bcs / _models.py View on Github external
for process in process_list:
                    try:
                        process.kill()
                    except Exception as e:
                        log.exception(e)




class Subsession(BaseSubsession):
    design = models.StringField()
    next_available_exchange = models.IntegerField()
    players_per_group = models.IntegerField()
    round_length = models.IntegerField()
    batch_length = models.IntegerField(initial=0)
    trade_ended = models.BooleanField(initial=False)
    code = models.CharField(default=random_chars_8)
    has_trial = models.BooleanField(initial=True)
    is_trial = models.BooleanField(initial=False)
    trial_length = models.IntegerField(initial=0)
    log_file = models.StringField()
    first_round = models.IntegerField(initial=1)
    last_round = models.IntegerField(initial=0)
    total_rounds = models.IntegerField(initial=0)
    restore_from = models.CharField()
    restore = models.BooleanField(initial=False)
    lambda_i = models.FloatField()
    lambda_j = models.FloatField()

    def init_cache(self):
        pairs = {}
        session_lock = Constants.lock_key.format(self=self)
github Leeps-Lab / high_frequency_trading / hft_bcs / _models.py View on Github external
except Exception as e:
                        log.exception(e)




class Subsession(BaseSubsession):
    design = models.StringField()
    next_available_exchange = models.IntegerField()
    players_per_group = models.IntegerField()
    round_length = models.IntegerField()
    batch_length = models.IntegerField(initial=0)
    trade_ended = models.BooleanField(initial=False)
    code = models.CharField(default=random_chars_8)
    has_trial = models.BooleanField(initial=True)
    is_trial = models.BooleanField(initial=False)
    trial_length = models.IntegerField(initial=0)
    log_file = models.StringField()
    first_round = models.IntegerField(initial=1)
    last_round = models.IntegerField(initial=0)
    total_rounds = models.IntegerField(initial=0)
    restore_from = models.CharField()
    restore = models.BooleanField(initial=False)
    lambda_i = models.FloatField()
    lambda_j = models.FloatField()

    def init_cache(self):
        pairs = {}
        session_lock = Constants.lock_key.format(self=self)
        pairs[session_lock] = Constants.unlock_value
        ready_groups = Constants.groups_ready_key.format(self=self)
        pairs[ready_groups] = {g.id: False for g in self.get_groups()}
github Leeps-Lab / high_frequency_trading / hft / models.py View on Github external
if self.pk is not None:
            json_fields = {}
            for field in self._meta.get_fields():
                if isinstance(field, JSONField):
                    json_fields[field.attname] = getattr(self, field.attname)
            self.__class__._default_manager.filter(pk=self.pk).update(**json_fields)


class Group(BaseGroup):
    pass


class Player(BasePlayer):

    channel = models.CharField(max_length=255)
    consented = models.BooleanField(initial=False)
    exchange_host = models.CharField()
    exchange_port = models.IntegerField()
    # subsession_id = models.CharField()
    market_id = models.CharField()
    id_in_market = models.IntegerField()
    speed_unit_cost = models.IntegerField()
    net_worth = models.IntegerField()
    cash = models.IntegerField()
    cost = models.IntegerField()
    speed_cost = models.IntegerField()
    tax_paid = models.IntegerField()
    reference_price = models.IntegerField()
    inventory = models.IntegerField()
    bid = models.IntegerField()
    offer = models.IntegerField()
    staged_bid = models.IntegerField()
github Leeps-Lab / high_frequency_trading / hft_bcs / _models.py View on Github external
design = models.StringField()
    next_available_exchange = models.IntegerField()
    players_per_group = models.IntegerField()
    round_length = models.IntegerField()
    batch_length = models.IntegerField(initial=0)
    trade_ended = models.BooleanField(initial=False)
    code = models.CharField(default=random_chars_8)
    has_trial = models.BooleanField(initial=True)
    is_trial = models.BooleanField(initial=False)
    trial_length = models.IntegerField(initial=0)
    log_file = models.StringField()
    first_round = models.IntegerField(initial=1)
    last_round = models.IntegerField(initial=0)
    total_rounds = models.IntegerField(initial=0)
    restore_from = models.CharField()
    restore = models.BooleanField(initial=False)
    lambda_i = models.FloatField()
    lambda_j = models.FloatField()

    def init_cache(self):
        pairs = {}
        session_lock = Constants.lock_key.format(self=self)
        pairs[session_lock] = Constants.unlock_value
        ready_groups = Constants.groups_ready_key.format(self=self)
        pairs[ready_groups] = {g.id: False for g in self.get_groups()}
        for k, v in pairs.items():
            cache.set(k, v, timeout=None)

    def convert_lambdas(self):
        self.lambda_i = round(1 / self.lambda_i, 1)
        self.lambda_j = round(1 / self.lambda_j, 1)
        self.save()
github oTree-org / oTree / matching_pennies / models.py View on Github external
for player in [mismatcher, matcher]:
            if (
                self.subsession.round_number == self.session.vars['paying_round']
                and player.is_winner
            ):
                player.payoff = Constants.stakes
            else:
                player.payoff = c(0)


class Player(BasePlayer):
    penny_side = models.StringField(
        choices=[['Heads', 'Heads'], ['Tails', 'Tails']], widget=widgets.RadioSelect
    )

    is_winner = models.BooleanField()

    def role(self):
        if self.id_in_group == 1:
            return 'Mismatcher'
        if self.id_in_group == 2:
            return 'Matcher'
github WZBSocialScienceCenter / otree_custom_models / example_decisions / models.py View on Github external
"""
        for _ in range(Constants.num_decisions_per_round):
            decision = self.decision_set.create()    # create a new Decision object as part of the player's decision set
            decision.value = random.randint(1, 10)
            decision.save()   # important: save to DB!


class Decision(Model):   # our custom model inherits from Django's base class "Model"
    REASONS = (
        ('dont_know', "Don't know"),
        ('example_reason', "Example reason"),
        ('another_example_reason', "Another example reason"),
    )

    value = models.IntegerField()    # will be randomly generated
    player_decision = models.BooleanField()
    reason = models.CharField(choices=REASONS)

    player = ForeignKey(Player)    # creates 1:m relation -> this decision was made by a certain player

    def __str__(self):
        return 'decision #%d for player %d (participant %d) - value %d'\
               % (self.pk, self.player.pk, self.player.participant.id_in_session, self.value)
github oTree-org / oTree / bertrand / models.py View on Github external
if p == winner:
                p.is_winner = True
                p.payoff = p.price
            else:
                p.is_winner = False
                p.payoff = c(0)


class Player(BasePlayer):
    price = models.CurrencyField(
        min=0,
        max=Constants.maximum_price,
        doc="""Price player offers to sell product for""",
    )

    is_winner = models.BooleanField()
github Leeps-Lab / high_frequency_trading / hft / models.py View on Github external
best_offer = models.IntegerField()
    e_best_bid = models.IntegerField()
    e_best_offer = models.IntegerField()
    slider_a_x = models.FloatField()
    slider_a_y = models.FloatField()
    slider_a_z = models.FloatField()
    signed_volume = models.FloatField()
    e_signed_volume = models.FloatField()

    # fields for this player's initial strategy decisions
    # these are set from the InitialDecisionSelection form
    initial_slider_a_x = models.FloatField()
    initial_slider_a_y = models.FloatField()
    initial_slider_a_z = models.FloatField()
    initial_role = models.CharField()
    initial_speed_on = models.BooleanField()

    def configure_for_trade_session(self, market, session_format: str):
        for field in ('exchange_host', 'exchange_port', 'market_id', 'subsession_id'):
            setattr(self, field, getattr(market, field))
        utility.configure_model_for_market('player', self, session_format, 
                                           self.session.config)
        self.save()
    
    def update_from_state_record(self, state_record):
        for field in state_record._meta.fields:
            if hasattr(self, field.name):
                attr = getattr(self, field.name)
                if attr is None:
                    setattr(self, field.name, getattr(state_record, field.name))
        self.save()