from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random from django.forms.widgets import NumberInput import pandas as pd import numpy doc = """ One player decides how to divide a certain amount between himself and the other player. See: Kahneman, Daniel, Jack L. Knetsch, and Richard H. Thaler. "Fairness and the assumptions of economics." Journal of business (1986): S285-S300. """ class Constants(BaseConstants): name_in_url = 'recipient' players_per_group = None num_rounds = 1 instructions_template = 'dictator/Instructions.html' # Initial amount allocated to the dictator endowment = c(12.5) data_given = pd.read_csv("recipient/giver_data.csv", sep = ";") data_given_dict = data_given.to_dict(orient='records') class Subsession(BaseSubsession): #def creating_session(self): #print(Constants.data_given) def creating_session(self): data_given = pd.read_csv("recipient/giver_data.csv", sep=";") print(data_given) print(data_given['given'].sample(n = 1)) for p in self.get_players(): p.points_allocated_by_giver = int(data_given.at[(p.id_in_group-1),'given']) p.giver_condition = str(data_given.at[(p.id_in_group-1),'condition']) p.giver_P_ID = str(data_given.at[(p.id_in_group - 1), 'dictator_P_ID']) class Group(BaseGroup): pass class Player(BasePlayer): consent = models.IntegerField( label='Consent declaration:', initial=None, choices=[ [1, 'I read and understood the stated terms. I had enough time to make a decision. Herewith, I consent to participate in this study.'], [0, 'I choose not to participate in this study.'] ], widget=widgets.RadioSelect ) P_ID = models.StringField(label="Please check whether your particpant ID is entered correctly.") expectation = models.IntegerField(blank=False, label='How many points would you expect to receive from Indvidual A if you were Individual B in this situation?', min=0, max=10) points_allocated_by_giver = models.CurrencyField() giver_condition = models.StringField() giver_P_ID = models.StringField() feedback = models.LongStringField(blank=True) #set payoff of donation game as payment for participating in experiment (here the endowment) minus the amount donated def set_payoffs(self): if self.donation_decision == 1: self.payoff = Constants.endowment - self.donation self.participant.vars['donation_payoff'] = self.payoff else: self.payoff = Constants.endowment self.participant.vars['donation_payoff'] = self.payoff