コード例 #1
0
class Group(BaseGroup):

    # プレイヤー1が送る
    sent_amount = models.CurrencyField(
        min=0,
        max=Constants.endowment,
        doc="""Amount sent by P1""",
    )

    # プレイヤー2が送る
    sent_back_amount = models.CurrencyField(
        doc="""Amount sent back by P1""",
        min=c(0),
    )

    # CPUが送る
    sent_cpu = models.IntegerField(initial=randint(0, 1000))

    # CPUが送り返す

    def b(self):
        return randint(0, self.sent_amount * Constants.multiplier)

    sent_back_cpu = models.CurrencyField()

    # 最終獲得値

    Xa = models.CurrencyField()

    Xb = models.CurrencyField()

    Ya = models.CurrencyField()

    Yb = models.CurrencyField()

    def set_payoffs(self):
        p1 = self.get_player_by_id(1)
        p2 = self.get_player_by_id(2)
        self.sent_back_cpu = c(self.b())
        # Y(a)
        p1.payoff = Constants.endowment - self.sent_amount + self.sent_back_cpu * Constants.multiplier
        self.Ya = Constants.endowment - self.sent_amount + self.sent_back_cpu * Constants.multiplier
        # X(a)
        p2.payoff = self.sent_amount * Constants.multiplier - self.sent_back_cpu
        self.Xa = self.sent_amount * Constants.multiplier - self.sent_back_cpu
        # Y(b)
        self.Yb = Constants.endowment - c(
            self.sent_cpu) + self.sent_back_amount * Constants.multiplier
        # X(b)
        self.Xb = c(
            self.sent_cpu) * Constants.multiplier - self.sent_back_amount

    def count1(self):
        return Constants.endowment - self.sent_amount
コード例 #2
0
ファイル: models.py プロジェクト: janvavra/wuotree
class Group(BaseGroup):
    bottle_price = models.CurrencyField(doc="""Price the bottles sell at""")

    def set_payoffs(self):
        players = self.get_players()
        self.bottle_price = (1 - (sum(p.initial_quantity
                                      for p in players) / 1000))
        if self.bottle_price < 0:
            self.bottle_price = 0
        for p in players:
            p.payoff = self.bottle_price * p.final_quantity

    pass
コード例 #3
0
ファイル: models.py プロジェクト: rizalap/docs
class Group(BaseGroup):
    kept = models.CurrencyField(
        doc="""Amount sender decided to keep for himself""",
        min=0, max=Constants.endowment,
        verbose_name='I will keep (from 0 to %i)' % Constants.endowment
    )

    Ikeep = models.CurrencyField (
        choices=Constants.kept_choices,
        doc="""receiver kept""",
        verbose_name='I understand that the amount of random number advise me to allocate this amount',
        widget=widgets.RadioSelectHorizontal()
    )

    # for strategy method
    response_10 = models.CharField(
        choices=[None, '10', '20', '30', '40'],
        widget=widgets.RadioSelectHorizontal(), verbose_name=question(10))
    response_20 = models.CharField(
        choices=[None, '10', '20', '30', '40'],
        widget=widgets.RadioSelectHorizontal(), verbose_name=question(20))
    response_30 = models.CharField(
        choices=[None, '10', '20', '30', '40'],
        widget=widgets.RadioSelectHorizontal(), verbose_name=question(30))
    response_40 = models.CharField(
        choices=[None, '10', '20', '30', '40'],
        widget=widgets.RadioSelectHorizontal(), verbose_name=question(40))



    def set_payoffs(self):
        sender = self.get_player_by_id(1)
        receiver = self.get_player_by_id(2)
        if self.round_number == 1:
            sender.payoff = self.kept * 2
            receiver.payoff = Constants.endowment - self.kept
        if self.round_number == 2:
            sender.payoff = self.kept
            receiver.payoff = (Constants.endowment - self.kept) * 2
コード例 #4
0
ファイル: models.py プロジェクト: janvavra/wuotree
class Group(BaseGroup):

    amount_offered = models.CurrencyField(min=0.01,
                                          max=Constants.endowment,
                                          doc="Amount offered")

    offer_accepted = models.BooleanField(doc="if offered amount is accepted")

    def set_payoffs(self):
        p1, p2 = self.get_players()
        p1.payoff = (Constants.endowment -
                     self.amount_offered) * self.offer_accepted
        p2.payoff = self.amount_offered * self.offer_accepted
コード例 #5
0
class Group(BaseGroup):
    total_consumption = models.CurrencyField(min=0, doc="""電気総消費量""")
    total_production = models.CurrencyField(min=0, doc="""電気総生産量""")
    is_blackout = models.BooleanField()

    def set_payoffs(self):
        self.total_consumption = sum([
            p.consumption for p in self.get_players() if p.role() == 'Consumer'
        ])
        self.total_production = sum([
            p.production for p in self.get_players() if p.role() == 'Producer'
        ])
        self.is_blackout = self.total_production < self.total_consumption  # 需要が供給を上回ったら

        # 停電が起きたら
        if self.is_blackout:
            for p in self.get_players():
                if p.role() == 'Consumer':
                    p.usage = Constants.penalty
                    p.participant.vars['payoff'] -= p.usage
                else:
                    p.usage = Constants.penalty * 3
                    p.participant.vars['payoff'] -= p.usage
        else:
            for p in self.get_players():
                if p.role() == 'Consumer':
                    regression_cost = Constants.regression_cost if self.subsession.round_number > 1 and p.in_previous_rounds(
                    )[-1].consumption > p.consumption else 0
                    consumer_minus = max(
                        0,
                        self.subsession.get_weather() -
                        p.consumption) * Constants.amplifier + regression_cost
                    cost_per_unit = Constants.cpp_cost_per_unit if Constants.cpp_cost_per_unit > 1 and self.subsession.get_weather_forecast(
                    ) * 3 >= Constants.cpp_criteria else 1
                    p.usage = p.consumption * cost_per_unit + consumer_minus
                    p.participant.vars['payoff'] -= p.usage
                else:
                    p.usage = p.production
                    p.participant.vars['payoff'] -= p.usage
コード例 #6
0
class Group(BaseGroup):
    item_value = models.CurrencyField(
        doc="""Common value of the item to be auctioned, random for treatment"""
    )

    highest_bid = models.CurrencyField()

    def set_winner(self):
        import random

        players = self.get_players()
        self.highest_bid = max([p.bid_amount for p in players])

        players_with_highest_bid = [
            p for p in players if p.bid_amount == self.highest_bid
        ]
        winner = random.choice(
            players_with_highest_bid
        )  # if tie, winner is chosen at random
        winner.is_winner = True
        for p in players:
            p.set_payoff()

    def generate_value_estimate(self):
        import random

        minimum = self.item_value - Constants.estimate_error_margin
        maximum = self.item_value + Constants.estimate_error_margin
        estimate = random.uniform(minimum, maximum)

        estimate = round(estimate, 1)

        if estimate < Constants.min_allowable_bid:
            estimate = Constants.min_allowable_bid
        if estimate > Constants.max_allowable_bid:
            estimate = Constants.max_allowable_bid

        return estimate
コード例 #7
0
ファイル: models.py プロジェクト: chapkovski/otree_AB
class Player(BasePlayer):
    contribution = models.CurrencyField(
        doc="""The amount contributed by the player""",
        min=0,
        max=100,
    )
    pgg_payoff = models.CurrencyField(
        doc='to store intermediary profit from pgg before punishment stage',
        initial=0)
    punishment_sent = models.CurrencyField(
        doc='amount of deduction tokens sent',
        min=0,
        max=Constants.pun_endowment)
    punishment_received = models.CurrencyField(
        doc='amount of pun received multiplied by factor', min=0)

    def set_punishment_received(self):
        all_puns_received = [
            getattr(i, 'pun_{}'.format(self.id_in_group))
            for i in self.get_others_in_group()
        ]
        self.punishment_received = sum(
            all_puns_received) * Constants.pun_factor

    def set_punishment_sent(self):
        all_puns_sent = [
            getattr(self, 'pun_{}'.format(i.id_in_group))
            for i in self.get_others_in_group()
        ]
        self.punishment_sent = sum(all_puns_sent)

    def set_pun(self):
        self.set_punishment_sent()
        self.set_punishment_received()

    def set_final_payoff(self):
        self.payoff = self.pgg_payoff + Constants.pun_endowment - (
            self.punishment_sent + self.punishment_received)
コード例 #8
0
class Group(BaseGroup):
    total_contribution = models.CurrencyField()
    individual_share = models.CurrencyField()
    round_num=models.IntegerField()

    # def __init__(self):
    #    self.group = None
    def round_number(self):
        return self.subsession.round_number

    def set_payoffs(self):
        self.total_contribution = sum([p.contribution for p in self.get_players()])
        self.individual_share = self.total_contribution * Constants.efficiency_factor / Constants.players_per_group
#        self.global_contribution = sum([p.total_contribution for p in self.in_all_rounds()])
        for p in self.get_players():
            p.payoff = Constants.endowment - p.contribution + self.individual_share
            # p1 = self.get_player_by_id(1)
            # p2 = self.get_player_by_id(2)
            # p3 = self.get_player_by_id(3)
            # p1_payoff = sum([p.payoff for p in self.in_previous_rounds() if p.p1 == 1])
            # p2_payoff = sum([p.payoff for p in self.in_previous_rounds() if p.p2 == 2])
            # p3_payoff = sum([p.payoff for p in self.in_previous_rounds() if p.p3 == 3])  # in_all_rounds
            print('p.payoff_is', p.payoff)
コード例 #9
0
class Player(BasePlayer):
    seller_proposed_price = models.CurrencyField(
        min=0, max=Constants.initial_endowment
    )

    seller_proposed_quality = models.StringField(
        choices=Constants.quality_level_names,
        widget=widgets.RadioSelectHorizontal
    )

    def role(self):
        if self.id_in_group == Constants.players_per_group:
            return 'buyer'
        return 'seller {}'.format(self.id_in_group)
コード例 #10
0
class Player(BasePlayer):
    gamble_number = models.IntegerField(
        choices=[1, 2, 3, 4, 5],
        doc="""This player's decision""",
        widget=widgets.RadioSelect
    )

    gain = models.CurrencyField(initial=c(0))
    event = models.StringField()

    def set_gain(self, r):
        self.event = r
        self.gain = Constants.payoff_matrix[self.event][self.gamble_number]
        self.payoff += self.gain
コード例 #11
0
class Group(BaseGroup):
    kept = models.CurrencyField(
        doc="""Amount allocator decided to keep for himself""",
        min=0,
        max=Constants.endowment,
        verbose_name="I will keep (from 0 to {})".format(Constants.endowment))
    predicted = models.CurrencyField(
        doc="""Amount receiver predicted they would receive from allocator""",
        min=0,
        max=Constants.endowment,
        verbose_name="I will receive (from 0 to {})".format(
            Constants.endowment))

    rating = models.PositiveIntegerField(choices=[
        [1, 'Fair'],
        [0, 'Unfair'],
    ])

    def set_payoffs(self):
        p1 = self.get_player_by_id(1)
        p2 = self.get_player_by_id(2)
        p1.payoff = self.kept
        p2.payoff = Constants.endowment - self.kept
コード例 #12
0
class Group(BaseGroup):

    unit_price = models.CurrencyField()

    total_units = models.IntegerField(
        doc="""Total units produced by all players"""
    )

    def set_payoffs(self):
        players = self.get_players()
        self.total_units = sum([p.units for p in players])
        self.unit_price = Constants.total_capacity - self.total_units
        for p in players:
            p.payoff = self.unit_price * p.units
コード例 #13
0
ファイル: models.py プロジェクト: chapkovski/focus_control
class Player(BasePlayer):
    def sent_back_amount_choices(self):
        return currency_range(
            c(0),
            self.sent_amount * Constants.multiplication_factor,
            c(1)
        )
    curpage=models.CharField()    
    sent_amount = models.CurrencyField(
        choices=currency_range(0, Constants.endowment, c(1)),
        doc="""Amount sent by P1""",
    )

    sent_back_amount = models.CurrencyField(
        doc="""Amount sent back by P2""",
    )

    def set_payoffs(self):
        tripled_amount = self.sent_amount * Constants.multiplication_factor
        self.sent_back_amount=random.choice(self.sent_back_amount_choices())
        # p1 = self
        # p2 = self.get_player_by_id(2)
        self.payoff = Constants.endowment - self.sent_amount + self.sent_back_amount
コード例 #14
0
class Player(BasePlayer):
    bot_decision = models.StringField(choices=['A', 'B'],
                                      doc="""This player's bot decision""",
                                      widget=widgets.RadioSelect)

    send_message = models.StringField(
        label="Que mensaje quiere mandar a la Persona 2?",
        choices=[['A', 'Yo elijo A'], ['B', 'Yo elijo B']],
        widget=widgets.RadioSelect)

    send_answer = models.StringField(
        label="Que mensaje quiere mandar a la Persona 1?",
        choices=[['A', 'Yo elijo A'], ['B', 'Yo elijo B']],
        widget=widgets.RadioSelect)

    decision = models.StringField(choices=['A', 'B'],
                                  doc="""This player's decision""",
                                  widget=widgets.RadioSelect)

    question_1 = models.IntegerField(
        label=
        "Suponga que usted es la Primera Persona, y que selecciona el símbolo de la derecha, ¿cuál sería su pago "
        "si la Segunda Persona también elige el símbolo de la derecha?",
        min=10,
        max=70)

    question_2 = models.IntegerField(
        label=
        "Suponga que usted es la Segunda Persona, y selecciona el símbolo de la derecha, ¿cuál sería su pago si "
        "la Primera Persona elige el símbolo de la izquierda?",
        min=10,
        max=70)

    trial_payoff = models.CurrencyField(initial=0)

    def rand_send_message(self):
        self.send_message = random.choice(['A', 'B'])

    def rand_send_answer(self):
        self.send_answer = random.choice(['A', 'B'])

    def other_player(self):
        return self.get_others_in_group()[0]

    def bot_result(self):
        self.bot_decision = random.choice(['A', 'B'])

    def set_payoff(self):
        self.trial_payoff = Constants.payoff_matrix[self.decision][
            self.bot_decision]
コード例 #15
0
class Group(BaseGroup):
    treatment = models.StringField()
    sent_amount = models.CurrencyField(
        min=0, max=Constants.endowment,
        doc="""Amount sent by P1""",
    )

    sent_back_amount = models.CurrencyField(
        doc="""Amount sent back by P2""",
        min=c(0),
    )

    def sent_back_amount_max(self):
        return self.sent_amount * self.subsession.multiplier

    def set_payoffs(self):
        p1 = self.get_player_by_id(1)
        p2 = self.get_player_by_id(2)
        p1.payoff = Constants.endowment - self.sent_amount + self.sent_back_amount
        p2.payoff = self.sent_amount * self.subsession.multiplier - self.sent_back_amount + 10

        p1.totalProfit = sum(p.payoff for p in p1.in_all_rounds())
        p2.totalProfit = sum(p.payoff for p in p2.in_all_rounds())
コード例 #16
0
class Group(BaseGroup):
    unit_price = models.CurrencyField()
    total_units = models.IntegerField(
        doc="""Total units produced by all players""")

    def set_payoffs(self):
        players = self.get_players()
        self.total_units = sum([p.units for p in players])
        self.unit_price = max(
            Constants.alpha - self.total_units,
            0)  # Max operator non binding with paper parameters
        for p in players:
            p.calculate_costs()
            p.payoff = self.unit_price * p.units - p.costs
コード例 #17
0
class Player(BasePlayer):
    item_value_estimate = models.CurrencyField(
        doc="""Estimate of the common value, may be different for each player"""
    )

    bid_amount = models.CurrencyField(
        min=Constants.min_allowable_bid,
        max=Constants.max_allowable_bid,
        doc="""Amount bidded by the player""",
        label="Bid amount"
    )

    is_winner = models.BooleanField(
        initial=False, doc="""Indicates whether the player is the winner"""
    )

    def set_payoff(self):
        if self.is_winner:
            self.payoff = self.group.item_value - self.bid_amount
            if self.payoff < 0:
                self.payoff = 0
        else:
            self.payoff = 0
コード例 #18
0
class Group(BaseGroup):
    kept = models.CurrencyField(
        doc="""Amount dictator decided to keep for himself""",
        min=c(0), max=c(Constants.endowment),
    )

    def set_payoffs(self):
        p1 = self.get_player_by_role('dictator')
        p2 = self.get_player_by_role('receiver')

        p1.payoff = 0
        p2.payoff = 0

        if
コード例 #19
0
ファイル: models.py プロジェクト: jkugel3/oTree-JKUGEL
class Group(BaseGroup):
    generic_charity_donation = models.CurrencyField(
        doc='info about money sent to gen.charity')
    specific_charity_donation = models.CurrencyField(
        doc='info about money sent to spec.charity chosen by a player')
    org_choice = models.StringField(choices=Constants.orgs, blank=True)

    def set_payoffs(self):
        double_giver = self.get_player_by_role('double_giver')
        generic_charity = self.get_player_by_role('generic_charity')
        specific_charity = self.get_player_by_role('specific_charity')
        for p in self.get_players():
            p.total_correct = sum([i.is_correct for i in p.in_all_rounds()])
            p.money_sent = p.total_correct * Constants.right_answer
        self.generic_charity_donation = generic_charity.money_sent
        self.specific_charity_donation = specific_charity.money_sent
        if self.session.config['treatment'] == 'DG':
            for p in self.get_players():
                p.payoff -= p.money_sent

        dg_share = double_giver.money_sent / 2
        generic_charity.payoff += dg_share
        specific_charity.payoff += dg_share
コード例 #20
0
class Player(BasePlayer):
    sender_allocation = models.CurrencyField(min=0, max=Constants.endowment)
    sender_expectation = models.IntegerField(min=0, max=900)

    def role(self):
        if self.id_in_group == Constants.players_per_group:
            return 'distributor'
        return 'sender {}'.format(self.id_in_group)

    survey1 = models.StringField(choices=['Male', 'Female', 'Non-Binary', 'I prefer not to say'],
                                 widget=widgets.RadioSelect)
    survey2 = models.LongStringField(blank=True)

    survey3 = models.LongStringField(blank=True)
コード例 #21
0
ファイル: models.py プロジェクト: leexpucp/Prueba-GECE
class Player(BasePlayer):
    # seller
    seller_proposed_price = models.CurrencyField(
        min=0, max=Constants.initial_endowment,
        verbose_name='Please indicate a price (from 0 to %i) you want to sell'
                     % Constants.initial_endowment)

    seller_proposed_quality = models.CurrencyField(
        choices=[
            (30, 'High'),
            (20, 'Medium'),
            (10, 'Low')],
        verbose_name='Please select a quality grade you want to produce',
        widget=widgets.RadioSelectHorizontal())

    def seller_id(self):
        # player 1 is the buyer, so seller 1 is actually player 2
        return (self.id_in_group - 1)

    def role(self):
        if self.id_in_group == 1:
            return 'buyer'
        return 'seller {}'.format(self.seller_id())
コード例 #22
0
class Player(BasePlayer):
    fixed_points = models.CurrencyField()
    fluid_points = models.CurrencyField()
    alloc_points = models.CurrencyField()
    total_points = models.CurrencyField()

    def vars_for_template(self):
        # final_pay = (self.participant.vars['part_fixed_payoff'] +
        #              self.participant.vars['part_fluid_payoff'] +
        #              self.participant.vars['part_alloc_payoff'])
        return {
            'circles_name': self.participant.vars['circles_name'],
            'triangles_name': self.participant.vars['triangles_name'],
            'circles_label': self.participant.vars['circles_label'],
            'triangles_label': self.participant.vars['triangles_label'],
            'names': len(Constants.names),
            'part_fixed_round': self.participant.vars['part_fixed_round'],
            'part_fixed_payoff': self.participant.vars['part_fixed_payoff'],
            'part_fluid_round': self.participant.vars['part_fluid_round'],
            'part_fluid_payoff': self.participant.vars['part_fluid_payoff'],
            'part_alloc_payoff': self.participant.vars['part_alloc_payoff'],
            # 'final_payment': final_pay
        }
コード例 #23
0
ファイル: models.py プロジェクト: akrgt/gotree
class Group(BaseGroup):
    kept = models.CurrencyField(
        doc="""自身の利益を決めてください.""",
        choices=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
        verbose_name='私は( 0 から %i )ポイントを自分の利益とします.' % Constants.endowment,

    )

#I will keep (from 0 to %i)
    def set_payoffs(self):
        p1 = self.get_player_by_id(1)
        p2 = self.get_player_by_id(2)
        p1.payoff = self.kept
        p2.payoff = Constants.endowment - self.kept
コード例 #24
0
ファイル: models.py プロジェクト: rizalap/docs
class Group(BaseGroup):
    kept = models.CurrencyField(
        doc="""Amount sender decided to keep for himself""",
        min=0,
        max=Constants.endowment,
        verbose_name='I will keep (from 0 to %i)' % Constants.endowment)

    Ikeep = models.CurrencyField(
        choices=Constants.kept_choices,
        doc="""receiver kept""",
        verbose_name=
        'I understand that the amount of random number advise me to allocate this amount',
        widget=widgets.RadioSelectHorizontal())

    def set_payoffs(self):
        sender = self.get_player_by_id(1)
        receiver = self.get_player_by_id(2)
        if self.round_number == 1:
            sender.payoff = self.kept * 3
            receiver.payoff = Constants.endowment - self.kept
        if self.round_number == 2:
            sender.payoff = self.kept
            receiver.payoff = (Constants.endowment - self.kept) * 3
コード例 #25
0
class Group(BaseGroup):
    total_quantity = models.IntegerField()

    price = models.CurrencyField(
        doc=
        """Unit price: P = T - Q1 - Q2, where T is total capacity and Q_i are the units produced by the players"""
    )

    def set_payoffs(self):
        self.total_quantity = sum(player.quantity
                                  for player in self.get_players())
        self.price = c(Constants.total_capacity - self.total_quantity)
        for player in self.get_players():
            player.payoff = self.price * player.quantity
コード例 #26
0
ファイル: models.py プロジェクト: sherafghanasad/oTree
class Group(BaseGroup):
    proposed_wage = models.CurrencyField(choices=currency_range(
        Constants.lowest_wage, Constants.highest_wage, c(5)), )
    random_wage = models.IntegerField()

    guessed_wage = models.CurrencyField(choices=currency_range(
        Constants.lowest_wage, Constants.highest_wage, c(5)), )
    effort = models.FloatField(choices=Constants.efforts,
                               widget=widgets.RadioSelect)

    def get_cost(self):
        return Constants.costs[Constants.efforts.index(self.effort)]

    expected_effort = models.FloatField(choices=Constants.efforts,
                                        widget=widgets.RadioSelect)

    effort_cost = models.IntegerField()

    multiplier = models.FloatField(choices=[
        0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.4,
        1.5, 1.6, 1.7, 1.8, 1.9, 2
    ],
                                   widget=widgets.RadioSelect)
    guessed_multiplier = models.FloatField(choices=[
        0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.4,
        1.5, 1.6, 1.7, 1.8, 1.9, 2
    ],
                                           widget=widgets.RadioSelect)

    def set_payoffs(self):
        print('in set_payoffs')
        employer = self.get_player_by_role('Employer')
        worker = self.get_player_by_role('Worker')

        if self.subsession.round_number == self.session.vars['paying_round']:
            employer.payoff = c((120 - self.random_wage) * self.effort)
            worker.payoff = c(self.random_wage - 20 - self.get_cost())
コード例 #27
0
class Player(BasePlayer):
    contribution = models.CurrencyField(
        min=0,
        max=Constants.endowment,
        doc="""The amount contributed by the player""",
    )

    name = models.StringField()
    number = models.IntegerField()
    # _class = models.IntegerField(choices=[
    #     [0, '计科1701'],
    #     [1, '软件1701'],
    # ])
    id_in_class = models.IntegerField()
    cumulative_payoff = models.CurrencyField()
    rank = models.IntegerField()
    is_random = models.BooleanField(initial=False)

    def set_cum_payoff(self):
        self.cumulative_payoff = sum([p.payoff for p in self.in_all_rounds()])

    def role(self):
        if self.id_in_group % 4 == 0:
            return 'A'
        if self.id_in_group % 4 == 1:
            return 'B'
        if self.id_in_group % 4 == 2:
            return 'C'
        if self.id_in_group % 4 == 3:
            return 'D'

    def set_rank(self):
        self.rank = self.session.vars['cumulative_payoff_rank'][
            self.id_in_group] + 1

    def chat_nickname(self):
        return '公司 {} ID {} '.format(self.role(), self.id_in_group)
コード例 #28
0
class Group(BaseGroup):

    sum_high_tech_investment = models.CurrencyField()

    individual_contribution = models.CurrencyField()

    def set_payoffs(self):

        high_tech_contribution = [
            p.high_tech_investment for p in self.get_players()
        ]

        self.sum_high_tech_investment = sum(high_tech_contribution)

        for p in self.get_players():

            p.low_tech_investment = sum(
                [+p.endowment, -p.high_tech_investment])
            if self.sum_high_tech_investment < 300:
                p.payoff = p.high_tech_investment * 0.95 + (
                    p.low_tech_investment) * 1.03

            elif self.sum_high_tech_investment < 400:
                p.payoff = p.high_tech_investment * 1.03 + (
                    p.low_tech_investment) * 1.03

            elif self.sum_high_tech_investment < 500:
                p.payoff = p.high_tech_investment * 1.05 + (
                    p.low_tech_investment) * 1.03

            elif self.sum_high_tech_investment < 600:
                p.payoff = p.high_tech_investment * 1.07 + (
                    p.low_tech_investment) * 1.03

            else:
                p.payoff = p.high_tech_investment * 1.09 + (
                    p.low_tech_investment) * 1.03
コード例 #29
0
class Group(BaseGroup):

    group_kept = models.CurrencyField(
        doc="""Amount actual dictator decided to keep for himself""",
        min=0,
        max=Constants.endowment)

    def set_random_dictator(self):
        """
        Sets randomly who will be selected as the dictator

        Input: None
        Output: None
        """

        for p in self.get_players():
            if p.id_in_group == Constants.id_random_dictator:
                p.dictator = True

    def set_group_data(self):
        """
        Sets group variables values

        Input: None
        Output: None
        """
        for p in self.get_players():
            if p.dictator:
                self.group_kept = p.kept

    def set_payoffs(self):
        """
        Sets the payoffs for each member of a group

        Input: None
        Output: None
        """
        amount_kept_dictator = 0  # storing dictator's decision

        # setting the payoffs for dictator in group
        for p in self.get_players():
            if p.dictator:
                amount_kept_dictator = p.kept
                p.payoff = amount_kept_dictator

        # looping again for setting non dictator's payoffs (cant assign before knowing who is dictator)
        for p in self.get_players():
            if not p.dictator:
                p.payoff = amount_kept_dictator
コード例 #30
0
ファイル: models.py プロジェクト: leexpucp/Prueba-GECE
class Group(BaseGroup):
    # use_strategy_method = models.BooleanField(
    #     doc="""Whether this group uses strategy method"""
    # )
    #
    amount_offered = models.CurrencyField(choices=Constants.offer_choices)
    #
    offer_accepted = models.BooleanField(
        doc="if offered amount is accepted (direct response method)")

    #
    # # for strategy method
    # response_0 = models.BooleanField(
    #     widget=widgets.RadioSelectHorizontal(), verbose_name=question(0))
    # response_10 = models.BooleanField(
    #     widget=widgets.RadioSelectHorizontal(), verbose_name=question(10))
    # response_20 = models.BooleanField(
    #     widget=widgets.RadioSelectHorizontal(), verbose_name=question(20))
    # response_30 = models.BooleanField(
    #     widget=widgets.RadioSelectHorizontal(), verbose_name=question(30))
    # response_40 = models.BooleanField(
    #     widget=widgets.RadioSelectHorizontal(), verbose_name=question(40))
    # response_50 = models.BooleanField(
    #     widget=widgets.RadioSelectHorizontal(), verbose_name=question(50))
    # response_60 = models.BooleanField(
    #     widget=widgets.RadioSelectHorizontal(), verbose_name=question(60))
    # response_70 = models.BooleanField(
    #     widget=widgets.RadioSelectHorizontal(), verbose_name=question(70))
    # response_80 = models.BooleanField(
    #     widget=widgets.RadioSelectHorizontal(), verbose_name=question(80))
    # response_90 = models.BooleanField(
    #     widget=widgets.RadioSelectHorizontal(), verbose_name=question(90))
    # response_100 = models.BooleanField(
    #     widget=widgets.RadioSelectHorizontal(), verbose_name=question(100))
    #

    def set_payoffs(self):
        p1, p2 = self.get_players()

        # if self.use_strategy_method:
        #     self.offer_accepted = getattr(self, 'response_{}'.format(
        #         int(self.amount_offered)))

        if self.offer_accepted:
            p1.payoff = Constants.endowment - self.amount_offered
            p2.payoff = self.amount_offered
        else:
            p1.payoff = Constants.payoff_if_rejected
            p2.payoff = Constants.payoff_if_rejected