from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random #doc = """人々がコンコルド効果に陥らず合理的判断をするために効果的な解決策の実験""" class Constants(BaseConstants): name_in_url = 'sunkcost_fallacy1' players_per_group = None num_rounds = 10 instructions_template = 'sunkcost_fallacy1/instructions.html' a_competitive_sales = 750 a_reviced_sales = 1500 investment = 100 class Subsession(BaseSubsession): success = models.IntegerField(min=1, max=10) def creating_session(self): self.session.vars['treatments'] = 50*[1, 2, 3, 4] # 上限50組 if self.round_number == 1: for p in self.get_players(): p.treatment = self.session.vars['treatments'].pop() else: for p in self.get_players(): p.treatment = p.in_round(1).treatment import random random.seed(5) # 乱数シードを5に固定 self.success = random.randint(1, 10) if self.success == self.round_number: for p in self.get_players(): price = Constants.a_reviced_sales p.price = round(price, 0) else: for p in self.get_players(): p.price = Constants.a_competitive_sales class Group(BaseGroup): def set_scores(self): for player in self.get_players(): player.fund = 0 if 'fund' in player.participant.vars: player.fund = player.participant.vars['fund'] for player in self.get_players(): player.expense0 = 0 if 'expense0' in player.participant.vars: player.expense0 = player.participant.vars['expense0'] class Player(BasePlayer): treatment = models.IntegerField(min=1, max=4) a_competitive_sales = models.IntegerField() a_reviced_sales = models.IntegerField() investment = models.IntegerField() price = models.IntegerField(min=750, max=1500) expense0 = models.IntegerField(initial=0) expense1 = models.IntegerField() total_expense = models.IntegerField() bop = models.IntegerField() fund = models.IntegerField(initial=0) capital = models.IntegerField() stop = models.IntegerField() plan = models.StringField( choices=[['0', '0'], ['1', '1'], ['2', '2'], ['3', '3'], ['4', '4'], ['5', '5'], ['6', '6'], ['7', '7'], ['8', '8'], ['9', '9'], ['10', '10']]) improvement_investment = models.BooleanField(choices=[[0, '投資する'], [1, '断念する']]) def balance_of_payments(self): self.expense1 = 0 - Constants.investment * self.round_number self.total_expense = self.expense0 + self.expense1 self.capital = self.fund + self.expense1 self.bop = self.fund + self.expense1 + self.price self.stop = self.bop + Constants.investment