예제 #1
0
파일: models.py 프로젝트: napaza147/Quiz_1
class Player(BasePlayer):
    """
    Description:
        Inherits oTree class BasePlayer. Defines player characteristics.
    Input:
        None
    Output:
        None
    """

    #Definir el  pay-off del sistema
    def set_payoffs(self):
        p.payoff = self.player.quiz_earnings

    time_spent_on_instructions = models.FloatField(initial=0)

    # Preguntas del escenario de control
    control_1 = models.IntegerField(label="¿Usted ha consumido cigarrillos al menos una vez en su vida?", choices=[[0, "No"], [1, "Sí"]], widget=widgets.RadioSelect)
    control_2 = models.IntegerField(label="Durante el año 2020, ¿Usted ha consumido cigarrillos?", choices=[[0, "No"], [1, "Sí"]], widget=widgets.RadioSelect)
    control_3 = models.IntegerField(label="Antes del confinamiento (2019), ¿Usted ha consumido cigarrillos?", choices=[[0, "No"], [1, "Sí"]], widget=widgets.RadioSelect)

    def current_field(self):
        return 'question_{}_response'.format(self.quiz_page_counter + 1)

    quiz_incorrect_answer = models.StringField(initial=None)
    quiz_respuesta_incorrecta = models.StringField(initial=None)

    # IP field
    player_ip = models.StringField()
    current_practice_page = models.IntegerField(initial=0)

    '''Quiz'''

    # Counter of the questions answered correctly on the first try
    num_correct = models.IntegerField(initial=0)
    quiz_page_counter = models.IntegerField(initial=0)
    # Inc Attemp per question
    q_incorrect_attempts = models.IntegerField(initial=0)
    q_timeout = models.IntegerField(initial=0)
    q_validation = models.IntegerField(initial=0)
    q_attempts = models.IntegerField(initial=0)
    error_sequence = models.CharField(initial='')
    timeout_sequence = models.CharField(initial='')

    question_1_response = models.IntegerField(verbose_name='', widget=widgets.RadioSelect,
                                              choices=Constants.q1_choices)
    question_2_response = models.IntegerField(verbose_name='', widget=widgets.RadioSelect,
                                              choices=Constants.q2_choices)
    question_3_response = models.IntegerField(verbose_name='', widget=widgets.RadioSelect,
                                              choices=Constants.q3_choices)
    question_4_response = models.IntegerField(verbose_name='', widget=widgets.RadioSelect,
                                              choices=Constants.q4_choices)
    control_formato = models.IntegerField(label="¿Cuál fue el formato de cigarrillos que más compró o prefiere?", widget=widgets.RadioSelect, choices=Constants.format_choices)

    quiz_earnings = models.CurrencyField(initial=0)

    # Hidden Field for detecting bots
    quiz_dec_2 = models.LongStringField(blank=True)
예제 #2
0
class Player(BasePlayer):
    # needed for prelec results.
    information_score = models.FloatField()
    prediction_score = models.FloatField()
    respondent_score = models.FloatField()

    # Question 1
    question = models.IntegerField(
        choices=Constants.likert_choices,
        widget=widgets.RadioSelectHorizontal(),
        verbose_name="This is the question you are after!")

    # Predictions for question 1, one for each likert option
    prediction1 = models.FloatField(
        min=0,
        max=1,
        verbose_name="How likely are others to answer %s?" %
        Constants.likert_choices[0])
    prediction2 = models.FloatField(
        min=0,
        max=1,
        verbose_name="How likely are others to answer %s?" %
        Constants.likert_choices[1])
    prediction3 = models.FloatField(
        min=0,
        max=1,
        verbose_name="How likely are others to answer %s?" %
        Constants.likert_choices[2])
    prediction4 = models.FloatField(
        min=0,
        max=1,
        verbose_name="How likely are others to answer %s?" %
        Constants.likert_choices[3])
예제 #3
0
class Player(BasePlayer):
    typeracer = models.LongStringField(blank=True)
    this_round_point = models.FloatField(initial=0)
    random_num = models.IntegerField(initial=0)
    declare = models.FloatField(min=0)
    fine = models.FloatField(initial=0)
    not_deklarert = models.FloatField(initial=0)
    score_after_taxes = models.FloatField()
    got_audited_score = models.FloatField(initial=0)
    not_audited_score = models.FloatField()
    eq1 = models.IntegerField(label='11 - 7 = ')
    eq2 = models.IntegerField(label='5 * 8 =')
    eq3 = models.IntegerField(label='45 - 30 = ')
    eq4 = models.IntegerField(label='44 + 30 ')
    eq5 = models.IntegerField(label='6 * 6 = ')
    eq6 = models.IntegerField(label='4 + 17 =')
    eq7 = models.IntegerField(label='52 - 30 = ')
    eq8 = models.IntegerField(label='44 - 33 = ')
    eq9 = models.IntegerField(label='90 - 30 = ')
    eq10 = models.IntegerField(label='28 - 11 = ')

    def declare_max(self):
        return self.this_round_point

    def posibility(self):
        import random
        self.random_num = random.randint(1, 100)
예제 #4
0
class Player(BasePlayer):
    typeracer = models.LongStringField(blank=True)
    this_round_point = models.FloatField(initial=0)
    random_num = models.IntegerField(initial=0)
    declare = models.FloatField(min=0)
    fine = models.FloatField(initial=0)
    not_deklarert = models.FloatField(initial=0)
    score_after_taxes = models.FloatField()
    got_audited_score = models.FloatField(initial=0)
    not_audited_score = models.FloatField()
    eq1 = models.IntegerField(label='21-12 =')
    eq2 = models.IntegerField(label='43-15 = ')
    eq3 = models.IntegerField(label='76-20  =')
    eq4 = models.IntegerField(label='90-45 = ')
    eq5 = models.IntegerField(label='22-11 = ')
    eq6 = models.IntegerField(label='61-26 =')
    eq7 = models.IntegerField(label='53-15 =')
    eq8 = models.IntegerField(label='38-22 =')
    eq9 = models.IntegerField(label='15*3 =')
    eq10 = models.IntegerField(label='33 + 36 =')

    def declare_max(self):
        return self.this_round_point

    def posibility(self):
        import random
        self.random_num = random.randint(1, 100)
예제 #5
0
class Player(BasePlayer):
    Red_Probability_guess = models.IntegerField()
    Green_Probability_guess = models.IntegerField()
    Yellow_Probability_guess = models.IntegerField()

    Red_Urn_Given = models.FloatField()
    Yellow_Urn_Given = models.FloatField()
    Green_Urn_Given = models.FloatField()

    isGray = models.IntegerField()  #1 for gray, 0 for not
    Accuracy = models.FloatField()

    #These are the black/white probabilities
    Assigned_Red = models.FloatField()
    Assigned_Yellow = models.FloatField()
    Assigned_Green = models.FloatField()

    isBlackBall = models.IntegerField()

    #point values for the urns
    Red_Points = models.IntegerField()
    Yellow_Points = models.IntegerField()
    Green_Points = models.IntegerField()
    Gray_Points = models.IntegerField()

    def current_data(self):
        return self.session.vars['data'][self.round_number -
                                         1]  #returns a row of the data
예제 #6
0
파일: models.py 프로젝트: Leeps-Lab/ri_cda
class Player(markets_models.Player):
    current_bid = models.ForeignKey(Order, null=True, on_delete=models.CASCADE, related_name="+")
    current_ask = models.ForeignKey(Order, null=True, on_delete=models.CASCADE, related_name="+")

    width = models.IntegerField(initial=100, blank=True)
    cost = models.FloatField(initial=0, blank=True)
    m_low = models.FloatField(initial=0, blank=True)
    m_high = models.FloatField(initial=100, blank=True)
    low_val = models.FloatField(initial=0, blank=True)
    high_val = models.FloatField(initial=100, blank=True)
    round_payoff = models.FloatField(initial=100, blank=True)
    bonds_held = models.IntegerField(initial = 0, blank = True)
    e = models.FloatField(initial = 0, blank = True)
    # allow negative settled
    def check_available(self, is_bid: bool, price: int, volume: int, asset_name: str):
        return True

    def asset_endowment(self):
        return self.subsession.config.asset_endowment

    def cash_endowment(self):
        return 0


    def custom_export(self, players):
        # header row
        print(players.values_list())
        yield ['width', 'cost', 'm_low', 'm_high', 'low_val', 'high_val', 'bid_price', 'bought', 'sold', 'round_payoff', 'bonds_held']
        for p in players:
            yield [p.width, p.bid_price, p.ask_price, p.bought, p.sold, p.round_payoff]
예제 #7
0
class Player(BasePlayer):

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

    othpayoff = models.IntegerField()

    starttime = models.FloatField()

    endtime = models.FloatField()

    conflict = models.PositiveIntegerField(
        choices=[[1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'],
                 [7, '7'], [8, '8'], [9, '9']],
        widget=widgets.RadioSelectHorizontal())

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

    def set_payoff(self):

        points_matrix = {
            'A': {
                'A': Constants.cc,
                'B': Constants.cdrow,
                'C': Constants.cprow
            },
            'B': {
                'A': Constants.dcrow,
                'B': Constants.dd,
                'C': Constants.dprow
            },
            'C': {
                'A': Constants.pcrow,
                'B': Constants.pdrow,
                'C': Constants.pp
            }
        }

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

        self.othpayoff = (
            points_matrix[self.other_player().decision][self.decision])
예제 #8
0
class Player(BasePlayer):
    typeracer = models.LongStringField(blank=True)
    this_round_point = models.FloatField(initial=0)
    random_num = models.IntegerField(initial=0)
    declare = models.FloatField(min=0)
    fine = models.FloatField(initial=0)
    not_deklarert = models.FloatField(initial=0)
    score_after_taxes = models.FloatField()
    got_audited_score = models.FloatField(initial=0)
    not_audited_score = models.FloatField()
    eq1 = models.IntegerField(label='7-5 =')
    eq2 = models.IntegerField(label='33 + 15 =')
    eq3 = models.IntegerField(label='37 + 18 =')
    eq4 = models.IntegerField(label='13-9 =')
    eq5 = models.IntegerField(label='11 + 19 =')
    eq6 = models.IntegerField(label='22+17 =')
    eq7 = models.IntegerField(label='53 + 15 =')
    eq8 = models.IntegerField(label='74 - 22  =')
    eq9 = models.IntegerField(label='7 * 12 = ')
    eq10 = models.IntegerField(label='34 + 21 =')
    def declare_max(self):
        return self.this_round_point
    def posibility(self):
        import random
        self.random_num = random.randint(1,100)
예제 #9
0
파일: models.py 프로젝트: ileppane/otree
class Player(BasePlayer):

    starttime = models.FloatField()
    endtime = models.FloatField()
    decision = models.PositiveIntegerField(choices=[0, 1, 2, 3, 4, 5, 6], widget=widgets.RadioSelect())
    state = models.PositiveIntegerField()
    truestate = models.CharField()
    truedecision = models.CharField()
    check1 = models.PositiveIntegerField(
        choices=[[1, '936'], [2, '364'], [3, '858']], widget=widgets.RadioSelect(), blank=True)
    check2 = models.PositiveIntegerField(
        choices=[[1, '0'], [2, '1/7'], [3, '5/7']], widget=widgets.RadioSelect(), blank=True)
    check3 = models.PositiveIntegerField(
        choices=[[1, '5/7'], [2, '1/7'], [3, '2/7']], widget=widgets.RadioSelect(), blank=True)
    check4 = models.PositiveIntegerField(
        choices=[[1, '1/7'], [2, '0'], [3, '5/7']], widget=widgets.RadioSelect(), blank=True)
    check5 = models.PositiveIntegerField(
        choices=[[1, '£0.11'], [2, '£11.30'], [3, '£1.13']], widget=widgets.RadioSelect(), blank=True)
예제 #10
0
class Player(BasePlayer):
    k = models.IntegerField()
    content = models.StringField()
    believe1 = models.StringField(
        choices=['Sincere', 'Random'],
        widget=widgets.RadioSelect,
        label=
        "Do you believe that your card was a sincere card or a random card? ")
    believe2 = models.StringField(
        choices=['Yes', 'No'],
        widget=widgets.RadioSelect,
        label=
        " After having observed the statement of your card, do you believe that you have performed better than the median?"
    )
    scale1 = models.IntegerField(
        widget=widgets.Slider(attrs={
            'min': '0',
            'max': '10'
        }),
        label="How sure are you? (Rate on a 10-point scale.)")
    scale2 = models.IntegerField(
        widget=widgets.Slider(attrs={
            'min': '0',
            'max': '10'
        }),
        label="How sure are you? (Rate on a 10-point scale.)")
    final_payoff = models.FloatField()

    def set_k(self):
        self.k = random.randint(5, 10)

    def card_content(self):
        if_sincere = numpy.random.choice(numpy.arange(1, 3),
                                         p=[self.k / 10, 1 - self.k / 10
                                            ])  # 1 sincere, 2 random
        if if_sincere == 1:
            return 0  # True message
        else:
            random_true = random.randint(0,
                                         1)  # 0: random false, 1:random true
            if random_true == 0:
                return 1  # False message
            else:
                return 0  # True message

    def get_msg(self):
        if self.participant.vars['median'] <= self.participant.vars[
                'n_correct']:
            return [
                "You performed better than the median",
                "You performed worse than the median "
            ]
        else:
            return [
                "You performed worse than the median ",
                "You performed better than the median"
            ]
예제 #11
0
class DefendToken(Model):
    group = ForeignKey(Group, on_delete='CASCADE')
    number = models.IntegerField()
    map = models.IntegerField(initial=0)
    x = models.FloatField(initial=0)
    y = models.FloatField(initial=0)
    x2 = models.FloatField(initial=0)
    y2 = models.FloatField(initial=0)
    last_updated = models.FloatField(blank=True)
    slot = models.IntegerField(initial=-1)

    def to_dict(self):
        return {
            "number": self.number,
            "map": self.map,
            "x": self.x,
            "y": self.y
        }
예제 #12
0
class Group(BaseGroup):

    alias_assignment = models.StringField
    alias_string = models.StringField
    Red_price = models.FloatField(initial=0.5)
    Green_price = models.FloatField(initial=0.5)

    Michael_index = models.IntegerField(choices=[1, 2, 3])
    Dwight_index = models.IntegerField(choices=[1, 2, 3])
    Jim_index = models.IntegerField(choices=[1, 2, 3])
    role_by_order = models.StringField()

    # New groups keep getting created even when new subsessions are not. dafuq
    def __init__(self, *args, **kwargs):
        BaseGroup.__init__(self, *args, **kwargs)
        np.random.seed(self.id_in_subsession)
        self.alias_assignment = np.random.permutation(Constants.characters)
        self.alias_string = ', '.join(self.alias_assignment)
예제 #13
0
class Group(BaseGroup):
    discussion1 = models.FloatField()

    def live_slider(self, id_in_group, package):
        broadcast = {
            "slider_value": package["slider_value"],
            "disable": package["disable"]
        }
        return {0: broadcast}
예제 #14
0
class Player(BasePlayer):

    round_payoff = models.FloatField()

    def role(self):
        if self.id_in_group == 1:
            return 'A'
        else:
            return 'B'
예제 #15
0
class Player(BasePlayer):
    f_bool = models.BooleanField()
    f_posint = models.IntegerField(min=2)
    f_float = models.FloatField()
    f_currency = models.CurrencyField()
    f_char = models.CharField()

    foo = models.PositiveIntegerField()
    timeout_happened = models.BooleanField(initial=False)
예제 #16
0
class Group(BaseGroup):
    price = models.IntegerField()
    auctionstartdate = models.FloatField()
    auctionenddate = models.FloatField()
    buyer = models.IntegerField()

    def time_left(self):
            now = time.time()
            time_left = self.auctionenddate - now
            time_left = round(time_left) if time_left > 0 else 0
            return time_left

    def set_payoffs(self):
        for p in self.get_players():
            if str(self.buyer) == str(p.id_in_group):
                p.payoff = Constants.endowment - self.price + Constants.prize
            else:
                p.payoff = Constants.endowment
예제 #17
0
class Group(BaseGroup):
    pts = models.FloatField()

    def set_payoffs(self):
        players = self.get_players()
        pts = [p.pts for p in self.group()]

    def other_player(self):
        return self.get_others_in_group()[0]
예제 #18
0
class Player(BasePlayer):
    typeracer = models.LongStringField(blank=True)
    this_round_point = models.FloatField(initial=0)
    random_num = models.IntegerField(initial=0)
    declare = models.FloatField(min=0)
    fine = models.FloatField(initial=0)
    not_deklarert = models.FloatField(initial=0)
    score_after_taxes = models.FloatField()
    got_audited_score = models.FloatField(initial=0)
    not_audited_score = models.FloatField()
    flag1 = models.StringField(choices=[['Spain', 'Spain'],
                                        ['United Kingdom', 'United Kingdom'],
                                        ['Japan', 'Japan'], ['Italy', 'Italy'],
                                        ['Sweden', 'Sweden'],
                                        ['Israel', 'Israel'], ['USA', 'USA']],
                               label='1')
    flag2 = models.StringField(choices=[['Spain', 'Spain'],
                                        ['United Kingdom', 'United Kingdom'],
                                        ['Japan', 'Japan'], ['Italy', 'Italy'],
                                        ['Sweden', 'Sweden'],
                                        ['Israel', 'Israel'], ['USA', 'USA']],
                               label='2. ')
    flag3 = models.StringField(choices=[['Spain', 'Spain'],
                                        ['United Kingdom', 'United Kingdom'],
                                        ['Japan', 'Japan'], ['Italy', 'Italy'],
                                        ['Sweden', 'Sweden'],
                                        ['Israel', 'Israel'], ['USA', 'USA']],
                               label='3. ')
    flag4 = models.StringField(choices=[['Spain', 'Spain'],
                                        ['United Kingdom', 'United Kingdom'],
                                        ['Japan', 'Japan'], ['Italy', 'Italy'],
                                        ['Sweden', 'Sweden'],
                                        ['Israel', 'Israel'], ['USA', 'USA']],
                               label='4. ')
    flag5 = models.StringField(choices=[['Spain', 'Spain'],
                                        ['United Kingdom', 'United Kingdom'],
                                        ['Japan', 'Japan'], ['Italy', 'Italy'],
                                        ['Sweden', 'Sweden'],
                                        ['Israel', 'Israel'], ['USA', 'USA']],
                               label='5.')
    flag6 = models.StringField(choices=[['Spain', 'Spain'],
                                        ['United Kingdom', 'United Kingdom'],
                                        ['Japan', 'Japan'], ['Italy', 'Italy'],
                                        ['Sweden', 'Sweden'],
                                        ['Israel', 'Israel'], ['USA', 'USA']],
                               label='6. ')
    flag7 = models.StringField(choices=[['Spain', 'Spain'],
                                        ['United Kingdom', 'United Kingdom'],
                                        ['Japan', 'Japan'], ['Italy', 'Italy'],
                                        ['Sweden', 'Sweden'],
                                        ['Israel', 'Israel'], ['USA', 'USA']],
                               label='7')

    def declare_max(self):
        return self.this_round_point

    def posibility(self):
        import random
        self.random_num = random.randint(1, 100)
예제 #19
0
파일: models.py 프로젝트: wpears/dimension
class Group(BaseGroup):
    # The group class is used to store market-level data
    mkt_bid_avg = models.FloatField()
    mkt_ask_min = models.IntegerField()
    mkt_ask_max = models.IntegerField()
    mkt_ask_spread = models.IntegerField()
    mkt_ask_stdev_min = models.FloatField()

    def create_contract(self, bid, ask):
        contract = Contract(bid=bid, ask=ask, group=self)
        contract.save()

    def set_marketvars(self):
        # this gets hit after all buyers and sellers have made their choices
        # sellers = Player.objects.filter(group=self, roledesc="Seller")
        # buyers = Player.objects.filter(group=self, roledesc="Buyer")

        contracts = Contract.objects.filter(group=self)

        print("contracts")
        print(contracts)
        print("ask totals")
        print([c.ask.total for c in contracts])

        # Player data
        for contract in contracts:
            seller = contract.ask.player
            buyer = contract.bid.player

            seller.numsold += 1
            seller.payoff += seller.ask_total - Constants.prodcost

            buyer.payoff = Constants.consbenefit - buyer.bid_total

        for player in self.get_players():
            player.payoff_interim = player.payoff + player.participant.payoff

        # Market data
        self.mkt_ask_min = min([c.ask.total for c in contracts])
        self.mkt_ask_max = max([c.ask.total for c in contracts])
        self.mkt_ask_spread = self.mkt_ask_max - self.mkt_ask_min
        self.mkt_bid_avg = float(sum([c.bid.total
                                      for c in contracts])) / len(contracts)
        self.mkt_ask_stdev_min = min([c.ask.stdev for c in contracts])
예제 #20
0
class Player(BasePlayer):
    type = models.FloatField()
    side = models.IntegerField()
    rank = models.IntegerField()
    partner_type = models.FloatField()
    bid = models.FloatField(min=0, max=50)
    late = models.IntegerField()
    points = models.FloatField()

    def initialize_player(self):
        self.type = round(random.uniform(Constants.type_space[0], Constants.type_space[1]),1)
        self.side = 1

    def get_outcome(self):
        me_list = [1, 0, 0, 0, 0, 0]
        side_list = Constants.side_space
        type_list = [round(random.uniform(Constants.type_space[0], Constants.type_space[1]), 1) for _ in range(6)]
        type_list[0] = self.type
        bid_list = [random.uniform(0, 20) for _ in range(6)]
        bid_list[0] = self.bid
        rank_list = [0, 0, 0, 0, 0, 0]
        side1_bids = [bid_list[i] for i in range(6) if side_list[i] == 1]
        side2_bids = [bid_list[i] for i in range(6) if side_list[i] == 2]
        side1_bids.sort(reverse=True)
        side2_bids.sort(reverse=True)
        for b in set(side1_bids):
            rank_set = [i for i, x in enumerate(side1_bids, 1) if x == b]
            for i in range(6):
                if side_list[i] == 1 and bid_list[i] == b:
                    rank_list[i] = rank_set.pop(random.randrange(0, len(rank_set)))
        for b in set(side2_bids):
            rank_set = [i for i, x in enumerate(side2_bids, 1) if x == b]
            for i in range(6):
                if side_list[i] == 2 and bid_list[i] == b:
                    rank_list[i] = rank_set.pop(random.randrange(0, len(rank_set)))
        self.rank = rank_list[0]
        self.participant.vars['practice_data'] = [{"id": me_list[i], "side": side_list[i], "type": type_list[i], "bid": bid_list[i], "rank": rank_list[i]} for i in range(6)]
        self.points = 0 - self.bid
        self.partner_type = 0
        for q in self.participant.vars['practice_data']:
            if self.rank == q['rank'] and self.side != q['side']:
                self.partner_type = q['type']
                self.points = self.type * q['type'] - self.bid
        self.points = round(self.points, 1)
예제 #21
0
class Group(BaseGroup):
    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,
    )

    agent_return_share = models.FloatField(
        choices=Constants.agent_return_share_choices,
        doc="""Agent's share of total return""",
        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.base_pay
        agent.payoff += Constants.base_pay

    def return_share_as_percentage(self):
        return int(self.agent_return_share * 100)
예제 #22
0
파일: models.py 프로젝트: janvavra/wuotree
class Group(BaseGroup):
    winning_demand = models.IntegerField()
    winning_price = models.FloatField()

    def set_payoff(self):
        for p in self.get_players():
            p.check_zero()
            p.set_payoff()

    pass
예제 #23
0
class Player(BasePlayer):
    guess = models.FloatField(min=0, label='')
    winner = models.BooleanField()

    def guess_max(self):
        return self.session.config['endowment']

    def guess_error_message(self, value):
        if str(value)[::-1].find('.') > 3:
            return 'Up to 3 decimal places are allowed'
예제 #24
0
class Player(BasePlayer):

    othpayoff = models.IntegerField()
    starttime = models.FloatField()
    endtime = models.FloatField()
    units = models.PositiveIntegerField(min=1,
                                        max=100,
                                        doc="""Quantity of units to order""")

    qu1 = models.PositiveIntegerField(choices=[86, 70, 40],
                                      widget=widgets.RadioSelect(),
                                      blank=True)
    qu2 = models.PositiveIntegerField(choices=[0, 50, 25],
                                      widget=widgets.RadioSelect(),
                                      blank=True)
    qu3 = models.PositiveIntegerField(choices=[320, 240, 280],
                                      widget=widgets.RadioSelect(),
                                      blank=True)

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

    def set_payoff(self):

        q1 = self.units
        q2 = self.other_player().units
        d = self.group.demand

        if (q1 > q2):
            self.payoff = Constants.price * min(
                d / 2 + max(int(round(0.8 * (d / 2 - q2))), 0),
                q1) - Constants.cost * q1
        else:
            self.payoff = Constants.price * min(d / 2,
                                                q1) - Constants.cost * q1

        if (q2 > q1):
            self.othpayoff = Constants.price * min(
                d / 2 + max(int(round(0.8 * (d / 2 - q1))), 0),
                q2) - Constants.cost * q2
        else:
            self.othpayoff = Constants.price * min(d / 2,
                                                   q2) - Constants.cost * q2
class Player(BasePlayer):
    type = models.FloatField()
    side = models.IntegerField()
    rank = models.IntegerField()
    partner_type = models.FloatField()
    bid = models.FloatField(min=0, max=50)
    late = models.IntegerField()
    points = models.FloatField()
    message = models.IntegerField(choices=[
        [
            1,
            'I agree with the above statement and I pledge to bid 0 in the next rounds.'
        ],
        [
            0,
            'I do not agree with the above statement and I do not pledge to bid 0 in the next rounds.'
        ],
    ],
                                  widget=widgets.RadioSelect)
예제 #26
0
class Subsession(BaseSubsession):
    randnumber = models.FloatField()

    def is_displayed(self):
        return self.player.id_in_group == 1

    def before_session_starts(self):
        for player in self.get_players():
            randnumber2c = random.randint(1, 10)
            player.participant.vars['randnumber2c'] = randnumber2c
예제 #27
0
class Player(BasePlayer):
    treatment = models.CharField(doc="Treatment of each player")
    endowment = models.CurrencyField(
        min=0,
        doc="endowment by each player"
    )
    peers =
    savings = models.CurrencyField(min=0, max=Constants.max_savings, doc="Savings by each player",choices=[c(0), c(2), c(4)])
    financial_reward = models.FloatField(min=0)
    last_savings = models.CurrencyField(initial=0)
예제 #28
0
파일: models.py 프로젝트: manumunoz/8005
class Subsession(BaseSubsession):
    word_points = models.FloatField()

    def creating_session(self):
        if self.round_number == 1:
            self.session.vars['questions'] = Constants.questions

        for i in self.get_players():
            for word in Constants.questions:
                i.participant.vars[word['question']] = []
예제 #29
0
파일: models.py 프로젝트: kutrifd/project
class Player(BasePlayer):
    dump_answer = models.StringField(
        doc='storing svo answers in a string for demo and export purposes')
    mean_ego = models.FloatField()
    mean_alter = models.FloatField()
    svo_angle = models.FloatField()
    svo_type = models.CharField()

    def dumping_answer(self):
        q = self.svo_set.all()
        return [i.to_dump() for i in q]

    def set_svo_angle(self):
        q = self.svo_set.all()
        tot_egos = [i.get_ego_value() for i in q]
        tot_alters = [i.get_alter_value() for i in q]
        self.mean_ego = sum(tot_egos) / len(tot_egos)
        self.mean_alter = sum(tot_alters) / len(tot_alters)
        mean_ego = self.mean_ego - 50
        mean_alter = self.mean_alter - 50
        svo_ratio = mean_alter / mean_ego
        angle_radians = math.atan(svo_ratio)
        self.svo_angle = math.degrees(angle_radians)
        return self.svo_angle

    def set_svo_type(self):
        assert isinstance(self.svo_angle,
                          float), 'Cannot define svo type without svo angle'
        angle = self.svo_angle
        if -70 < angle <= -12.04:
            st = 'Competitive'
        if -12.04 < angle <= 22.45:
            st = 'Individualistic'
        if 22.45 < angle <= 57.15:
            st = 'Prosocial'
        if 57.15 < angle <= 120:
            st = 'Altruist'
        assert st is not None, 'Cannot define the current svo type based on data.'
        self.svo_type = st
        return st

    def unanswered_svo_left(self):
        return self.svo_set.filter(answer__isnull=True).exists()
예제 #30
0
class Player(BasePlayer):
    age = models.FloatField()
    gender = models.StringField()
    religion = models.StringField()
    school_type = models.StringField()
    school_level = models.IntegerField()
    math_skill = models.IntegerField()
    german_skill = models.IntegerField()
    education_mother = models.IntegerField()
    education_father = models.IntegerField()