from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) author = 'Tobias Regner' doc = """ Crowdfunding """ class Constants(BaseConstants): name_in_url = 'MTurk_Exper' players_per_group = None num_rounds = 1 treatment = 1 market_size = 15 endowment = 15 price = 10 investment = 21 cost = 6 alpha = 7.5 rho = 0.75 # import random # print(random.random()) # p = random.randint(1, 10) # wrong discount = 0.9 delta = 3 role_desc = {'seller': 'S', 'buyer': 'B'} wtp_low = 2 wtp_high = 18 # pledgers = 7 # set to 5 for the time being instructions_template = 'CF_experiment/InstrucOverview.html' instructions_decision = 'CF_experiment/InstrucDecisionSituation.html' class Subsession(BaseSubsession): pass # def before_session_starts(self): # for p in self.get_players(): # p.rng = random.Random(42) # p.pledgers = rng.randint(1, 15) # def creating_session(self): # p3 = models.FloatField( # # wrong # initial=random.randint(1, 10) # ) class Group(BaseGroup): PledgeCap = models.BooleanField() Discount = models.BooleanField() def set_conditions(self): if Constants.treatment == 1: self.PledgeCap = 0 self.Discount = 0 elif Constants.treatment == 2: self.PledgeCap = 1 self.Discount = 0 elif Constants.treatment == 3: self.PledgeCap = 0 self.Discount = 1 elif Constants.treatment == 4: self.PledgeCap = 1 self.Discount = 1 class Player(BasePlayer): import random p2 = models.FloatField( # wrong initial=random.randint(1, 10) ) pledgers = models.IntegerField( # wrong initial=random.randint(6, 16) ) decision_target = models.IntegerField(min=0, max=Constants.market_size, label='Which minimum level of pledging consumers do you set? This can be between 1 and 15.') funding_target = models.IntegerField() campaign_funded = models.BooleanField() # pledgers = models.IntegerField(min=0, max=15) total_amount = models.IntegerField(min=0, max=Constants.endowment) total_costs = models.IntegerField(min=0, max=Constants.endowment) total_profit = models.IntegerField(min=0, max=Constants.endowment) campaign_amount = models.IntegerField(min=0, max=Constants.endowment) consumers_aftermarket = models.FloatField(min=0, max=Constants.endowment) total_aftermarket = models.FloatField(min=0, max=Constants.endowment) profit_aftermarket = models.FloatField(min=0, max=Constants.endowment) costs_aftermarket = models.FloatField(min=0, max=Constants.endowment) decision_production = models.BooleanField(choices=[(0, "produce"), (1, "run")], label='Please choose whether you want to produce or run:', widget=widgets.RadioSelectHorizontal) run_success = models.BooleanField() def set_values(self): self.funding_target = Constants.price * self.decision_target self.total_amount = Constants.price * self.pledgers self.total_costs = Constants.investment + Constants.cost * self.pledgers self.total_profit = self.total_amount - self.total_costs if self.total_amount < self.funding_target: self.campaign_funded = 0 elif self.total_amount >= self.funding_target: self.campaign_funded = 1 if self.campaign_funded == 1: self.consumers_aftermarket = self.pledgers * Constants.rho self.total_aftermarket = self.consumers_aftermarket * Constants.price self.costs_aftermarket = self.consumers_aftermarket * Constants.cost self.profit_aftermarket = self.total_aftermarket - self.costs_aftermarket elif self.campaign_funded == 0: self.total_aftermarket = 0 if Constants.treatment == 1: self.campaign_amount = self.total_amount elif Constants.treatment == 2: self.campaign_amount = self.funding_target if self.p2 > Constants.alpha: self.run_success = 0 elif self.p2 < Constants.alpha: self.run_success = 1 def set_payoffs(self): if self.campaign_funded == 0: self.payoff = 0 elif self.campaign_funded == 1 and self.decision_production == 0: self.payoff = self.total_amount - self.total_costs + self.profit_aftermarket elif self.campaign_funded == 1 and self.decision_production == 1 and self.run_success == 0: self.payoff = 0 elif self.campaign_funded == 1 and self.decision_production == 1 and self.run_success == 1: self.payoff = self.total_amount question1 = models.BooleanField(choices=[(0, "yes"), (1, "no")], label='"As the entrepreneur, can you make a loss if your funding target is higher than your costs?"', widget=widgets.RadioSelectHorizontal) question2 = models.BooleanField(choices=[(0, "right"), (1, "wrong")], label='"If the campaign succeeds, the entrepreneur can make a further profit in the aftermarket."', widget=widgets.RadioSelectHorizontal) question3 = models.BooleanField(choices=[(0, "right"), (1, "wrong")], label='"If the campaign succeeds, the entrepreneur will find out how many consumers pledged (the funding amount)."', widget=widgets.RadioSelectHorizontal) question4 = models.BooleanField(choices=[(0, "right"), (1, "wrong")], label='"If the entrepreneur decides to run, he could make a profit of zero."', widget=widgets.RadioSelectHorizontal) question5 = models.BooleanField(choices=[(0, "right"), (1, "wrong")], label='"If the entrepreneur decides to run, the consumers receive the good anyway."', widget=widgets.RadioSelectHorizontal) question6 = models.BooleanField(choices=[(0, "right"), (1, "wrong")], label='"The entrepreneur can set the price of the good as he wishes."', widget=widgets.RadioSelectHorizontal) survey_easy_difficult = models.IntegerField(choices=[(1, "Very easy"), (2, ""), (3, ""), (4, ""), (5, ""), (6, ""), (7, "Very complicated")], label='Did you find the experiment rather easy or difficult?', widget=widgets.RadioSelectHorizontal) survey_risk = models.IntegerField(choices=[(1, "Very risk averse"), (2, ""), (3, ""), (4, ""), (5, ""), (6, ""), (7, ""), (8, ""), (9, ""), (10, "Very risk seeking")], label='In general, how do you evaluate your own risk preferences?', widget=widgets.RadioSelectHorizontal) age = models.IntegerField(min=18, max=120, label='How old are you?') strategy_e = models.LongStringField(label='Please elaborate on your reasoning behind your funding target choice:') gender = models.IntegerField(choices=[(0, "Male"), (1, "Female"), (2, "Others")], label='Which gender do you identify with?') feedback = models.LongStringField(label='Do you have any further comments on the experiment?')