Exemple #1
0
class FormFieldModel(otree.models.BaseGroup):
    null_boolean = models.BooleanField()
    big_integer = models.BigIntegerField()
    boolean = models.BooleanField(default=False)
    char = models.CharField()
    comma_separated_integer = models.CommaSeparatedIntegerField(max_length=100)
    date = models.DateField()
    date_time = models.DateTimeField()
    alt_date_time = models.DateTimeField(
        widget=otree.forms.SplitDateTimeWidget)
    decimal = models.DecimalField(max_digits=5, decimal_places=2)
    email = models.EmailField()
    file = models.FileField(upload_to='_tmp/uploads')
    file_path = models.FilePathField()
    float = models.FloatField()
    integer = models.IntegerField()
    generic_ip_address = models.GenericIPAddressField()
    positive_integer = models.PositiveIntegerField()
    positive_small_integer = models.PositiveSmallIntegerField()
    slug = models.SlugField()
    small_integer = models.SmallIntegerField()
    text = models.TextField()
    alt_text = models.TextField(widget=otree.forms.TextInput)
    time = models.TimeField()
    url = models.URLField()
    many_to_many = models.ManyToManyField('SimpleModel', related_name='+')
    one_to_one = models.OneToOneField('SimpleModel', related_name='+')

    currency = models.CurrencyField()
    currency_choice = models.CurrencyField(choices=[('0.01',
                                                     '0.01'), ('1.20',
                                                               '1.20')])

    sent_amount = models.CurrencyField(choices=currency_range(0, 0.75, 0.05))
    slider_widget = models.IntegerField(widget=widgets.SliderInput())
Exemple #2
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()
Exemple #3
0
class Player(otree.models.BasePlayer):

    treatment = models.IntegerField(
        doc="The player's treatment; identical to subsession.treatment"
    )

    contribution = models.DecimalField(
        min=0, max=Constants.endowment,
        max_digits=12, decimal_places=2,
        doc="The amount the player contributed for the observed round",
    )

    signal = models.DecimalField(max_digits=12, decimal_places=2,
        doc="The signal observed by the player in given round",
    )
    round_points = models.DecimalField(max_digits=12, decimal_places=2,
        doc="This is the total points (tokens) for the subject for a given round. It includes the points from the public good (one forth of the total points present in the public good plus tokens present in the private account).  Notice that points/payoff for any given round will be materially paid to subjects at the end of the experiment only if the game that includes that round is randomly selected for payment."
    )
    points = models.DecimalField(max_digits=12, decimal_places=2,
        doc="The same as round_points except this only gets populated when the paying_game variable is equal to 1.  The variable is required by the application when determining payouts because only one game is selected for actual subject payment."
    )

    def set_signal_value(self):
        rn = self.subsession.round_number
        vr = self.session.vars['varied_round']
        signalVariance = self.session.config['signalVariance']
        if rn in Constants.starting_rounds or rn in range(vr, vr+Constants.rounds_per_game):
            mpcr = self.group.efficiency_rate
            choicesLeft = [mpcr - Decimal(x*.1) for x in range(1, signalVariance + 1)]
            choicesRight = [mpcr + Decimal(x*.1) for x in range(1, signalVariance + 1)]

            #chop off choices if at the tails
            if mpcr < Decimal(.06):
                choices = choicesRight + [mpcr]
            elif Decimal(.06) < mpcr < Decimal(.16) and signalVariance == 2:
                choices = choicesRight + [mpcr] + choicesLeft[:1]
            elif mpcr > Decimal(1.16):
                choices = choicesLeft + [mpcr]
            elif Decimal(1.06) < mpcr < Decimal(1.16) and signalVariance == 2:
                choices = choicesLeft + [mpcr] + choicesRight[:1]
            else:
                choices = [mpcr] + choicesLeft + choicesRight
            signal = random.choice(choices)
            self.signal = signal.quantize(Decimal('.01'))
        else:
            self.signal = self.in_previous_rounds()[-1].signal

    def get_signal_values(self):
        if self.session.config['signalVariance'] == 2:
            signalVariance = Decimal(.2)
        else:
            signalVariance = Decimal(.1)
        left = self.signal - signalVariance
        right = self.signal + signalVariance
        signals = dict(left=left.quantize(Decimal('.01')), right=right.quantize(Decimal('.01')))
        return signals

    def get_game_info(self):
        for p in self.in_all_rounds():
            if p.subsession.round_number in Constants.starting_rounds:
                info = []
            info.append(p)
        return info

    def get_round_period(self):
        x = 1
        for r in Constants.starting_rounds:
            if self.subsession.round_number in range(r, r+Constants.rounds_per_game):
                game_round = self.subsession.round_number - r
                break
            else:
                x += 1
        game_round += 1
        return [game_round, x]

    def get_game_payoffs(self):
        for p in self.in_all_rounds():
            if p.subsession.round_number in Constants.starting_rounds:
                payoffs = []
            payoffs.append(p.round_points)
        return sum(payoffs)

    def set_session_payoffs(self):
        self.participant.vars['pg_points'] = sum([p.points for p in self.in_all_rounds()])
        self.participant.vars['pg_payoff'] = sum([p.payoff for p in self.in_all_rounds()])
Exemple #4
0
class Group(otree.models.BaseGroup):

    total_contribution = models.DecimalField(max_digits=12, decimal_places=2,
        doc="The aggregate of all member's of a given game's contributions"
    )
    individual_share = models.DecimalField(max_digits=12, decimal_places=2,
        doc="total_contribution divided by 4"
    )

    efficiency_rate = models.DecimalField(max_digits=12, decimal_places=2,
        doc="This is the group's true MPCR"
    )

    def set_efficiency_rate(self):
        #Used for singular MPRC throughout the game
        # Get the MPRCs for each game
        vr = self.session.vars["varied_round"]
        pastMpcrs = []
        fixed_rounds = []
        player = self.get_players()[0]
        for f in player.in_all_rounds():
            # only do this for starting rounds that are to reamin fixed
            if f.subsession.round_number not in range(vr, vr+Constants.rounds_per_game):
                if f.subsession.round_number in Constants.starting_rounds:
                    fixed_rounds.append(f.subsession.round_number)
                    pastMpcrs.append(f.group.efficiency_rate)

        # determine whether to select a new MPCR or use an old one
        if self.subsession.round_number not in range(vr, vr+Constants.rounds_per_game):
            if self.subsession.round_number in fixed_rounds:
                newMpcr = False
                while not newMpcr:
                    number = random.choice(Constants.MPCRS)
                    if pastMpcrs.count(number) < 1:
                        newMpcr = number
            else:
                player = self.get_players()[0]
                newMpcr = player.in_previous_rounds()[-1].group.efficiency_rate

        # Make sure that an MPCR is not getting set in the varied round
        if self.subsession.round_number not in range(vr, vr+Constants.rounds_per_game):
            self.efficiency_rate = newMpcr

    def set_varying_efficiency_rate(self):
        #Used for different efficiency rates throughout game
        vr = self.session.vars['varied_round']
        pastMpcrs = []
        player = self.get_players()[0]
        for f in player.in_all_rounds():
            if f.subsession.round_number in Constants.starting_rounds:
                pastMpcrs = []
            else:
                pastMpcrs.append(f.group.efficiency_rate)
        newMpcr = False
        while not newMpcr:
            number = random.choice(Constants.efficiency_factors)
            if pastMpcrs.count(number) < 2:
                newMpcr = number
        if self.subsession.round_number in range(vr, vr+Constants.rounds_per_game):
            self.efficiency_rate = newMpcr

    def set_payoffs(self):
        # add some logic here to add up contributions
        # from rounds 1-10, 11-20, 21-30
        x = self.session.vars['paying_round']
        self.total_contribution = sum([p.contribution for p in self.get_players()])
        self.individual_share = self.total_contribution * self.efficiency_rate
        for p in self.get_players():
            p.round_points = (Constants.endowment - p.contribution) + self.individual_share
            if x <= self.subsession.round_number <= x + 7:
                p.payoff = p.round_points * self.session.real_world_currency_per_point
                p.points = p.round_points
            else:
                p.points = 0
                p.payoff = 0

    def set_game_payoffs(self):
        for p in self.get_players():
            p.set_session_payoffs()
Exemple #5
0
class Player(BasePlayer):
    def set_payoff(self):
        """Calculate payoff, which is zero for the survey"""
        self.payoff = 0

    q_risk1 = models.PositiveIntegerField(
        initial=None,
        choices=[[1, 'A 50% chance of $35'], [2, 'A 100% chance of $15']],
        verbose_name=
        'Hypothetically, which would you prefer: a 50% chance of getting $35 or a 100% chance of getting $15?',
        widget=widgets.RadioSelect())
    q_risk2 = models.CharField(
        initial=None,
        choices=['A 50% chance of $35', 'A 100% chance of $17.50'],
        verbose_name=
        'Hypothetically, which would you prefer: a 50% chance of getting $35 or a 100% chance of getting $17.50?',
        widget=widgets.RadioSelect())
    q_risk3 = models.CharField(
        initial=None,
        choices=['A 50% chance of $35', 'A 100% chance of $10'],
        verbose_name=
        'Hypothetically, which would you prefer: a 50% chance of getting $35 or a 100% chance of getting $10?',
        widget=widgets.RadioSelect())
    q_risk4 = models.CharField(
        initial=None,
        choices=[
            '1. Not at all willing to take risks', '2', '3', '4',
            '5. Very willing to take risks'
        ],
        verbose_name=
        'How willing are you to take risks in your life, in general?',
        widget=widgets.RadioSelect())

    q_subjNum1 = models.CharField(
        initial=None,
        choices=[
            '1. Not at all good', '2', '3', '4', '5', '6. Extremely good'
        ],
        verbose_name='How good are you at working with fractions?',
        widget=widgets.RadioSelect())
    q_subjNum2 = models.CharField(
        initial=None,
        choices=[
            '1. Not at all good', '2', '3', '4', '5', '6. Extremely good'
        ],
        verbose_name='How good are you at working with percentages?',
        widget=widgets.RadioSelect())
    q_subjNum3 = models.CharField(
        initial=None,
        choices=[
            '1. Not at all good', '2', '3', '4', '5', '6. Extremely good'
        ],
        verbose_name='How good are you at calculating a 15% tip?',
        widget=widgets.RadioSelect())
    q_subjNum4 = models.CharField(
        initial=None,
        choices=[
            '1. Not at all good', '2', '3', '4', '5', '6. Extremely good'
        ],
        verbose_name=
        'How good are you at figuring out how much a shirt will cost if it is 25% off?',
        widget=widgets.RadioSelect())
    q_subjNum5 = models.CharField(
        initial=None,
        choices=['1. Not at all', '2', '3', '4', '5', '6. Extremely'],
        verbose_name=
        'When reading the newspaper, how helpful do you find tables and graphs that are parts of a story?',
        widget=widgets.RadioSelect())
    q_subjNum6 = models.CharField(
        initial=None,
        choices=[
            '1. Always prefer words', '2', '3', '4', '5',
            '6. Always prefer numbers'
        ],
        verbose_name=
        'When people tell you the chance of something happening, do you prefer that they use words ("it rarely happens") or numbers ("there\'s a 1% chance")?',
        widget=widgets.RadioSelect())
    q_subjNum7 = models.CharField(
        initial=None,
        choices=[
            '1. Always prefer percentages', '2', '3', '4', '5',
            '6. Always prefer words'
        ],
        verbose_name=
        'When you hear a weather forecast, do you prefer predictions using percentages (e.g., "there will be a 20% chance of rain today") or predictions using only words (e.g., "there is a small chance of rain today")?',
        widget=widgets.RadioSelect())
    q_subjNum8 = models.CharField(
        initial=None,
        choices=['1. Never', '2', '3', '4', '5', '6. Very often'],
        verbose_name=
        'How often do you find numerical information to be useful?',
        widget=widgets.RadioSelect())

    q_objNum1 = models.PositiveIntegerField(
        verbose_name=
        'Imagine that we have a fair, 6-sided die (for example, from a board game or a casino craps table).  Imagine we now roll it 1000 times.  Out of 1000 rolls, how many times do you think the die would come up even (numbers 2, 4, or 6)?',
        min=0,
        max=10000,
        initial=None)
    q_objNum2 = models.PositiveIntegerField(
        verbose_name=
        'In the Big Bucks Lottery, the chance of winning a $10.00 prize is 1%.  What is your best guess about how many people would win a $10.00 prize if 1000 people each buy a single ticket to Big Bucks?',
        min=0,
        max=10000,
        initial=None)
    q_objNum3 = models.DecimalField(
        verbose_name=
        'In the Acme Publishing Sweepstakes, the chance of winning a car is 1 in 1000.  What percentage of tickets to Acme Publishing Sweepstakes win a car?',
        max=10000,
        max_digits=5,
        decimal_places=3,
        initial=None)

    q_nfc1 = models.PositiveIntegerField(
        initial=None,
        choices=Constants.nfc_responses,
        verbose_name='I would prefer complex to simple problems.',
        widget=widgets.RadioSelect())
    q_nfc2 = models.PositiveIntegerField(
        initial=None,
        choices=Constants.nfc_responses,
        verbose_name=
        'I like to have the responsibility of handling a situation that requires a lot of thinking.',
        widget=widgets.RadioSelect())
    q_nfc3 = models.PositiveIntegerField(
        initial=None,
        choices=Constants.nfc_responses,
        verbose_name='Thinking is not my idea of fun.',
        widget=widgets.RadioSelect())
    q_nfc4 = models.PositiveIntegerField(
        initial=None,
        choices=Constants.nfc_responses,
        verbose_name=
        'I would rather do something that requires little thought than something that is sure to challenge my thinking abilities.',
        widget=widgets.RadioSelect())
    q_nfc5 = models.PositiveIntegerField(
        initial=None,
        choices=Constants.nfc_responses,
        verbose_name=
        'I find satisfaction in deliberating hard and for long hours.',
        widget=widgets.RadioSelect())
    q_nfc6 = models.PositiveIntegerField(
        initial=None,
        choices=Constants.nfc_responses,
        verbose_name='I only think as hard as I have to.',
        widget=widgets.RadioSelect())
    q_nfc7 = models.PositiveIntegerField(
        initial=None,
        choices=Constants.nfc_responses,
        verbose_name='I prefer my life to be filled with puzzles I must solve.',
        widget=widgets.RadioSelect())
    q_nfc8 = models.PositiveIntegerField(
        initial=None,
        choices=Constants.nfc_responses,
        verbose_name=
        'I feel relief rather than satisfaction after completing a task that requires a lot of mental effort.',
        widget=widgets.RadioSelect())

    q_experience = models.CharField(
        initial=None,
        choices=['0', '1 to 3', '4 to 6', '7 to 9', '10 or more'],
        verbose_name=
        'Approximately how many in-person, laboratory experiments have you completed before today?  If you\'re not sure, please make your best guess.',
        widget=widgets.RadioSelect())
    q_english = models.CharField(
        initial=None,
        choices=['Yes', 'No', 'Prefer not to answer'],
        verbose_name='Is English your primary language?',
        widget=widgets.RadioSelect())
    q_gender = models.CharField(initial=None,
                                choices=['Male', 'Female'],
                                verbose_name='What is your gender?',
                                widget=widgets.RadioSelect())
    q_age = models.PositiveIntegerField(
        verbose_name='How old are you, in years?',
        min=16,
        max=120,
        initial=None)

    q_course_micro = models.BooleanField()
    q_course_mkt = models.BooleanField()
    q_course_law = models.BooleanField()

    q_futureStudies = models.CharField(
        initial=None,
        choices=[
            'Yes, I would like to be contacted for future studies',
            'No, I would not like to be contacted for future studies'
        ],
        verbose_name=
        'Researchers conducting this study may be interested in contacting you regarding additional research studies in the next year.  These future studies will provide compensation of approximately $35/hour.  Please indicate whether you would like us to contact you for these studies.  Doing so will not affect any aspect of your participation today, including payment or privacy.',
        widget=widgets.RadioSelect())