Exemple #1
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'
Exemple #2
0
class Player(BasePlayer):
    # <built-in>
    subsession = models.ForeignKey(Subsession)
    group = models.ForeignKey(Group, null=True)
    # </built-in>

    contribution = models.CurrencyField(min=0, max=Constants.endowment)
Exemple #3
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'
Exemple #4
0
class Player(BasePlayer):
    # <built-in>
    subsession = models.ForeignKey(Subsession)
    group = models.ForeignKey(Group, null=True)
    # </built-in>
    x_place = models.FloatField()
    y_place = models.FloatField()
    price = models.CurrencyField(doc="""The mill price""", )

    def other_player(self):
        """Returns other player in group. Only valid for 2-player groups."""
        return self.get_others_in_group()[0]
Exemple #5
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()

    def other_player(self):
        """Returns other player in group. Only valid for 2-player groups."""
        return self.get_others_in_group()
Exemple #6
0
class Player(otree.models.BasePlayer):
    # <built-in>
    subsession = models.ForeignKey(Subsession)
    group = models.ForeignKey(Group, null=True)

    # </built-in>
    def set_payoff(self):
        self.payoff = 0

    # example field
    q_race = models.CharField(
        initial=None,
        choices=RACE_CHOICES,
        verbose_name="Ethnicity origin (or Race): Please specify your ethnicity"
    )
    q_age = models.PositiveIntegerField(verbose_name="What is your age?",
                                        choices=range(13, 125),
                                        initial=None)
    q_gender = models.CharField(initial=None,
                                choices=['Female', 'Male'],
                                verbose_name="What is your gender?",
                                widget=widgets.RadioSelect())
    q_education = models.CharField(
        initial=None,
        choices=EDUCATION_CHOICES,
        verbose_name=
        "Education: What is the highest degree or level of school you have completed?",
    )
    q_household = models.CharField(
        initial=None,
        choices=HOUSEHOLD_CHOICES,
        verbose_name="Marital Status: What is your marital status",
    )
    q_gpa = models.CharField(
        blank=True, verbose_name="If you are a student, what is your gpa?")
    q_professional = models.CharField(
        initial=None,
        choices=PROFESSIONAL_CHOICES,
        verbose_name="Employment Status: Are you currenly...?",
    )
    q_decision = models.TextField(
        initial=None,
        verbose_name=
        "Can you explain in few words what guided your decision to invest or not invest in the Group Account?"
    )
    q_comments = models.TextField(
        blank=True,
        initial=None,
        verbose_name=
        "Do you have any comment, questions, or complains about today's experiment?"
    )
Exemple #7
0
class Player(BasePlayer):
    # <built-in>
    subsession = models.ForeignKey(Subsession)
    group = models.ForeignKey(Group, null=True)

    # </built-in>

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

    def role(self):
        # you can make this depend of self.id_in_group
        return ''
Exemple #8
0
class Group(BaseGroup):
    # <built-in>
    subsession = models.ForeignKey(Subsession)
    # </built-in>
    total_contribution = models.CurrencyField()
    individual_share = models.CurrencyField()

    def set_records(self):
        for p in self.get_players():
            x = random.random()
            if x < 0.1:
                p.record = 0
            if x >= 0.1:
                p.record = p.contribution
            

    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
        for p in self.get_players():
            p.income = Constants.endowment - p.contribution + self.individual_share
            p.cost = p.punishment_p1 + p.punishment_p2 + p.punishment_p3
            if p.id_in_group == 1:
                p.deduction = sum([q.punishment_p1 for q in p.other_player()])
            if p.id_in_group == 2:
                p.deduction = sum([q.punishment_p2 for q in p.other_player()])
            if p.id_in_group == 3:
                p.deduction = sum([q.punishment_p3 for q in p.other_player()])
            if p.income >= (3 * p.deduction):#ここは解釈が正しいか確信がない
                p.payoff = p.income - p.cost - 3 * p.deduction
            if p.income < (3 * p.deduction):
                p.payoff = 0 - p.cost
Exemple #9
0
class Message(models.Model):

    group = models.ForeignKey(Group)
    player = models.ForeignKey(Player)
    message = models.TextField()
    timestamp = models.DateTimeField(auto_now_add=True)

    COLORS = {1: "#F249F2",
              2: "#60AB4F",
              3: "#FCC767",
              4: "#FF7979",
              5: "#F249F2"}

    @property
    def color(self):
        return Message.COLORS[self.player.id_in_group]
Exemple #10
0
class Group(otree.models.BaseGroup):
    # <built-in>
    subsession = models.ForeignKey(Subsession)
    # </built-in>


    x = Album(1)
    y = Album(2)
    z = Album(3)
    a = Album(4)

    val = x.value
    val1 = y.value
    val2 = z.value
    val3 = a.value




    def set_payoffs(self):
        consumer = self.get_player_by_role('consumer')
        producer = self.get_player_by_role('producer')


        consumer.payoff = self.val
        producer.payoff = 20
Exemple #11
0
class Group(BaseGroup):
    # <built-in>
    subsession = models.ForeignKey(Subsession)

    # </built-in>

    def set_payoffs(self):
        for p in self.get_players():
            p.payoff = 0  # change to whatever the payoff should be
Exemple #12
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
Exemple #13
0
class Group(BaseGroup):
    # <built-in>
    subsession = models.ForeignKey(Subsession)
    # </built-in>
    networktype = models.CharField()

    def network_type(self):
        network_type_group = ['Blue network', 'Red network', 'Brown network']
        network_type = random.choice(network_type_group, p=Constants.weight)
        return network_type

    def network(self):
        network_type = str(self.network_tp)
        if network_type == 'Blue network':
            network = {
                'A': ['B'],
                'B': ['A', 'C', 'E'],
                'C': ['B', 'D', 'E'],
                'D': ['C', 'E'],
                'E': ['B', 'C', 'D']
            }
        elif network_type == 'Red network':
            network = {
                'A': ['B'],
                'B': ['A', 'C'],
                'C': ['B', 'D', 'E'],
                'D': ['C', 'E'],
                'E': ['C', 'D']
            }
        else:
            network = {
                'A': ['B'],
                'B': ['A', 'C', 'E'],
                'C': ['B', 'D'],
                'D': ['C', 'E'],
                'E': ['B', 'D']
            }
        network_group = [network_type, network]
        return network_group

    def set_payoffs(self):
        network_group = self.network_histry[self.subsession.round_number - 1]
        self.network_type = network_group[0]
        self.network = network_group[1]
        player = [0 for i in range(Constants.players_per_group)]
        active = [0 for i in range(Constants.players_per_group)]
        i = 0
        for role in Constants.places:
            player[i] = self.get_player_by_role(role)
            assign_nghb = self.network[role]
            for other_role in assign_nghb:
                if self.get_player_by_role(other_role).decision == 'ACTIVE':
                    active[i] += 1
            player[i].payoff = float(100 * active[i] / 3)
            player[i].num_active = active[i]
            i += 1
Exemple #14
0
class Group(BaseGroup):
    # <built-in>
    subsession = models.ForeignKey(Subsession)
    # </built-in>
    total_contribution = models.CurrencyField()
    individual_share = models.CurrencyField()
    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
        for p in self.get_players():
            p.payoff = Constants.endowment - p.contribution + self.individual_share # change to whatever the payoff should be
Exemple #15
0
class Player(otree.models.BasePlayer):
    # <built-in>
    subsession = models.ForeignKey(Subsession)
    group = models.ForeignKey(Group, null = True)
    # </built-in>

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

    # example field
    my_field = models.PositiveIntegerField(
        min=0,
        max=(Constants.producer_budget/Constants.album_production_cost),
        doc="""
        Description of this field, for documentation
        """
    )

    consumer_purchase = models.PositiveIntegerField(
        min=0,
        max=(Constants.consumer_budget/Constants.album_own_cost),
        doc="""
        Description of this field, for documentation
        """
    )

    album_purchase = models.PositiveIntegerField(
        min = 0,
        max = 1,
        doc = """ Binary album purchase
        """
    )


    def role(self):
        # you can make this depend of self.id_in_group
        if self.id_in_group == 1:
            return 'producer'
        if self.id_in_group == 2:
            return 'consumer'
Exemple #16
0
class Player(otree.models.BasePlayer):
    # <built-in>
    subsession = models.ForeignKey(Subsession)
    group = models.ForeignKey(Group, null=True)

    # </built-in>

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

    # example field
    my_field = models.CurrencyField(min=c(0),
                                    max=c(10),
                                    doc="""
        Description of this field, for documentation
        """)

    def role(self):
        # you can make this depend of self.id_in_group
        return ''
Exemple #17
0
class Group(otree.models.BaseGroup):
    # <built-in>
    subsession = models.ForeignKey(Subsession)
    # </built-in>

    total_contribution = models.CurrencyField()
    individual_share = models.CurrencyField()

    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
        for p in self.get_players():
            p.payoff = Constants.endowment - p.contribution + self.individual_share
Exemple #18
0
class Player(otree.models.BasePlayer):

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

    decision = models.CharField(choices=['ACTIVE', 'INACTIVE'],
                                doc="""このプレイヤーの選択は""",
                                widget=widgets.RadioSelect())

    nghb = models.PositiveIntegerField()
    num_active = models.PositiveIntegerField()

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

    def role(self):
        return Constants.places[self.id_in_group - 1]

    def num_nghb(self):
        return len(Group.network_histry[self.subsession.round_number -
                                        1][1][self.role()])
Exemple #19
0
class Group(BaseGroup):
    # <built-in>
    subsession = models.ForeignKey(Subsession)
    # </built-in>
    total_contribution = models.CurrencyField()
    individual_share = models.CurrencyField()

    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
        for p in self.get_players():
            p.payoff = Constants.endowment - p.contribution + self.individual_share
            x = random.random()
            if x < 0.1:
                p.record = 0
            if x >= 0.1:
                p.record = p.contribution
Exemple #20
0
class Group(BaseGroup):
    # <built-in>
    subsession = models.ForeignKey(Subsession)
    # </built-in>
    total_contribution = models.CurrencyField()
    individual_share = models.CurrencyField()

    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
        for p in self.get_players():
            p.income = Constants.endowment - p.contribution + self.individual_share
            p.cost = p.punishment_p1 + p.punishment_p2 + p.punishment_p3
            if p.id_in_group == 1:
                p.deduction = sum([q.punishment_p1 for q in p.other_player()])
            if p.id_in_group == 2:
                p.deduction = sum([q.punishment_p2 for q in p.other_player()])
            if p.id_in_group == 3:
                p.deduction = sum([q.punishment_p3 for q in p.other_player()])
            p.payoff = p.income - p.cost - 6 * p.deduction
Exemple #21
0
class Group(otree.models.BaseGroup):

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

    # </built-in>

    def set_payoffs(self):
        husband = self.get_player_by_role('husband')
        wife = self.get_player_by_role('wife')

        if husband.decision != wife.decision:
            husband.payoff = Constants.mismatch_amount
            wife.payoff = Constants.mismatch_amount

        else:
            if husband.decision == 'Football':
                husband.payoff = Constants.football_husband_amount
                wife.payoff = Constants.football_wife_amount
            else:
                husband.payoff = Constants.opera_husband_amount
                wife.payoff = Constants.opera_wife_amount
Exemple #22
0
class Group(otree.models.BaseGroup):
    # <built-in>
    subsession = models.ForeignKey(Subsession)
    # </built-in>

    A1 = Album(1)
    A2 = Album(2)
    A3 = Album(3)
    A4 = Album(4)
    A5 = Album(5)
    A6 = Album(6)
    A7 = Album(7)
    A8 = Album(8)
    A9 = Album(9)
    A10 = Album(10)

    val = A1.value
    val1 = A2.value
    val2 = A3.value
    val3 = A4.value
    val4 = A5.value
    val5 = A6.value
    val6 = A7.value
    val7 = A8.value
    val8 = A9.value
    val9 = A10.value

    def get_albums(self):
        producer = self.get_player_by_role('producer')

        return producer.my_field

    def get_albums2(self):

        producer2 = self.get_player_by_role('producer2')

        return producer2.my_field

    def get_value(self):
        consumer = self.get_player_by_role('consumer')

        return consumer.totalValue

    def calc_prod_albumsBought(self):
        calcBought = 0
        producer = self.get_player_by_role('producer')
        for p in producer.get_others_in_group():
            if p.id_in_group != 2:
                calcBought += p.album1BuyCount
                calcBought += p.album2BuyCount
                calcBought += p.album3BuyCount
                calcBought += p.album4BuyCount
                calcBought += p.album5BuyCount
        return calcBought

    def calc_prod_albumsBought2(self):
        calcBought2 = 0
        producer2 = self.get_player_by_role('producer2')
        for p in producer2.get_others_in_group():
            if p.id_in_group != 1:
                calcBought2 += p.album6BuyCount
                calcBought2 += p.album7BuyCount
                calcBought2 += p.album8BuyCount
                calcBought2 += p.album9BuyCount
                calcBought2 += p.album10BuyCount
        return calcBought2

    def calc_prod_albumsPirated(self):
        calcPirated = 0
        producer = self.get_player_by_role('producer')
        for p in producer.get_others_in_group():
            if p.id_in_group != 2:
                calcPirated += p.album1PiracyCount
                calcPirated += p.album2PiracyCount
                calcPirated += p.album3PiracyCount
                calcPirated += p.album4PiracyCount
                calcPirated += p.album5PiracyCount
        return calcPirated

    def calc_prod_albumsPirated2(self):
        calcPirated2 = 0
        producer2 = self.get_player_by_role('producer2')
        for p in producer2.get_others_in_group():
            if p.id_in_group != 1:
                calcPirated2 += p.album6PiracyCount
                calcPirated2 += p.album7PiracyCount
                calcPirated2 += p.album8PiracyCount
                calcPirated2 += p.album9PiracyCount
                calcPirated2 += p.album10PiracyCount
        return calcPirated2

    def calc_prod_albumsListened(self):
        calcListens = 0
        producer = self.get_player_by_role('producer')
        for p in producer.get_others_in_group():
            if p.id_in_group != 2:
                calcListens += p.album1ListenCount
                calcListens += p.album2ListenCount
                calcListens += p.album3ListenCount
                calcListens += p.album4ListenCount
                calcListens += p.album5ListenCount
        return calcListens

    def calc_prod_albumsListened2(self):
        calcListens2 = 0
        producer2 = self.get_player_by_role('producer2')
        for p in producer2.get_others_in_group():
            if p.id_in_group != 1:
                calcListens2 += p.album6ListenCount
                calcListens2 += p.album7ListenCount
                calcListens2 += p.album8ListenCount
                calcListens2 += p.album9ListenCount
                calcListens2 += p.album10ListenCount
        return calcListens2

    def calc_prod_payoff(self):
        calcPayoff = 0
        producer = self.get_player_by_role('producer')
        for p in producer.get_others_in_group():
            if p.id_in_group != 2:
                calcPayoff += p.album1BuyCount
                calcPayoff += p.album2BuyCount
                calcPayoff += p.album3BuyCount
                calcPayoff += p.album4BuyCount
                calcPayoff += p.album5BuyCount
                calcPayoff *= Constants.album_own_cost
        return calcPayoff

    def calc_prod2_payoff(self):
        calc2Payoff = 0
        producer2 = self.get_player_by_role('producer2')
        for p in producer2.get_others_in_group():
            if p.id_in_group != 1:
                calc2Payoff += p.album6BuyCount
                calc2Payoff += p.album7BuyCount
                calc2Payoff += p.album8BuyCount
                calc2Payoff += p.album9BuyCount
                calc2Payoff += p.album10BuyCount
                calc2Payoff *= Constants.album_own_cost
        return calc2Payoff

    def set_payoffs(self):
        consumer = self.get_player_by_role('consumer')
        producer = self.get_player_by_role('producer')
        producer2 = self.get_player_by_role('producer2')

        consumer.payoff = self.get_value()
        producer.payoff = self.calc_prod_payoff()
        producer2.payoff = self.calc_prod2_payoff()
Exemple #23
0
class Player(otree.models.BasePlayer):
    # <built-in>
    subsession = models.ForeignKey(Subsession)
    group = models.ForeignKey(Group, null=True)
    # </built-in>

    # example field
    my_field = models.PositiveIntegerField(
        min=0,
        max=(Constants.producer_budget / Constants.album_production_cost),
        doc="""
        Description of this field, for documentation
        """)

    totalValue = models.PositiveIntegerField()

    album1BuyCount = models.PositiveIntegerField()
    album2BuyCount = models.PositiveIntegerField()
    album3BuyCount = models.PositiveIntegerField()
    album4BuyCount = models.PositiveIntegerField()
    album5BuyCount = models.PositiveIntegerField()
    album6BuyCount = models.PositiveIntegerField()
    album7BuyCount = models.PositiveIntegerField()
    album8BuyCount = models.PositiveIntegerField()
    album9BuyCount = models.PositiveIntegerField()
    album10BuyCount = models.PositiveIntegerField()

    album1ListenCount = models.PositiveIntegerField()
    album2ListenCount = models.PositiveIntegerField()
    album3ListenCount = models.PositiveIntegerField()
    album4ListenCount = models.PositiveIntegerField()
    album5ListenCount = models.PositiveIntegerField()
    album6ListenCount = models.PositiveIntegerField()
    album7ListenCount = models.PositiveIntegerField()
    album8ListenCount = models.PositiveIntegerField()
    album9ListenCount = models.PositiveIntegerField()
    album10ListenCount = models.PositiveIntegerField()

    album1PiracyCount = models.PositiveIntegerField()
    album2PiracyCount = models.PositiveIntegerField()
    album3PiracyCount = models.PositiveIntegerField()
    album4PiracyCount = models.PositiveIntegerField()
    album5PiracyCount = models.PositiveIntegerField()
    album6PiracyCount = models.PositiveIntegerField()
    album7PiracyCount = models.PositiveIntegerField()
    album8PiracyCount = models.PositiveIntegerField()
    album9PiracyCount = models.PositiveIntegerField()
    album10PiracyCount = models.PositiveIntegerField()

    subPurchaseCount = models.PositiveIntegerField()

    def get_num_bought(self):
        numB = 0
        numB += self.album1BuyCount
        numB += self.album2BuyCount
        numB += self.album3BuyCount
        numB += self.album4BuyCount
        numB += self.album5BuyCount
        numB += self.album6BuyCount
        numB += self.album7BuyCount
        numB += self.album8BuyCount
        numB += self.album9BuyCount
        numB += self.album10BuyCount
        return numB

    def get_num_pirate(self):
        numP = 0
        numP += self.album1PiracyCount
        numP += self.album2PiracyCount
        numP += self.album3PiracyCount
        numP += self.album4PiracyCount
        numP += self.album5PiracyCount
        numP += self.album6PiracyCount
        numP += self.album7PiracyCount
        numP += self.album8PiracyCount
        numP += self.album9PiracyCount
        numP += self.album10PiracyCount
        return numP

    def get_num_listen(self):
        numL = 0
        numL += self.album1ListenCount
        numL += self.album2ListenCount
        numL += self.album3ListenCount
        numL += self.album4ListenCount
        numL += self.album5ListenCount
        numL += self.album6ListenCount
        numL += self.album7ListenCount
        numL += self.album8ListenCount
        numL += self.album9ListenCount
        numL += self.album10ListenCount
        return numL

    def role(self):
        # you can make this depend of self.id_in_group
        if self.id_in_group == 1:
            return 'producer'
        if self.id_in_group == 2:
            return 'producer2'
        if self.id_in_group == 3:
            return 'consumer'
Exemple #24
0
class Player(BasePlayer):
    # <built-in>
    subsession = models.ForeignKey(Subsession)
    group = models.ForeignKey(Group, null=True)
    # </built-in>

    # whether bomb is collected or not
    bomb = models.IntegerField()

    # location of bomb with row/col info
    bomb_location = models.TextField()

    # number of collected boxes
    boxes_collected = models.IntegerField()

    # set/scheme of collected boxes
    boxes_scheme = models.TextField()

    # --- set round results and player's payoff
    # ------------------------------------------------------------------------------------------------------------------
    round_to_pay = models.IntegerField()
    round_result = models.CurrencyField()

    def set_payoff(self):
        # randomly determine round to pay on player level
        if self.subsession.round_number == 1:
            self.session.vars['round_to_pay'] = random.randint(
                1, Constants.num_rounds)

        # determine round_result as (potential) payoff per round
        if self.bomb == 0:
            self.round_result = c(self.boxes_collected * Constants.box_value)
        else:
            self.round_result = c(0)

        # set payoffs if <random_payoff = True> to round_result of randomly chosen round
        if Constants.random_payoff == True:
            if self.subsession.round_number == self.session.vars[
                    'round_to_pay']:
                self.payoff = self.round_result
            else:
                self.payoff = c(0)

        # set payoffs to round_result if <random_payoff = False>
        else:
            self.payoff = self.round_result

    # --- store values as global variables for session-wide use
    # ------------------------------------------------------------------------------------------------------------------
    def set_globals(self):
        self.session.vars['bomb'] = [p.bomb for p in self.in_all_rounds()]
        self.session.vars['bomb_location'] = [
            p.bomb_location for p in self.in_all_rounds()
        ]
        self.session.vars['boxes_collected'] = [
            p.boxes_collected for p in self.in_all_rounds()
        ]
        self.session.vars['boxes_scheme'] = [
            p.boxes_scheme for p in self.in_all_rounds()
        ]
        self.session.vars['round_result'] = [
            p.round_result for p in self.in_all_rounds()
        ]
        self.session.vars['bret_payoff'] = [
            p.payoff for p in self.in_all_rounds()
        ]
Exemple #25
0
class Player(otree.models.BasePlayer):

    TRUE_FALSE_CHOICES = (
        ('True', 'True'),
        ('False', 'False'),
    )

    PRIVATE_CHOICES_2 = (
        ("1", "0.45, 0.55, 0.65"),
        ("2", "0.25, 0.35, 0.45"),
        ("3", "0.35, 0.45, 0.55"),
    )

    PRIVATE_CHOICES_3 = (
        ("1", "0.95, 1.05, 1.15"),
        ("2", "0.85, 0.95, 1.05"),
        ("3", "0.75, 0.85, 0.95"),
    )

    PUBLIC_CHOICES_2 = (
        ("1", "1.05, 1.15, 1.25"),
        ("2", "0.95, 1.05"),
        ("3", "1.05"),
    )

    PUBLIC_CHOICES_3 = (
        ("1", "0.95, 1.05, 1.15"),
        ("2", "1.05, 1.15"),
        ("3", "1.05, 1.15, 1.25"),
    )

    PRIVATE_WIDE_CHOICES_2 = (
        ("1", "0.05, 0.15, 0.25, 0.35, 0.45"),
        ("2", "0.55, 0.65, 0.75, 0.85, 0.95"),
        ("3", "0.25, 0.35, 0.45, 0.55, 0.65"),
    )

    PRIVATE_WIDE_CHOICES_3 = (
        ("1", "0.55, 0.65, 0.75, 0.85, 0.95"),
        ("2", "0.75, 0.85, 0.95, 1.05, 1.15"),
        ("3", "0.65, 0.75, 0.85, 0.95, 1.05"),
    )

    PUBLIC_WIDE_CHOICES_2 = (
        ("1", "0.85, 0.95, 1.05, 1.15, 1.25"),
        ("2", "1.05, 1.15, 1.25"),
        ("3", "0.85, 0.95, 1.05"),
    )

    PUBLIC_WIDE_CHOICES_3 = (
        ("1", "0.55, 0.65"),
        ("2", "0.35, 0.45, 0.55"),
        ("3", "0.25, 0.35, 0.45. 0.55, 0.65"),
    )

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

    label = models.CharField()
    q_first_q1 = models.CharField(initial=None,
                                  choices=TRUE_FALSE_CHOICES,
                                  widget=widgets.RadioSelect())
    q_first_q2 = models.CharField(initial=None,
                                  choices=TRUE_FALSE_CHOICES,
                                  widget=widgets.RadioSelect())
    q_first_q3 = models.CharField(initial=None,
                                  choices=TRUE_FALSE_CHOICES,
                                  widget=widgets.RadioSelect())
    q_first_q4 = models.CharField(initial=None,
                                  choices=TRUE_FALSE_CHOICES,
                                  widget=widgets.RadioSelect())
    q_first_q5 = models.CharField(initial=None,
                                  choices=TRUE_FALSE_CHOICES,
                                  widget=widgets.RadioSelect())
    q_first_q6 = models.CharField(initial=None,
                                  choices=TRUE_FALSE_CHOICES,
                                  widget=widgets.RadioSelect())
    private_2_q1 = models.CharField(initial=None,
                                    choices=TRUE_FALSE_CHOICES,
                                    widget=widgets.RadioSelect())
    private_2_q2 = models.CharField(initial=None,
                                    choices=TRUE_FALSE_CHOICES,
                                    widget=widgets.RadioSelect())
    private_2_q3 = models.CharField(initial=None,
                                    choices=TRUE_FALSE_CHOICES,
                                    widget=widgets.RadioSelect())
    private_2_q4 = models.CharField(initial=None,
                                    choices=PRIVATE_CHOICES_2,
                                    widget=widgets.RadioSelect())
    private_3_q1 = models.CharField(initial=None,
                                    choices=TRUE_FALSE_CHOICES,
                                    widget=widgets.RadioSelect())
    private_3_q2 = models.CharField(initial=None,
                                    choices=PRIVATE_CHOICES_3,
                                    widget=widgets.RadioSelect())
    exact_2_q1 = models.CharField(initial=None,
                                  choices=TRUE_FALSE_CHOICES,
                                  widget=widgets.RadioSelect())
    exact_3_q1 = models.CharField(initial=None,
                                  choices=TRUE_FALSE_CHOICES,
                                  widget=widgets.RadioSelect())
    public_2_q1 = models.CharField(initial=None,
                                   choices=TRUE_FALSE_CHOICES,
                                   widget=widgets.RadioSelect())
    public_2_q2 = models.CharField(initial=None,
                                   choices=TRUE_FALSE_CHOICES,
                                   widget=widgets.RadioSelect())
    public_2_q3 = models.CharField(initial=None,
                                   choices=TRUE_FALSE_CHOICES,
                                   widget=widgets.RadioSelect())
    public_2_q4 = models.CharField(initial=None,
                                   choices=PUBLIC_CHOICES_2,
                                   widget=widgets.RadioSelect())
    public_3_q1 = models.CharField(initial=None,
                                   choices=TRUE_FALSE_CHOICES,
                                   widget=widgets.RadioSelect())
    public_3_q2 = models.CharField(initial=None,
                                   choices=TRUE_FALSE_CHOICES,
                                   widget=widgets.RadioSelect())
    public_3_q3 = models.CharField(initial=None,
                                   choices=PUBLIC_CHOICES_3,
                                   widget=widgets.RadioSelect())

    private_wide_2_q1 = models.CharField(initial=None,
                                         choices=['True', 'False'],
                                         widget=widgets.RadioSelect())
    private_wide_2_q2 = models.CharField(initial=None,
                                         choices=['True', 'False'],
                                         widget=widgets.RadioSelect())
    private_wide_2_q3 = models.CharField(initial=None,
                                         choices=['True', 'False'],
                                         widget=widgets.RadioSelect())
    private_wide_2_q4 = models.CharField(initial=None,
                                         choices=PRIVATE_WIDE_CHOICES_2,
                                         widget=widgets.RadioSelect())
    private_wide_3_q1 = models.CharField(initial=None,
                                         choices=['True', 'False'],
                                         widget=widgets.RadioSelect())
    private_wide_3_q2 = models.CharField(initial=None,
                                         choices=PRIVATE_WIDE_CHOICES_3,
                                         widget=widgets.RadioSelect())

    public_wide_2_q1 = models.CharField(initial=None,
                                        choices=['True', 'False'],
                                        widget=widgets.RadioSelect())
    public_wide_2_q2 = models.CharField(initial=None,
                                        choices=['True', 'False'],
                                        widget=widgets.RadioSelect())
    public_wide_2_q3 = models.CharField(initial=None,
                                        choices=['True', 'False'],
                                        widget=widgets.RadioSelect())
    public_wide_2_q4 = models.CharField(initial=None,
                                        choices=PUBLIC_WIDE_CHOICES_2,
                                        widget=widgets.RadioSelect())
    public_wide_3_q1 = models.CharField(initial=None,
                                        choices=['True', 'False'],
                                        widget=widgets.RadioSelect())
    public_wide_3_q2 = models.CharField(initial=None,
                                        choices=['True', 'False'],
                                        widget=widgets.RadioSelect())
    public_wide_3_q3 = models.CharField(initial=None,
                                        choices=PUBLIC_WIDE_CHOICES_3,
                                        widget=widgets.RadioSelect())

    def set_label(self):
        self.participant.label = self.label
        self.label = ""

    def get_quiz(self):
        treatment = self.session.config['treatment']
        signalVariance = self.session.config['signalVariance']
        if treatment == 1:
            quiz = "exact"
        elif treatment == 2 or treatment == 4:
            quiz = "private"
        elif treatment == 3 or treatment == 5:
            quiz = "public"
        else:
            quiz = "NONE"

        if treatment == 2 and signalVariance == 2:
            quiz = "private_wide"
        elif treatment == 3 and signalVariance == 2:
            quiz = "public_wide"
        else:
            pass
        return quiz

    def get_form_fields(self, pnum):
        form_fields = []
        if pnum == 1:
            for x in range(1, len(dict_of_dicts['q_first']) + 1):
                form_fields.append("q_first_q{}".format(x))
        else:
            quiz = self.get_quiz()
            quiz = "{}_{}".format(quiz, pnum)
            for x in range(1, len(dict_of_dicts[quiz])):
                form_fields.append("{}_q{}".format(quiz, x))
        return form_fields
Exemple #26
0
class Group(otree.models.BaseGroup):
    # <built-in>
    subsession = models.ForeignKey(Subsession)