from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) author = 'Immo' doc = """ Gift Exchange """ class Constants(BaseConstants): name_in_url = 'gift_exchange' players_per_group = 2 num_rounds = 1 endowment = c(80) wage_options = currency_range(10, 20, 10) wage_options_count = len(wage_options) effort_options = [ [percent / 100.0, '{}%'.format(percent)] for percent in range(10, 100 + 1, 10)] EFFORT_TO_COST = { 0.1: 0, 0.2: 1, 0.3: 2, 0.4: 3, 0.5: 4, 0.6: 6, 0.7: 8, 0.8: 10, 0.9: 12, 1: 15} def cost_from_effort(effort): return c(Constants.EFFORT_TO_COST[effort]) class Subsession(BaseSubsession): pass def make_field(amount): return models.FloatField( choices = Constants.effort_options, label = 'Falls dein Manager dir einen Lohn von {} zahlt, wie hoch ist dein Anstrengungsniveau?'.format(c(amount)) ) class Group(BaseGroup): wage = models.CurrencyField( choices = Constants.wage_options, widget = widgets.RadioSelectHorizontal ) work_effort = models.FloatField() effort_cost = models.CurrencyField() response_10 = make_field(10) response_20 = make_field(20) def set_payoffs(self): p1 = self.get_player_by_id(1) p2 = self.get_player_by_id(2) self.work_effort = getattr(self, 'response_{}'.format( int(self.wage))) self.effort_cost = cost_from_effort(self.work_effort) p1.payoff = (Constants.endowment - self.wage) * self.work_effort p2.payoff = self.wage - self.effort_cost class Player(BasePlayer): mq1 = models.CurrencyField( label = 'Wenn du deinem Mitarbeiter 20€ bezahlst und er ein Anstrengungsniveau von 0.3 impliziert, wie hoch ist deine Auszahlung?' ) def mq1_error_message(self, value): print ('value is', value) if value != c(18): return 'Versuche es bitte nochmal! Solltest du Hilfe benötigen, melde dich bitte.' mq2 = models.CurrencyField( label = 'Wenn du einen Lohn von 10€ wählst und dein Mitarbeiter ein Anstrengungsniveau von 0.5 impliziert, wie hoch ist deine Auszahlung?' ) def mq2_error_message(self, value): print ('value is', value) if value != c(35): return 'Versuche es bitte nochmal! Solltest du Hilfe benötigen, melde dich bitte.' eq1 = models.CurrencyField( label = 'Du bekommst einen Lohn von 10€, wie hoch ist deine Auszahlung, wenn du ein Anstrengungsniveau von 0.2 implizierst?' ) def eq1_error_message(self, value): print ('value is', value) if value != c(9): return 'Versuche es bitte nochmal! Solltest du Hilfe benötigen, melde dich bitte.' eq2 = models.CurrencyField( label = 'Du bekommst einen Lohn von 20€, wie hoch ist deine Auszahlung, wenn du ein Anstrengungsniveau von 0.7 implizierst?' ) def eq2_error_message(self, value): print ('value is', value) if value != c(12): return 'Versuche es bitte nochmal! Solltest du Hilfe benötigen, melde dich bitte.'