Ejemplo n.º 1
0
class Player(otree.models.BasePlayer):

    # <built-in>
    group = models.ForeignKey(Group, null=True)
    subsession = models.ForeignKey(Subsession)
    # </built-in>

    name = models.CharField(max_length=255, verbose_name="Your name")

    age = models.CharField(max_length=255, verbose_name="Your age")

    email = models.EmailField(verbose_name="Your email address")

    gender = models.CharField(verbose_name="Are you",
                              max_length=255,
                              widget=widgets.RadioSelect(),
                              choices=["Male", "Female"])

    major = models.CharField(max_length=1000,
                             verbose_name="What is your major?")

    location_of_your_partners_influence_your_decisions = models.TextField(
        verbose_name=("Did the location of your partners influence your "
                      "decisions of how much to contribute to the individual "
                      "account versus the team account? If yes, how?"))

    working_in_a_location_of_their_choice_more_less_to_the_team = models.BooleanField(
        widget=widgets.RadioSelect(),
        verbose_name=("When you were partnered with two people working in a "
                      "location of their choice, did you want to give more "
                      "to the team or less than when you were partnered "
                      "with two people working in a lab?"))

    partners_in_location_their_choice_worked_harder_than_the_lab = models.BooleanField(
        widget=widgets.RadioSelect(),
        verbose_name=("Do you believe your partners participation in a "
                      "location of their choice gave more to the group than "
                      "your partners working the lab?"))

    I_work_best_in = models.CharField(
        verbose_name="Are you",
        max_length=255,
        widget=widgets.RadioSelect(),
        choices=["Structured environments", "flexible environments"])

    risks_in_everyday_life = models.PositiveIntegerField(
        min=1,
        max=10,
        widget=widgets.SliderInput(),
        verbose_name=("In general, do you take more or less risks in everyday "
                      "life? ('1' = take less risk and '10' take more risk.)"))

    risks_in_financial_decision = models.PositiveIntegerField(
        min=1,
        max=10,
        widget=widgets.SliderInput(),
        default=5,
        verbose_name=
        (" In general, do you take more or less risks in financial decisions? "
         "life? ('1' = take less risk and '10' take more risk.)"))
Ejemplo n.º 2
0
class Player(otree.models.BasePlayer):

    # <built-in>
    group = models.ForeignKey(Group, null=True)
    subsession = models.ForeignKey(Subsession)
    # </built-in>

    training_question_1 = models.CharField(
        choices=Constants.training_1_choices,
        widget=widgets.RadioSelect(),
        #timeout_default=Constants.training_1_choices[1]
    )

    def is_training_question_1_correct(self):
        return self.training_question_1 == Constants.training_1_correct

    decision = models.CharField(
        choices=['Cooperate', 'Defect'],
        doc="""This player's decision""",
        widget=widgets.RadioSelect()
    )

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

    def set_payoff(self):
        points_matrix = {'Cooperate': {'Cooperate': Constants.cooperate_amount,
                                       'Defect': Constants.cooperate_defect_amount},
                         'Defect':   {'Cooperate': Constants.defect_cooperate_amount,
                                      'Defect': Constants.defect_amount}}

        self.payoff = (points_matrix[self.decision]
                                           [self.other_player().decision])
Ejemplo n.º 3
0
class Player(BasePlayer):
    ethnic_in = models.CharField(
        initial=None,
        choices=[Constants.ethnicity_dai, Constants.ethnicity_han],
        widget=widgets.RadioSelect())
    # Input variable to ask the participants' religion
    religion_in = models.CharField(initial=None,
                                   choices=[
                                       Constants.religion_buddhist,
                                       Constants.religion_christian,
                                       Constants.religion_none
                                   ],
                                   widget=widgets.RadioSelect())

    # Function defined to get the ethnicity of the other participant in the group in the trust game
    def other_eth(self):
        return self.get_others_in_group()[0].participant.vars['ethnic']

    # Function defined to get the religion of the other participant in the group in the trust game
    def other_relig(self):
        return self.get_others_in_group()[0].participant.vars['religion']

    def get_ethnicity(self):
        return self.in_all_rounds()[0].participant.vars['ethnic']

    def get_religion(self):
        return self.in_all_rounds()[0].participant.vars['religion']

    payoff_block1 = models.CurrencyField()
Ejemplo n.º 4
0
class Player(otree.models.BasePlayer):

    # <built-in>
    group = models.ForeignKey(Group, null=True)
    subsession = models.ForeignKey(Subsession)
    # </built-in>

    demo_field1 = models.CharField(
        doc="""field With radiobutton input.""",
        widget=widgets.RadioSelect(),
    )

    def set_payoff(self):
        self.payoff = c(0)


    training_question_1 = models.CharField(widget=widgets.RadioSelect())
    training_question_2 = models.CharField(widget=widgets.RadioSelect())
    training_question_3 = models.CharField(widget=widgets.RadioSelect())

    def training_question_1_choices(self):
        return ['Head', 'Tail']

    def training_question_2_choices(self):
        return ['Head', 'Tail']

    def training_question_3_choices(self):
        return ['Head', 'Tail']
Ejemplo n.º 5
0
class Player(otree.models.BasePlayer):

    # <built-in>
    group = models.ForeignKey(Group, null=True)
    subsession = models.ForeignKey(Subsession)
    # </built-in>

    training_question_1 = models.CharField(
        max_length=100,
        choices=[
            'Player 1 gets 0 points, Player 2 gets 0 points',
            'Player 1 gets 100 points, Player 2 gets 100 points',
            'Player 1 gets 100 points, Player 2 gets 0 points',
            'Player 1 gets 0 points, Player 2 gets 100 points'
        ],
        widget=widgets.RadioSelect())

    def is_training_question_1_correct(self):
        return self.training_question_1 == Constants.training_1_correct

    penny_side = models.CharField(choices=['Heads', 'Tails'],
                                  doc="""Heads or tails""",
                                  widget=widgets.RadioSelect())

    is_winner = models.NullBooleanField(doc="""Whether player won the round""")

    def other_player(self):
        """Returns the opponent of the current player"""
        return self.get_others_in_group()[0]

    def role(self):
        if self.id_in_group == 1:
            return 'Player 1'
        if self.id_in_group == 2:
            return 'Player 2'
Ejemplo n.º 6
0
class Player(otree.models.BasePlayer):
    # <built-in>
    subsession = models.ForeignKey(Subsession)
    group = models.ForeignKey(Group, null = True)
    # </built-in>

    # initial shares and payoff
    shares = models.PositiveIntegerField(initial=5)

    cash = models.CurrencyField()

    # default allocated shares for both players; provides a range for buyers; sellers' range is limited by the number of shares they have


    # order fields
    bp = models.CurrencyField(initial=0.00, doc="""maximum buying price per share""")
    bn = models.PositiveIntegerField(initial=0,
                                     choices=range(0, Constants.num_shares+1, 1),
                                     doc="""number of shares willing to buy""")
    sp = models.CurrencyField(initial=0.00, doc="""minimum selling price per share""")
    sn = models.PositiveIntegerField(initial=0, doc="""number of shares willing to sell.""")

    order_type = models.CharField(choices=['Sell', 'Buy', 'None'],
                                  doc="""player: buy or sell?""",
                                  widget=widgets.RadioSelectHorizontal)

    def sn_choices(self):
        return range(0, self.shares+1, 1)

    def bp_choices(self):
        return currency_range(0, self.cash, 0.5)

    def sp_choices(self):
        return currency_range(0, self.cash, 0.5)

    def other_player(self):
        """Returns other player in group. Only valid for 2-player groups."""
        return self.get_others_in_group()[0]

    QUESTION_1_CHOICES = ['P=3, N=2','P=2, N=3','P=2.5, N=3','P=2.5, N=2','No transaction will take place',]
    QUESTION_2_CHOICES = ['$8, $12', '$12, $8', '$8, $8', '$12, $12', '$10, $10']

    understanding_question_1 = models.CharField(choices=QUESTION_1_CHOICES, widget=widgets.RadioSelect())
    understanding_question_2 = models.CharField(choices=QUESTION_2_CHOICES, widget=widgets.RadioSelect())

    # check correct answers
    def is_understanding_question_1_correct(self):
        return self.understanding_question_1 == Constants.understanding_1_correct

    def is_understanding_question_2_correct(self):
        return self.understanding_question_2 == Constants.understanding_2_correct


    def set_payoff(self):
        self.payoff = 0
        if self.subsession.round_number == Constants.num_rounds:
            self.payoff = self.cash
        else:
            self.payoff = 0
Ejemplo n.º 7
0
class Player(BasePlayer):
    time_Demographics = models.TextField(widget=widgets.HiddenInput(
        attrs={'id': 'arrive_time'}))
    time_CognitiveReflectionTest = models.TextField(widget=widgets.HiddenInput(
        attrs={'id': 'arrive_time'}))

    def set_payoff(self):
        """Calculate payoff, which is zero for the survey"""
        self.payoff = 0

    q_country = models.CharField(verbose_name='What country are you from?')

    q_age = models.PositiveIntegerField(verbose_name='What is your age?',
                                        choices=range(13, 125),
                                        initial=None)

    q_station = models.PositiveIntegerField(
        verbose_name=
        'What is your computer station number? (see white sticker on computer or ask experimenter)',
        choices=range(1, 17),
        initial=None)

    q_gender = models.CharField(initial=None,
                                choices=['Male', 'Female', 'Other'],
                                verbose_name='What is your gender?',
                                widget=widgets.RadioSelect())
    q_income = models.PositiveIntegerField(
        verbose_name='What is the approximate annual income of your family?',
        choices=[
            [1, 'less than $15,000'],
            [2, '$15,000 - $29,999'],
            [3, '$30,000 - $59,999'],
            [4, '$60,000 - $99,999'],
            [5, '$100,000 - $199,999'],
            [6, '$200,000 or more'],
            [7, 'I rather not answer this question'],
        ])

    q_zipcode = models.PositiveIntegerField(
        verbose_name='What is the zip code where you grew up?')

    q_opinion = models.CharField(
        initial=None,
        verbose_name=
        'Were the instructions provided in this experiment clear and useful?',
        choices=['Yes', 'No'],
        widget=widgets.RadioSelect())

    crt_bat = models.PositiveIntegerField()

    crt_widget = models.PositiveIntegerField()

    crt_lake = models.PositiveIntegerField()
Ejemplo n.º 8
0
class Player(otree.models.BasePlayer):

    # <built-in>
    group = models.ForeignKey(Group, null=True)
    subsession = models.ForeignKey(Subsession)
    # </built-in>

    training_question_1 = models.CharField(max_length=100,
                                           null=True,
                                           verbose_name='',
                                           widget=widgets.RadioSelect())

    def training_question_1_choices(self):
        return [
            'Alice gets 300 points, Bob gets 0 points',
            'Alice gets 200 points, Bob gets 200 points',
            'Alice gets 0 points, Bob gets 300 points',
            'Alice gets 100 points, Bob gets 100 points'
        ]

    def is_training_question_1_correct(self):
        return self.training_question_1 == Constants.training_1_correct

    points_earned = models.PositiveIntegerField(default=0,
                                                doc="""Points earned""")

    decision = models.CharField(doc="""This player's decision""",
                                widget=widgets.RadioSelect())

    def decision_choices(self):
        return ['Cooperate', 'Defect']

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

    def set_points(self):
        points_matrix = {
            'Cooperate': {
                'Cooperate': Constants.cooperate_amount,
                'Defect': Constants.cooperate_defect_amount
            },
            'Defect': {
                'Cooperate': Constants.defect_cooperate_amount,
                'Defect': Constants.defect_amount
            }
        }

        self.points_earned = (
            points_matrix[self.decision][self.other_player().decision])

    def set_payoff(self):
        self.payoff = 0
Ejemplo n.º 9
0
class Player(BasePlayer):
    def set_payoff(self):
        """Calculate payoff, which is zero for the survey"""
        self.payoff = 0

    q_age = models.PositiveIntegerField(verbose_name='What is your age?',
                                        choices=range(13, 125),
                                        initial=None)

    q_gender = models.CharField(initial=None,
                                choices=['Male', 'Female'],
                                verbose_name='What is your gender?',
                                widget=widgets.RadioSelect())

    q_occupation = models.CharField(
        widget=widgets.RadioSelect(),
        choices=["wage-employed", "self-employed", "unemployed"])

    q_income = models.CharField(widget=widgets.RadioSelect(),
                                choices=[
                                    "Less than Ksh.10,000",
                                    "Ksh.10,000 - Ksh. 30,000",
                                    "Ksh. 30,000 - Ksh. 60,000",
                                    "Ksh. 60,000 - Ksh.100,000",
                                    "More than Ksh.100,000",
                                    "Don’t know",
                                ])

    q_education_father = models.CharField(
        widget=widgets.RadioSelect(),
        choices=[
            "Completed High School",
            "Completed Vocational College",
            "Completed University (Bachelor)",
            "Completed University (Advanced)",
            "Other",
        ])

    q_education_mother = models.CharField(
        widget=widgets.RadioSelect(),
        choices=[
            "Completed High School",
            "Completed Vocational College",
            "Completed University (Bachelor)",
            "Completed University (Advanced)",
            "Other",
        ])

    crt_bat = models.PositiveIntegerField()
    crt_widget = models.PositiveIntegerField()
    crt_lake = models.PositiveIntegerField()
Ejemplo n.º 10
0
class Player(BasePlayer):

    comprehension_1 = models.CharField(
        max_length=10, choices=sorted(Constants.comprehension_1.items()),
        widget=widgets.RadioSelect())

    comprehension_2 = models.CharField(
        max_length=10, choices=sorted(Constants.comprehension_2.items()),
        widget=widgets.RadioSelect())

    comprehension_3 = models.CharField(
        max_length=10, choices=sorted(Constants.comprehension_3.items()),
        widget=widgets.RadioSelect())

    last_question = models.BooleanField(widget=widgets.RadioSelect())
Ejemplo n.º 11
0
class Player(otree.models.BasePlayer):

    # <built-in>
    group = models.ForeignKey(Group, null=True)
    subsession = models.ForeignKey(Subsession)

    # </built-in>

    def set_payoff(self):
        """Calculate payoff, which is zero for the survey"""
        self.payoff = 0

    def q_gender_choices(self):
        return ['Male', 'Female']

    def q_age_choices(self):
        return range(13, 125)

    q_country = CountryField(
        verbose_name='What is your country of citizenship?')
    q_age = models.PositiveIntegerField(verbose_name='What is your age?',
                                        default=None)
    q_gender = models.CharField(default=None,
                                verbose_name='What is your gender?',
                                widget=widgets.RadioSelect())

    crt_bat_float = models.DecimalField(max_digits=6, decimal_places=2)
    crt_bat = models.PositiveIntegerField()
    crt_widget = models.PositiveIntegerField()
    crt_lake = models.PositiveIntegerField()
Ejemplo n.º 12
0
class Player(otree.models.BasePlayer):

    # <built-in>
    group = models.ForeignKey(Group, null=True)
    subsession = models.ForeignKey(Subsession)
    # </built-in>

    def other_player(self):
        """Returns other player in group"""
        return self.other_players_in_group()[0]

    decision = models.CharField(
        default=None,
        doc='either A or B',
        widget=widgets.RadioSelect()
    )

    def decision_choices(self):
        return ['A', 'B']

    def role(self):
        if self.id_in_group == 1:
            return 'column'
        if self.id_in_group == 2:
            return 'row'
Ejemplo n.º 13
0
class Player(otree.models.BasePlayer):

    # <built-in>
    group = models.ForeignKey(Group, null=True)
    subsession = models.ForeignKey(Subsession)
    # </built-in>

    decision = models.CharField(
        default=None,
        doc="""Either football or the opera""",
        widget=widgets.RadioSelect()
    )

    def decision_choices(self):
        return ['Football', 'Opera']

    def other_player(self):
        """Returns other player in group"""
        return self.other_players_in_group()[0]

    def role(self):
        if self.id_in_group == 1:
            return 'husband'
        if self.id_in_group == 2:
            return 'wife'
Ejemplo n.º 14
0
class Player(BasePlayer):

    training_question_1_husband = models.CurrencyField(
        min=0, max=Constants.training_1_maximum_offered_points)

    training_question_1_wife = models.CurrencyField(
        min=0, max=Constants.training_1_maximum_offered_points)

    decision = models.CharField(choices=['Football', 'Opera'],
                                doc="""Either football or the opera""",
                                widget=widgets.RadioSelect())

    def is_training_question_1_husband_correct(self):
        return (self.training_question_1_husband ==
                Constants.training_1_husband_correct)

    def is_training_question_1_wife_correct(self):
        return (
            self.training_question_1_wife == Constants.training_1_wife_correct)

    def other_player(self):
        """Returns other player in group"""
        return self.get_others_in_group()[0]

    def role(self):
        if self.id_in_group == 1:
            return 'husband'
        if self.id_in_group == 2:
            return 'wife'
Ejemplo n.º 15
0
class Player(BasePlayer):
    # seller
    price = models.CurrencyField(
        min=0,
        max=Constants.INITIAL,
        verbose_name='Please indicate a price (from 0 to %i) you want to sell'
        % Constants.INITIAL)

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

    # buyer
    choice = models.PositiveIntegerField(
        choices=[(i, 'Buy from seller %i' % i)
                 for i in range(1, Constants.players_per_group)] +
        [(0, 'Buy nothing')],
        blank=True,
        widget=widgets.RadioSelect(),
        verbose_name='And you will')  # seller index

    def role(self):
        if self.id_in_group == 1:
            return 'buyer'
        return 'seller %i' % (self.id_in_group - 1)
Ejemplo n.º 16
0
class Player(BasePlayer):

    def other_player(self):
        """Returns other player in group"""
        return self.get_others_in_group()[0]

    decision = models.CharField(
        choices=['A', 'B'],
        doc='either A or B',
        widget=widgets.RadioSelect(),
    )

    def set_payoff(self):

        payoff_matrix = {
            'A': {
                'A': Constants.self_A_other_A,
                'B': Constants.self_A_other_B,
            },
            'B': {
                'A': Constants.self_B_other_A,
                'B': Constants.self_B_other_B,
            }
        }

        self.payoff = payoff_matrix[self.decision][self.other_player().decision]
Ejemplo n.º 17
0
class Player(otree.models.BasePlayer):

    # <built-in>
    group = models.ForeignKey(Group, null=True)
    subsession = models.ForeignKey(Subsession)
    # </built-in>

    decision = models.CharField(
        default=None,
        doc="""The player's choice""",
        widget=widgets.RadioSelect()
    )

    def decision_choices(self):
        return ['Stag', 'Hare']

    def other_player(self):
        """Returns other player in group"""
        return self.other_players_in_group()[0]

    def set_payoff(self):

        payoff_matrix = {
            'Stag': {
                'Stag': self.subsession.stag_stag_amount,
                'Hare': self.subsession.stag_hare_amount,
            },
            'Hare': {
                'Stag': self.subsession.hare_stag_amount,
                'Hare': self.subsession.hare_hare_amount,
            }
        }
        self.payoff = payoff_matrix[self.decision][self.other_player().decision]
Ejemplo n.º 18
0
class Player(otree.models.BasePlayer):

    # <built-in>
    group = models.ForeignKey(Group, null=True)
    subsession = models.ForeignKey(Subsession)

    # </built-in>

    def set_payoff(self):
        """Calculate payoff, which is zero for the survey"""
        self.payoff = 0

    q_country = CountryField(
        verbose_name='What is your country of citizenship?')
    q_age = models.PositiveIntegerField(verbose_name='What is your age?',
                                        choices=range(13, 125),
                                        initial=None)
    q_gender = models.CharField(initial=None,
                                choices=['Male', 'Female'],
                                verbose_name='What is your gender?',
                                widget=widgets.RadioSelect())

    crt_bat = models.PositiveIntegerField()
    crt_widget = models.PositiveIntegerField()
    crt_lake = models.PositiveIntegerField()
Ejemplo n.º 19
0
class Player(otree.models.BasePlayer):

    # <built-in>
    group = models.ForeignKey(Group, null=True)
    subsession = models.ForeignKey(Subsession)
    # </built-in>

    training_question_1_husband = models.CurrencyField(
        bounds=[0, Constants.training_1_maximum_offered_points])

    training_question_1_wife = models.CurrencyField(
        bounds=[0, Constants.training_1_maximum_offered_points])

    decision = models.CharField(choices=['Football', 'Opera'],
                                doc="""Either football or the opera""",
                                widget=widgets.RadioSelect())

    def is_training_question_1_husband_correct(self):
        return (self.training_question_1_husband ==
                Constants.training_1_husband_correct)

    def is_training_question_1_wife_correct(self):
        return (
            self.training_question_1_wife == Constants.training_1_wife_correct)

    def other_player(self):
        """Returns other player in group"""
        return self.get_others_in_group()[0]

    def role(self):
        if self.id_in_group == 1:
            return 'husband'
        if self.id_in_group == 2:
            return 'wife'
Ejemplo n.º 20
0
class Player(BasePlayer):
    # <built-in>
    subsession = models.ForeignKey(Subsession)
    group = models.ForeignKey(Group, null = True)
    # </built-in>

    contribution = models.CurrencyField(choices=[0,Constants.endowment],widget=widgets.RadioSelect())
    record = models.CurrencyField()
    punishment_p1 = models.CurrencyField(min=0, max=50)
    punishment_p2 = models.CurrencyField(min=0, max=50)
    punishment_p3 = models.CurrencyField(min=0, max=50)
    income = models.PositiveIntegerField(min=0, max=90)
    cost  = models.PositiveIntegerField(min=0, max=150)
    deduction = models.PositiveIntegerField(min=0, max=150)
    def other_player(self):
        """Returns other player in group. Only valid for 2-player groups."""
        return self.get_others_in_group()

    def set_payoff(self):
        self.income = Constants.endowment - self.contribution + group.individual_share
        self.cost = self.punishment_for_p1 + self.punishment_for_p2 + self.punishment_for_p3
        self.deduction = sum([q.punishment_p1 for q in self.other_player()])

    def role(self):
        if self.id_in_group == 1:
            return 'Player 1'
        if self.id_in_group == 2:
            return 'Player 2'
        if self.id_in_group == 3:
            return 'Player 3'
Ejemplo n.º 21
0
class Player(otree.models.BasePlayer):

    # <built-in>
    group = models.ForeignKey(Group, null=True)
    subsession = models.ForeignKey(Subsession)

    # </built-in>

    def other_player(self):
        """Returns other player in group"""
        return self.get_others_in_group()[0]

    decision = models.CharField(
        doc='either A or B',
        widget=widgets.RadioSelect(),
    )

    def decision_choices(self):
        return ['A', 'B']

    def set_payoff(self):

        payoff_matrix = {
            'A': {
                'A': Constants.self_A_other_A,
                'B': Constants.self_A_other_B,
            },
            'B': {
                'A': Constants.self_B_other_A,
                'B': Constants.self_B_other_B,
            }
        }

        self.payoff = payoff_matrix[self.decision][
            self.other_player().decision]
Ejemplo n.º 22
0
class Group(otree.models.BaseGroup):

    # <built-in>
    subsession = models.ForeignKey(Subsession)
    # </built-in>

    total_return = models.CurrencyField(
        doc="""Total return from agent's effort = [Return for single unit of
            agent's work effort] * [Agent's work effort]""")

    agent_fixed_pay = models.CurrencyField(
        doc="""Amount offered as fixed pay to agent""",
        min=Constants.min_fixed_payment,
        max=Constants.max_fixed_payment,
        verbose_name='Fixed Payment (from %i to %i)' %
        (Constants.min_fixed_payment, Constants.max_fixed_payment))

    agent_return_share = models.FloatField(
        choices=Constants.agent_return_share_choices,
        doc="""Agent's share of total return""",
        verbose_name='Return Share',
        widget=widgets.RadioSelectHorizontal())

    agent_work_effort = models.PositiveIntegerField(
        choices=range(1, 10 + 1),
        doc="""Agent's work effort, [1, 10]""",
        widget=widgets.RadioSelectHorizontal(),
    )

    agent_work_cost = models.CurrencyField(
        doc="""Agent's cost of work effort""")

    contract_accepted = models.BooleanField(
        doc="""Whether agent accepts proposal""",
        widget=widgets.RadioSelect(),
        choices=(
            (True, 'Accept'),
            (False, 'Reject'),
        ))

    def set_payoffs(self):
        principal = self.get_player_by_role('principal')
        agent = self.get_player_by_role('agent')

        if not self.contract_accepted:
            principal.payoff = Constants.reject_principal_pay
            agent.payoff = Constants.reject_agent_pay
        else:
            self.agent_work_cost = cost_from_effort(self.agent_work_effort)
            self.total_return = return_from_effort(self.agent_work_effort)

            money_to_agent = self.agent_return_share * \
                self.total_return + self.agent_fixed_pay
            agent.payoff = money_to_agent - self.agent_work_cost
            principal.payoff = self.total_return - money_to_agent
        principal.payoff += Constants.bonus
        agent.payoff += Constants.bonus

    def return_share_as_percentage(self):
        return utils.float_as_percentage(self.agent_return_share)
Ejemplo n.º 23
0
class Player(otree.models.BasePlayer):

    # <built-in>
    group = models.ForeignKey(Group, null=True)
    subsession = models.ForeignKey(Subsession)
    # </built-in>

    Q1 = models.CharField(
        max_length=255, choices=['One', 'Two', 'Three'],
        verbose_name="How many bids will you submit in each auction round?",
        widget=widgets.RadioSelect())

    Q2 = models.CharField(
        max_length=255,
        choices=[
            "No", "Yes"],
        verbose_name="Will your valuations be drawn anew before each auction round?",
        widget=widgets.RadioSelect())


    Q3 = models.CharField(
        verbose_name=(
            "Are your valuations independent of the valuations assigned to your competitor?"),
        max_length=255, widget=widgets.RadioSelect(),
        choices=[
            "Yes", "No" ])

    Q4 = models.CharField(
        verbose_name=" How are your valuations determined?",
        choices=[
            "The valuation on the second unit (v2) is randomly drawn between 0 and 100, and the value on the first unit (v1) is drawn randomly from the interval between v2 and 100.", "Valuations are same across all 25 auction rounds",
            "Valuations are linked to bids in the last round"],
        max_length=255, widget=widgets.RadioSelect())

    Q5 = models.CharField(
        verbose_name="If you win an item, what price do you pay?",
        widget=widgets.RadioSelect(), max_length=255,
        choices=["My bid corresponding to the unit won", "The market price  determined by the losing bid - the fourth highest bid", "My competitor's highest bid"])

    Q6 = models.CharField(
        verbose_name=(
            "How many units are your guaranteed to purchase?"),
        widget=widgets.RadioSelect(), max_length=255,
        choices=["Zero", "One", "Two"])

    Q7 = models.CharField(
          verbose_name=(
            "Calculate the profits earned by Bidder A on her first unit purchased in the example depicted in the table below"),
          widget=widgets.RadioSelect(), max_length=255,
          choices=["98 - 44 = 54", "98 - 98 = 0", "98 - 56 = 42"])


    Q8 = models.CharField(
          verbose_name=(
              "Calculate the total profits earned by Bidder B on all units purchased in the example depicted in the table below"),
          widget=widgets.RadioSelect(), max_length=255,
          choices=["(56 - 56)+(48 - 48) = 0", "(56 - 44)+(48 - 44) = 16", "(56 - 48)+(48 - 48) = 8"])
Ejemplo n.º 24
0
class Group(BaseGroup):
    prize = models.StringField(choices=['игрок A', 'игрок B'],
                               widget=widgets.RadioSelect())

    def get_winner_name(self):
        s = self.prize.replace('игрок', 'игрок{}')
        return {
            'nominative': s.format(''),
            'genitive': s.format('а'),
            'dative': s.format('у'),
            'accusative': s.format('а'),
            'instrumental': s.format('ом'),
            'prepositional': s.format('е'),
        }

    contribution_A = models.IntegerField(
        min=0,
        max=Constants.endowment,
        doc="""The amount contributed by the player""",
    )

    contribution_B = models.IntegerField(
        min=0,
        max=Constants.endowment,
        doc="""The amount contributed by the player""",
    )

    task_corrects_A = models.IntegerField(default=0)
    task_corrects_B = models.IntegerField(default=0)

    def set_pay(self):
        if self.prize == 'игрок A':
            for p in self.get_players():
                if p.role() == "игрок A":
                    p.pay = (Constants.endowment - self.contribution_A +
                             Constants.prize)
                elif p.role() == "игрок B":
                    p.pay = (Constants.endowment - self.contribution_B)
                elif p.role() == "судья":
                    p.pay = (Constants.endowment + self.contribution_A +
                             self.contribution_B)

        else:
            for p in self.get_players():
                if p.role() == "игрок A":
                    p.pay = (Constants.endowment - self.contribution_A)
                elif p.role() == "игрок B":
                    p.pay = (Constants.endowment - self.contribution_B +
                             Constants.prize)
                elif p.role() == "судья":
                    p.pay = (Constants.endowment + self.contribution_A +
                             self.contribution_B)

    def set_payoff(self):  # this is the payoff of the paid rounds
        for player in self.get_players():
            for rounds in self.session.vars['paying_rounds']:
                if player.round_number == rounds:
                    player.payoff = player.pay
Ejemplo n.º 25
0
class Group(otree.models.BaseGroup):

    # <built-in>
    subsession = models.ForeignKey(Subsession)
    # </built-in>

    players_per_group = 2

    total_return = models.MoneyField(
        doc="""Total return from agent's effort = [Return for single unit of agent's work effort] * [Agent's work effort]"""
    )

    agent_fixed_pay = models.MoneyField(
        doc="""Amount offered as fixed pay to agent"""
    )

    agent_return_share = models.FloatField(
        doc="""Agent's share of total return""",
    )

    agent_work_effort = models.PositiveIntegerField(
        doc="""Agent's work effort, [1, 10]""",
    )


    agent_work_cost = models.MoneyField(
        doc="""Agent's cost of work effort"""
    )

    contract_accepted = models.NullBooleanField(
        doc="""Whether agent accepts proposal""",
        widget=widgets.RadioSelect(),
    )

    # choices
    def agent_fixed_pay_choices(self):
        return money_range(-Constants.max_fixed_payment, Constants.max_fixed_payment, 0.50)

    def agent_work_effort_choices(self):
        return range(1, 10+1)

    def agent_return_share_choices(self):
        return Constants.agent_return_share_choices

    def set_payoffs(self):
        principal = self.get_player_by_role('principal')
        agent = self.get_player_by_role('agent')

        if not self.contract_accepted:
            principal.payoff = Constants.reject_principal_pay
            agent.payoff = Constants.reject_agent_pay
        else:
            self.agent_work_cost = cost_from_effort(self.agent_work_effort)
            self.total_return = return_from_effort(self.agent_work_effort)

            money_to_agent = self.agent_return_share*self.total_return + self.agent_fixed_pay
            agent.payoff = money_to_agent - self.agent_work_cost
            principal.payoff = self.total_return - money_to_agent
Ejemplo n.º 26
0
class Group(BaseGroup):
    # <built-in>
    subsession = models.ForeignKey(Subsession)
    # </built-in>

    type = models.CharField(choices=['SIM', 'SEQ'],
                            doc="""今回のゲームのタイプは""",
                            widget=widgets.RadioSelect())

    def place(self):
        place = [[0, 0], [0, 0]]
        players = self.get_players()
        i = 0
        for p in players:
            place[i][0] = p.x_place
            place[i][1] = p.y_place
            i += 1
        return place

    def place2(self):
        o_place = [0, 0]
        p = self.get_player_by_id(1)
        o_place[0] = p.x_place
        o_place[1] = p.y_place
        return o_place

    def game_type(self):
        self.type = self.in_previous_rounds()[0].type

    def set_payoffs(self):
        p1 = self.get_player_by_id(1)
        p2 = self.get_player_by_id(2)
        Fx = 0.0
        for i in range(50):
            for j in range(20):
                mytotalcomsumer = (p1.x_place - i)**2 + (p1.y_place - j)**2
                othertotalcomsumer = (p2.x_place - i)**2 + (p2.y_place - j)**2
                if mytotalcomsumer < othertotalcomsumer:
                    Fx += 1.0
                elif mytotalcomsumer == othertotalcomsumer:
                    Fx += 0.5
        mycomsumer = 0.0
        othercomsumer = 0.0
        for i in range(50):
            for j in range(20):
                mytotalprice = 100 + (p1.x_place - i)**2 + (p1.y_place - j)**2
                othertotalprice = ((1000 - Fx) / Fx * 100) + (
                    p2.x_place - i)**2 + (p2.y_place - j)**2
                if mytotalprice < othertotalprice:
                    mycomsumer += 1.0
                elif mytotalprice == othertotalprice:
                    mycomsumer += 0.5
                    othercomsumer += 0.5
                else:
                    othercomsumer += 1.0
        p1.payoff = 100 * mycomsumer
        p2.payoff = ((1000 - Fx) / Fx * 100) * othercomsumer
Ejemplo n.º 27
0
class Player(otree.models.BasePlayer):

    # <built-in>
    group = models.ForeignKey(Group, null=True)
    subsession = models.ForeignKey(Subsession)
    # </built-in>

    training_question_1 = models.CharField(max_length=100,
                                           null=True,
                                           verbose_name='',
                                           widget=widgets.RadioSelect())

    def training_question_1_choices(self):
        return [
            'Player 1 gets 0 points, Player 2 gets 0 points',
            'Player 1 gets 100 points, Player 2 gets 100 points',
            'Player 1 gets 100 points, Player 2 gets 0 points',
            'Player 1 gets 0 points, Player 2 gets 100 points'
        ]

    def is_training_question_1_correct(self):
        return self.training_question_1 == self.subsession.training_1_correct

    points_earned = models.PositiveIntegerField(default=0,
                                                doc="""Points earned""")

    penny_side = models.CharField(choices=['Heads', 'Tails'],
                                  doc="""Heads or tails""",
                                  widget=widgets.RadioSelect())

    is_winner = models.NullBooleanField(doc="""Whether player won the round""")

    def other_player(self):
        """Returns the opponent of the current player"""
        return self.other_players_in_group()[0]

    def role(self):
        if self.id_in_group == 1:
            return 'Player 1'
        if self.id_in_group == 2:
            return 'Player 2'

    def set_payoff(self):
        self.payoff = 0
Ejemplo n.º 28
0
class Player(BasePlayer):

    ethnic = models.CharField(
    )  # Variable to store the participants' ethnicity
    religion = models.CharField(
    )  # Variable to store the participants' religion
    # Input variable to ask the participants' ethnicity
    ethnic_in = models.CharField(
        initial=None,
        choices=[Constants.ethnicity_dai, Constants.ethnicity_han],
        widget=widgets.RadioSelect())
    # Input variable to ask the participants' religion
    religion_in = models.CharField(initial=None,
                                   choices=[
                                       Constants.religion_buddhist,
                                       Constants.religion_christian,
                                       Constants.religion_none
                                   ],
                                   widget=widgets.RadioSelect())

    # Function defined to get the ethnicity of the other participant in the group in the trust game
    def other_eth(self):
        return self.get_others_in_group()[0].participant.vars['ethnic']

    # Function defined to get the religion of the other participant in the group in the trust game
    def other_relig(self):
        return self.get_others_in_group()[0].participant.vars['religion']

    def get_ethnicity(self):
        return self.in_all_rounds()[0].participant.vars['ethnic']

    def get_religion(self):
        return self.in_all_rounds()[0].participant.vars['religion']

    # Prepayoff is the payment of each round
    prepayoff = models.CurrencyField()
    # Payoff_block1 is the payment of the round selected to be paid
    # Block 1 refers to the trust game
    # Block 2 refers to the public goods game with punishment
    payoff_block1 = models.CurrencyField()

    # Variables to store the responses to the understanding questions
    question_trustA = models.CurrencyField()
    question_trustB = models.CurrencyField()
Ejemplo n.º 29
0
class Player(otree.models.BasePlayer):
    # <built-in>
    group = models.ForeignKey(Group, null=True)
    subsession = models.ForeignKey(Subsession)
    # </built-in>

    rating = models.IntegerField(default=None,
                                 choices=RATING_CHOICES,
                                 doc="Players enter norm rating",
                                 widget=widgets.RadioSelect())
Ejemplo n.º 30
0
class Player(BasePlayer):

    ethnic_in = models.CharField(initial=None,
                                 choices=['Dai', 'Han'],
                                 widget=widgets.RadioSelect())
    religion_in = models.CharField(
        initial=None,
        choices=['Buddhist', 'Christian', 'None (atheist)'],
        widget=widgets.RadioSelect())

    def other_eth(self):
        return self.get_others_in_group()[0].participant.vars['ethnic']

    def other_relig(self):
        return self.get_others_in_group()[0].participant.vars['religion']

    prepayoff = models.CurrencyField()

    question_trustA = models.CurrencyField()
    question_trustB = models.CurrencyField()