import datetime from django.forms import fields from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) from django import forms doc = "" class Constants(BaseConstants): name_in_url = "my_survey" players_per_group = None num_rounds = 1 instructions_template = 'my_survey/instructions.html' payments = tuple([ c(0.01*100), c(0.02*100), c(0.11*100), c(0.07*100), c(0.06*100), c(0.1*100), c(0.08*100), c(0.20*100), c(0.15*100), c(0.19*100), ]) payment_tot = sum(payments) factor = 0.1 start = 9 import random class Subsession(BaseSubsession): def creating_session(self): import itertools colors = itertools.cycle(['yellow', 'orange', 'black', 'white', 'red', 'green']) for p in self.get_players(): p.color = next(colors) class Group(BaseGroup): pass class Player(BasePlayer): def beliefs(self): return [ self.belief0, self.belief1, self.belief2, self.belief3, self.belief4, self.belief5, self.belief6, self.belief7, self.belief8, self.belief9, ] def set_payoff(self): print("in set_payoff") beliefs = self.beliefs() self.total_belief = sum(beliefs) self.payoff = c(9) if self.total_belief != Constants.payment_tot: for i in range(len(beliefs)): self.payoff -= 0.1*abs(beliefs[i] - Constants.payments[i]) if self.payoff < c(1.00): self.payoff = c(1.00) charity = models.CurrencyField(choices=currency_range(c(0), c(1.00), c(0.10))) def some_method(self): self.random_bonus = c(random.randint(1,10)) color = models.StringField() submit = models.StringField() total_belief = models.DecimalField(min=0, max=1, decimal_places=2, max_digits=5) contribution = models.CurrencyField() outcome = models.IntegerField( # blank = True, min = 0, label = "" , ) HEXACO1 = models.IntegerField(choices=[1, 2, 3, 4, 5], label="I wouldn't use flattery to get a " "raise or promotion at work.", widget=widgets.RadioSelectHorizontal) HEXACO2 = models.IntegerField(choices=[1, 2, 3, 4, 5], label="If I knew that I could never get " "caught, I would be willing to steal a " "million dollars.", widget=widgets.RadioSelectHorizontal) HEXACO3 = models.IntegerField(choices=[1, 2, 3, 4, 5], label="Having a lot of money is not " "especially important to me.", widget=widgets.RadioSelectHorizontal) HEXACO4 = models.IntegerField(choices=[1, 2, 3, 4, 5], label="I think that I am entitled to more " "respect than the average person is.", widget=widgets.RadioSelectHorizontal) HEXACO5 = models.IntegerField(choices=[1, 2, 3, 4, 5], label="If I want something from someone, I " "will laugh at that person's worst jokes.", widget=widgets.RadioSelectHorizontal) HEXACO6 = models.IntegerField(choices=[1, 2, 3, 4, 5], label="I would get a lot of pleasure from " "owning expensive luxury goods.", widget=widgets.RadioSelectHorizontal) HEXACO7 = models.IntegerField(choices=[1, 2, 3, 4, 5], label="I want people to know that I am an " "important person of high status.", widget=widgets.RadioSelectHorizontal) HEXACO8 = models.IntegerField(choices=[1, 2, 3, 4, 5], label="I wouldn't pretend to like someone " "just to get that person to do favors for me.", widget=widgets.RadioSelectHorizontal) HEXACO9 = models.IntegerField(choices=[1, 2, 3, 4, 5], label="I wouldn't pretend to like someone " "just to get that person to do favors for me.", widget=widgets.RadioSelectHorizontal) HEXACO10 = models.IntegerField(choices=[1, 2, 3, 4, 5], label="I'd be tempted to use counterfeit " "money, if I were sure I could get away with it.", widget=widgets.RadioSelectHorizontal) startTime = models.LongStringField() endTime = models.LongStringField() seconds = models.LongStringField() timenow = models.LongStringField() greed1 = models.IntegerField(choices=[1, 2, 3, 4, 5], label="I always want more.", widget=widgets.RadioSelectHorizontal) greed2 = models.IntegerField(choices=[1, 2, 3, 4, 5], label="Actually, I'm kind of greedy.", widget=widgets.RadioSelectHorizontal) greed3 = models.IntegerField(choices=[1, 2, 3, 4, 5], label="One can never have too much money.", widget=widgets.RadioSelectHorizontal) greed4 = models.IntegerField(choices=[1, 2, 3, 4, 5], label="As soon as I have acquired something. I start to " "think about the next thing I want.", widget=widgets.RadioSelectHorizontal) greed5 = models.IntegerField(choices=[1, 2, 3, 4, 5], label="It doesn't matter how much I have. I'm never " "completely satisfied.", widget=widgets.RadioSelectHorizontal) greed6 = models.IntegerField(choices=[1, 2, 3, 4, 5], label="My life motto is 'more is better'.", widget=widgets.RadioSelectHorizontal) greed7 = models.IntegerField(choices=[1, 2, 3, 4, 5], label="I can't imagine having too many things.", widget=widgets.RadioSelectHorizontal) belief0 = models.IntegerField(label="What percentage of participants received a payment of 0?", min=0, max=100) belief1 = models.IntegerField(label="What percentage of participants received a payment of 1?", min=0, max=100) belief2 = models.IntegerField(label="What percentage of participants received a payment of 2?", min=0, max=100) belief3 = models.IntegerField(label="What percentage of participants received a payment of 3?", min=0, max=100) belief4 = models.IntegerField(label="What percentage of participants received a payment of 4?", min=0, max=100) belief5 = models.IntegerField(label="What percentage of participants received a payment of 5?", min=0, max=100) belief6 = models.IntegerField(label="What percentage of participants received a payment of 6?", min=0, max=100) belief7 = models.IntegerField(label="What percentage of participants received a payment of 7?", min=0, max=100) belief8 = models.IntegerField(label="What percentage of participants received a payment of 8?", min=0, max=100) belief9 = models.IntegerField(label="What percentage of participants received a payment of 9?", min=0, max=100) confidence = models.IntegerField(choices=[1, 2, 3, 4, 5], label="How sure are you about your assessment?", widget=widgets.RadioSelectHorizontal)