from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) author = 'Kevin Trutmann' doc = """ This App shows the final payoff for the Dynamic investment task. It is based on the 'Payoff_Bubble_Market' app and may thus still contain some unnecessary code. """ class Constants(BaseConstants): name_in_url = 'payoff_investment_task' players_per_group = None num_rounds = 1 payoff_names_now = { # Contains the dict keys for all apps and the names to be displayed 'Investment_dynamic_payoff': 'Investment-Aufgabe' } class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): final_payoff_inv_task = models.CurrencyField() # What they earned from the inv. task final_payoff_this_block = models.CurrencyField() # What has to be payed out donation = models.FloatField(min=0) money_kept = models.FloatField() # All that was not donated. fMRI_interest = models.BooleanField(choices=[(True, 'Ja, ich bin interessiert'), (False, 'Nein, ich möchte nicht teilnehmen')], label='', widget=widgets.RadioSelect) def calculate_all_payoffs(self): # Fist handle the donation: self.money_kept = float(self.session.config['participation_fee']) - self.donation self.final_payoff_this_block = self.participant.vars['Investment_dynamic_payoff'] *\ self.session.config['real_world_currency_per_point'] +\ self.money_kept # TODO: Test if displayed and saved correctly! # If this is the last block, add the completion fee: if self.participant.vars['study_block_nr'] == 5: self.final_payoff_this_block = float(self.final_payoff_this_block + self.session.config['completion_fee']) self.final_payoff_inv_task = self.participant.vars['Investment_dynamic_payoff'] self.participant.vars['final_payoff_now_dict'] =\ {'Investment_dynamic_payoff': int(self.participant.vars['Investment_dynamic_payoff'])} def create_display_lists(self): # This can then be iterated over on the page to create the tables now_list = zip([Constants.payoff_names_now[this_key] for this_key in self.participant.vars['final_payoff_now_dict'].keys()], [int(round(i)) if i is not None else '-' for i in self.participant.vars['final_payoff_now_dict'].values()]) return now_list