from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random class Constants(BaseConstants): name_in_url = 'my_survey' players_per_group = None num_rounds = 5 instructions_template = 'my_survey/instructions.html' income = 5000 purchase_price_of_stock = [300, 400, 500, 600, 700, 800 ] true_price_of_stock = [ 50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000] class Subsession(BaseSubsession): def creating_session( self ): for player in self.get_players(): player.purchase_stock = random.choice(Constants.purchase_price_of_stock) player.true_stock = random.choice(Constants.true_price_of_stock) player.pressure = player.id_in_subsession % 2 class Group(BaseGroup): pass class Player(BasePlayer): income = models.FloatField() stock = models.FloatField() investment_gain = models.FloatField() total_property = models.FloatField() purchase_stock = models.FloatField() true_stock = models.FloatField() total_investment = models.FloatField() pressure = models.BooleanField() invest_point = models.FloatField( label ='' '株を何単位購入しますか?購入しない場合は0を記入してください' '', min = 0) def invest_return(self): if self.invest_point == -1: self.total_investment = 0 * self.purchase_stock self.investment_gain = 0 * self.true_stock self.total_property = self.investment_gain + Constants.income - 3000 else: self.total_investment = self.invest_point * self.purchase_stock self.investment_gain = self.invest_point * self.true_stock self.total_property = self.investment_gain + Constants.income - (self.invest_point * self.purchase_stock)