from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random author = 'Laura Hueber' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'SecondDate' players_per_group = None num_rounds = 10 endowment = 200 # -------------------------------------------------------------------------------------------------------------------- # # -------------------------------------------------------------------------------------------------------------------- # # -------------------------------------------------------------------------------------------------------------------- # class Subsession(BaseSubsession): pass # -------------------------------------------------------------------------------------------------------------------- # class Group(BaseGroup): pass # -------------------------------------------------------------------------------------------------------------------- # class Player(BasePlayer): amount_invested = models.FloatField() draw_lottery = models.StringField() lottery_outcomeH = models.StringField() draw_lottery1 = models.StringField() draw_lottery2 = models.StringField() draw_lottery3 = models.StringField() draw_lottery4 = models.StringField() draw_lottery5 = models.StringField() draw_lottery6 = models.StringField() draw_lottery7 = models.StringField() draw_lottery8 = models.StringField() draw_lottery9 = models.StringField() lottery_outcomeL1 = models.StringField() lottery_outcomeL2 = models.StringField() lottery_outcomeL3 = models.StringField() lottery_outcomeL4 = models.StringField() lottery_outcomeL5 = models.StringField() lottery_outcomeL6 = models.StringField() lottery_outcomeL7 = models.StringField() lottery_outcomeL8 = models.StringField() lottery_outcomeL9 = models.StringField() lottery_realization1 = models.FloatField() lottery_realization2 = models.FloatField() lottery_realization3 = models.FloatField() lottery_realization4 = models.FloatField() lottery_realization5 = models.FloatField() lottery_realization6 = models.FloatField() lottery_realization7 = models.FloatField() lottery_realization8 = models.FloatField() lottery_realization9 = models.FloatField() sum_lottery_realization123 = models.FloatField() sum_lottery_realization456 = models.FloatField() sum_lottery_realization789 = models.FloatField() periodic_payout_lottery = models.FloatField() risk_general = models.IntegerField() risk_finance = models.IntegerField() perception_risk = models.IntegerField() perception_loss = models.IntegerField() worry_loss = models.IntegerField() great_loss = models.IntegerField() understanding_risk = models.IntegerField() understanding_risk2 = models.IntegerField() understanding_risk3 = models.IntegerField() understanding_risk4 = models.IntegerField() understanding_risk5 = models.IntegerField() understanding_risk6 = models.IntegerField() perceived_prob_loss = models.FloatField() perceived_prob_win = models.FloatField() satisfaction_risk = models.IntegerField() age = models.FloatField() gender = models.IntegerField() education = models.StringField() study = models.IntegerField() email = models.StringField() email2 = models.StringField() investment = models.IntegerField() payoffSecondDate = models.FloatField() payoff_help = models.FloatField() comments = models.LongStringField(blank=True) def random_draw_lottery(self): if self.participant.vars['subtreatment'] == 'H': draw_lotteries = ['x', 'x', 'y'] self.draw_lottery = random.choice(draw_lotteries) # ------------------------determine periodic payout from lottery for treatment baseLF and baseFL---------------- if self.participant.vars['subtreatment'] == 'H': if self.draw_lottery == 'x': self.periodic_payout_lottery = Constants.endowment - self.amount_invested elif self.draw_lottery == 'y': self.periodic_payout_lottery = Constants.endowment + (self.amount_invested * 2.5) print('draw_lotteryH', self.draw_lottery) if self.draw_lottery == 'x': self.lottery_outcomeH = 'Verloren' elif self.draw_lottery == 'y': self.lottery_outcomeH = 'Gewonnen' print('lottery_outcomeH', self.lottery_outcomeH) # -------------------------determine periodic payout from lottery for treatmnent debiasingLF and debiasingFL---- elif self.participant.vars['subtreatment'] == 'L': if self.round_number == 1: if self.in_round(1).sum_lottery_realization123 == 0: self.periodic_payout_lottery = Constants.endowment * 3 - (3 * self.in_round(1).amount_invested) if self.in_round(1).sum_lottery_realization123 == 2.5: self.periodic_payout_lottery = Constants.endowment * 3 - (2 * self.in_round(1).amount_invested) + \ (2.5 * self.in_round(1).amount_invested) if self.in_round(1).sum_lottery_realization123 == 5: self.periodic_payout_lottery = Constants.endowment * 3 - self.in_round(1).amount_invested + \ (2.5 * 2 * self.in_round(1).amount_invested) if self.in_round(1).sum_lottery_realization123 == 7.5: self.periodic_payout_lottery = Constants.endowment * 3 + ( 2.5 * 3 * self.in_round(1).amount_invested) # ---------------------------------------------------------------------------------------------------------- if self.round_number == 4: if self.in_round(1).sum_lottery_realization456 == 0: self.periodic_payout_lottery = Constants.endowment * 3 - (3 * self.in_round(4).amount_invested) if self.in_round(1).sum_lottery_realization456 == 2.5: self.periodic_payout_lottery = Constants.endowment * 3 - (2 * self.in_round(4).amount_invested) + \ (2.5 * self.in_round(4).amount_invested) if self.in_round(1).sum_lottery_realization456 == 5: self.periodic_payout_lottery = Constants.endowment * 3 - self.in_round(4).amount_invested + \ (2.5 * 2 * self.in_round(4).amount_invested) if self.in_round(1).sum_lottery_realization456 == 7.5: self.periodic_payout_lottery = Constants.endowment * 3 + ( 2.5 * 3 * self.in_round(4).amount_invested) # ---------------------------------------------------------------------------------------------------------- if self.round_number == 7: if self.in_round(1).sum_lottery_realization789 == 0: self.periodic_payout_lottery = Constants.endowment * 3 - (3 * self.in_round(7).amount_invested) if self.in_round(1).sum_lottery_realization789 == 2.5: self.periodic_payout_lottery = Constants.endowment * 3 - (2 * self.in_round(7).amount_invested) + \ (2.5 * self.in_round(7).amount_invested) if self.in_round(1).sum_lottery_realization789 == 5: self.periodic_payout_lottery = Constants.endowment * 3 - self.in_round(7).amount_invested + \ (2.5 * 2 * self.in_round(7).amount_invested) if self.in_round(1).sum_lottery_realization789 == 7.5: self.periodic_payout_lottery = Constants.endowment * 3 + ( 2.5 * 3 * self.in_round(7).amount_invested) # ------------------------------------------------------------------------------------------------------------------ def control_payoff(self): if self.round_number == 9: print('periodic_payout_lottery1', self.in_round(1).periodic_payout_lottery) print('periodic_payout_lottery2', self.in_round(2).periodic_payout_lottery) print('periodic_payout_lottery3', self.in_round(3).periodic_payout_lottery) print('periodic_payout_lottery4', self.in_round(4).periodic_payout_lottery) print('periodic_payout_lottery5', self.in_round(5).periodic_payout_lottery) print('periodic_payout_lottery6', self.in_round(6).periodic_payout_lottery) print('periodic_payout_lottery7', self.in_round(7).periodic_payout_lottery) print('periodic_payout_lottery8', self.in_round(8).periodic_payout_lottery) print('periodic_payout_lottery9', self.in_round(9).periodic_payout_lottery) print('payoffSecondDate', self.payoffSecondDate) print('player_playoff_help', self.payoff_help) print('payoff', self.payoff) # ------------------------------------------------------------------------------------------------------------------ def calculate_payoff(self): if self.round_number == 7: self.payoffSecondDate = self.in_round(1).periodic_payout_lottery + \ self.in_round(4).periodic_payout_lottery + \ self.in_round(7).periodic_payout_lottery self.payoff_help = (self.in_round(1).periodic_payout_lottery + self.in_round(4).periodic_payout_lottery + self.in_round(7).periodic_payout_lottery) / 400 self.payoff = round((self.payoff_help * 2) + 0.0001) / 2 print('periodic_payout_lottery1', self.in_round(1).periodic_payout_lottery) print('periodic_payout_lottery4', self.in_round(4).periodic_payout_lottery) print('periodic_payout_lottery7', self.in_round(7).periodic_payout_lottery) print('payoffSecondDate', self.payoffSecondDate) print('payoff_help', self.payoff_help, ) print('payoff', self.payoff)