from otree.api import * c = cu doc = '社会责任型投资意愿的测度:股票报价任务' class Constants(BaseConstants): name_in_url = 'Stock_Quotes' players_per_group = None num_rounds = 1 initial_currency = cu(50) class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): test1 = models.IntegerField(label='您的最终账户余额为多少点') test2 = models.IntegerField(label='您的最终账户余额为多少点') Alipay = models.FloatField(choices=[[1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7']], label='您对支付宝公益平台的信任程度是(1表示很不信任,7表示很信任)', widget=widgets.RadioSelectHorizontal) Alipay2 = models.IntegerField(choices=[[1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7']], label='您认为支付宝公益平台在多大程度上为社会做了贡献(1表示贡献很小,7表示贡献很大)', widget=widgets.RadioSelectHorizontal) SRI_perceptual_validity = models.IntegerField(choices=[[1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7']], label='您认为买到乙股票在多大程度上为社会做了贡献(1表示贡献很小,7表示贡献很大)', widget=widgets.RadioSelectHorizontal) Market_environment = models.IntegerField(choices=[[1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7']], label='您认为目前股票市场的总体走势如何(1表示很差,7表示很好)', widget=widgets.RadioSelectHorizontal) SRI_self = models.IntegerField(choices=[[1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7']], widget=widgets.RadioSelectHorizontal) treatment = models.IntegerField() ESG_success = models.BooleanField() Mundane_success = models.BooleanField() outcome = models.IntegerField(max=1, min=0) revenue = models.IntegerField(max=40, min=10) price = models.IntegerField(max=50, min=0) ESG_fund_quotes = models.IntegerField(label='您对乙股票的报价为多少点(最少为0,最多为1500)', max=1500, min=0) Mundane_fund_quotes = models.IntegerField(label='您对甲股票的报价为多少点(最少为0,最多为1500)', max=1500, min=0) income = models.IntegerField() class Welcome(Page): form_model = 'player' @staticmethod def before_next_page(player, timeout_happened): import random player.treatment = random.choice([1,2,3]) class Quiz(Page): form_model = 'player' form_fields = ['test1', 'test2'] @staticmethod def error_message(player, values): if values['test1'] != 2500: return '回答错误,请重新输入' if values['test2'] != 1500: return '回答错误,请重新输入' class Mundane_fund_quotes(Page): form_model = 'player' form_fields = ['Mundane_fund_quotes'] class ESG_fund_quotes(Page): form_model = 'player' form_fields = ['ESG_fund_quotes'] class Question(Page): form_model = 'player' form_fields = ['Alipay', 'Alipay2', 'SRI_perceptual_validity', 'Market_environment'] @staticmethod def before_next_page(player, timeout_happened): participant = player.participant import random player.price = random.randint(0,1500) player.outcome = random.choice([0,1]) #值为0为社会责任股票,为1为普通股票 player.revenue = random.choice([1500,500]) ESG_fund_quotes = player.ESG_fund_quotes Mundane_fund_quotes = player.Mundane_fund_quotes if ESG_fund_quotes >= player.price: player.ESG_success = True else: player.ESG_success = False if Mundane_fund_quotes >= player.price: player.Mundane_success = True else: player.Mundane_success = False if player.outcome == 0: if player.ESG_success == True: player.income = 1500 - player.price + player.revenue else: player.income = 1500 else: if player.Mundane_success == True: player.income = 1500 - player.price + player.revenue else: player.income = 1500 participant.vars['outcome'] = player.outcome participant.vars['price'] = player.price participant.vars['ESG_fund_quotes'] = player.ESG_fund_quotes participant.vars['Mundane_fund_quotes'] = player.Mundane_fund_quotes participant.vars['ESG_success'] = player.ESG_success participant.vars['Mundane_success'] = player.Mundane_success participant.vars['treatment'] = player.treatment participant.vars['revenue'] = player.revenue participant.vars['income'] = player.income class Test(Page): form_model = 'player' page_sequence = [Welcome, Quiz, Mundane_fund_quotes, ESG_fund_quotes, Question, Test]