from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'meta_results_old' players_per_group = 6 num_rounds = 1 endowment = c(10) multiplier = 0.5 show_up = c(15) probability = 50 class Subsession(BaseSubsession): pass class Player(BasePlayer): water = models.IntegerField( label="Wie viel Wasser haben Sie während des Experiments ungefähr getrunken?", choices=[ [1, 'keins'], [2, '0-0,25 l'], [3, '0,25-0,5 l'], [4, 'mehr als 0,5 l'], ], ) known_others = models.IntegerField( label="Wie viele der im Raum anwesenden anderen Teilnehmer kennen Sie persönlich?", min=0, max=8, ) known_from = models.IntegerField( blank=True, choices=[ [1, 'Studium'], [2, 'Arbeit'], [3, 'Freizeit'], ], label = "Falls ja, woher kennen Sie sich?" ) exp_own_a_right = models.IntegerField( initial=0 ) exp_own_b_right = models.IntegerField( initial=0 ) exp_other_a_right = models.IntegerField( initial=0 ) exp_other_b_right = models.IntegerField( initial=0 ) exp_right = models.IntegerField( initial=0 ) payoff_extra = models.CurrencyField( initial=0 ) payback_a = models.CurrencyField( initial=0 ) payback_b = models.CurrencyField( initial=0 ) subtract_b = models.CurrencyField( initial=0 ) final_payoff_with_endowment = models.CurrencyField( initial=0 ) def role(self): if self.id_in_group <= 3: return 'subgroup1' else: return 'subgroup2' def set_final(self): self.role=self.participant.vars['role'] self.final_payoff_with_endowment =self.player.payoff + Constants.show_up + self.participant.vars['scl_payoff'] + self.participant.vars['rows_payoff'] self.participant.vars['final_payoff_with_endowment'] = self.final_payoff_with_endowment self.participant.vars['exp_right'] = self.player.exp_right self.participant.vars['payoff_extra'] = 0.5 * (self.player.exp_right) class Group( BaseGroup ): subgroup1_within = models.CurrencyField( initial=0 ) subgroup1_between = models.CurrencyField( initial=0 ) subgroup2_within = models.CurrencyField( initial=0 ) subgroup2_between = models.CurrencyField( initial=0 ) #expectations avg_subgroup1_within = models.CurrencyField( initial=0 ) avg_subgroup1_between = models.CurrencyField( initial=0 ) avg_subgroup2_within = models.CurrencyField( initial=0 ) avg_subgroup2_between = models.CurrencyField( initial=0 ) def set_payoffs(self): for p in self.get_players(): if p.role() == 'subgroup1': self.subgroup1_within += p.participant.vars['contribution_within'] self.avg_subgroup1_within = (self.subgroup1_within - p.participant.vars['contribution_within']) / 2 self.subgroup1_between += p.participant.vars['contribution_between'] self.avg_subgroup1_between = (self.subgroup1_between - p.participant.vars['contribution_between']) / 2 elif p.role() == 'subgroup2': self.subgroup2_within += p.participant.vars['contribution_within'] self.avg_subgroup2_within = (self.subgroup2_within - p.participant.vars['contribution_within']) / 2 self.subgroup2_between += p.participant.vars['contribution_between'] self.avg_subgroup2_between = (self.subgroup2_between - p.participant.vars['contribution_between']) / 2 for p in self.get_players(): if p.role() == 'subgroup1': #expectations if p.participant.vars['exp_own_a'] == round( self.avg_subgroup1_within ): p.exp_own_a_right = 1 if p.participant.vars['exp_own_b'] == round( self.avg_subgroup1_between ): p.exp_own_b_right = 1 if p.participant.vars['exp_other_a'] == round( self.avg_subgroup2_within ): p.exp_other_a_right = 1 if p.participant.vars['exp_other_b'] == round( self.avg_subgroup2_between ): p.exp_other_b_right = 1 elif p.role() == 'subgroup2': if p.participant.vars['exp_own_a'] == round( self.avg_subgroup2_within ): p.exp_own_a_right = 1 if p.participant.vars['exp_own_b'] == round( self.avg_subgroup2_between ): p.exp_own_b_right = 1 if p.participant.vars['exp_other_a'] == round( self.avg_subgroup1_within ): p.exp_other_a_right = 1 if p.participant.vars['exp_other_b'] == round( self.avg_subgroup1_between ): p.exp_other_b_right = 1 for p in self.get_players(): if p.role() == 'subgroup1': p.exp_right = p.exp_own_a_right +p.exp_own_b_right +p.exp_other_a_right +p.exp_other_a_right p.payoff_extra = (p.exp_own_a_right + p.exp_own_b_right + p.exp_other_a_right + p.exp_other_a_right) * 0.5 p.payback_a = Constants.multiplier * self.subgroup1_within p.payback_b = Constants.multiplier * self.subgroup1_between p.subtract_b = - Constants.multiplier * self.subgroup2_between p.payoff = Constants.endowment -p.participant.vars['contribution_between'] - p.participant.vars['contribution_within'] + p.payback_b + p.payback_a +p.subtract_b + p.payoff_extra p.final_payoff_with_endowment = Constants.show_up + p.payoff + p.participant.vars['scl_payoff'] + p.participant.vars['rows_payoff'] elif p.role() == 'subgroup2': p.exp_right = p.exp_own_a_right + p.exp_own_b_right + p.exp_other_a_right + p.exp_other_a_right p.payoff_extra = (p.exp_own_a_right + p.exp_own_b_right + p.exp_other_a_right + p.exp_other_a_right) * 0.5 p.payback_a = Constants.multiplier * self.subgroup2_within p.payback_b = Constants.multiplier * self.subgroup2_between p.subtract_b = - Constants.multiplier * self.subgroup1_between p.payoff = Constants.endowment- p.participant.vars['contribution_between'] - p.participant.vars['contribution_within'] + p.payback_b + p.payback_a + p.subtract_b + p.payoff_extra p.final_payoff_with_endowment = Constants.show_up + p.payoff + p.participant.vars['scl_payoff'] + p.participant.vars['rows_payoff']