from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import pandas as pd import random as rd from datetime import datetime author = 'Kevin Trutmann' doc = """ App to show the MTurk workers what they earned when. """ class Constants(BaseConstants): name_in_url = 'results' num_rounds = 1 players_per_group = None POINTS_PER_WIN = c(8500) # How many points are the "bounty" in the beauty contest? beauty_group_size = 100 # How many players will enter the contest in the group condition? class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): general_comments = models.LongStringField(label='', blank=True) computer_winner = models.BooleanField() computer_23mean = models.FloatField() winner_game = models.StringField() earned_by_game = models.CurrencyField() payoff_date = models.StringField() payoff_time_days_delay = models.StringField() money_now = models.FloatField() points_later = models.FloatField() money_later = models.FloatField() def calculate_payoff(self): self.earned_by_game = 0 # First decide which game to pay out: winner_game_ix = rd.sample(range(3), 1)[0] self.winner_game = ['computer', 'dyad', 'group'][winner_game_ix] # The computer response: if self.winner_game == 'computer': self.computer_23mean = self.participant.vars['computer_submission'] / 3 if self.participant.vars['computer_submission'] == 0: self.computer_winner = rd.random() < .5 self.earned_by_game = Constants.POINTS_PER_WIN else: self.computer_winner = False self.payoff = self.earned_by_game # The MPL stuff: self.payoff_date = str(datetime.strptime(self.participant.vars['timepref_pat_mpl_payout_day'], '%Y-%m-%d').date()) self.payoff_time_days_delay = str(self.participant.vars['timepref_pat_mpl_delay_days']) self.money_now = float(self.participant.payoff_plus_participation_fee()) self.points_later = int(self.participant.vars['mpl_pat_pot_payoff']) self.money_later = float(self.participant.vars['mpl_pat_pot_payoff'] * self.session.config['real_world_currency_per_point'])