from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) author = 'Neeraja Gupta' doc = """ This is a one-shot "Prisoner's Dilemma" with flipped labels. Two players are asked separately whether they want to cooperate or defect. Their choices directly determine the payoffs. This app is programmed in the form of a survey with randomization and payoffs determined outside and stored in a dataframe. Option corresponds to defection and option corresponds to cooperative action """ import pandas as pd import random dataframe = pd.read_csv('./assignment_s1.csv') class Constants(BaseConstants): name_in_url = 'pd' players_per_group = None num_rounds = 1 class Subsession(BaseSubsession): def creating_sessions(self): for p in self.get_players(): p.my_id = p.id_in_group p.my_code = str(random.randint(10000,99999)) p.partner_r1 = dataframe.iloc[p.my_id - 1][1] p.aa_payoff_r1 = dataframe.iloc[p.my_id - 1][3] p.ab_payoff_r1 = dataframe.iloc[p.my_id - 1][4] p.ba_payoff_r1 = dataframe.iloc[p.my_id - 1][5] p.bb_payoff_r1 = dataframe.iloc[p.my_id - 1][6] p.selection_r1 = dataframe.iloc[p.my_id - 1][7] p.partner_r2 = dataframe.iloc[p.my_id - 1][8] p.aa_payoff_r2 = dataframe.iloc[p.my_id - 1][10] p.ab_payoff_r2 = dataframe.iloc[p.my_id - 1][11] p.ba_payoff_r2 = dataframe.iloc[p.my_id - 1][12] p.bb_payoff_r2 = dataframe.iloc[p.my_id - 1][13] p.selection_r2 = dataframe.iloc[p.my_id - 1][14] p.partner_r3 = dataframe.iloc[p.my_id - 1][15] p.aa_payoff_r3 = dataframe.iloc[p.my_id - 1][17] p.ab_payoff_r3 = dataframe.iloc[p.my_id - 1][18] p.ba_payoff_r3 = dataframe.iloc[p.my_id - 1][19] p.bb_payoff_r3 = dataframe.iloc[p.my_id - 1][20] p.selection_r3 = dataframe.iloc[p.my_id - 1][21] p.partner_r4 = dataframe.iloc[p.my_id - 1][22] p.aa_payoff_r4 = dataframe.iloc[p.my_id - 1][24] p.ab_payoff_r4 = dataframe.iloc[p.my_id - 1][25] p.ba_payoff_r4 = dataframe.iloc[p.my_id - 1][26] p.bb_payoff_r4 = dataframe.iloc[p.my_id - 1][27] p.selection_r4 = dataframe.iloc[p.my_id - 1][28] class Group(BaseGroup): pass class Player(BasePlayer): # this where we define all column for the player table in the database # player_session = self.participant.label my_id = models.IntegerField() my_code = models.StringField( label='''Your participation code''', ) # Comprehension Question 1 ques1 = models.StringField( choices=['$20', '$7', '$14', '$15'], label='''Suppose that this decision table is selected for final payment. If in this table you chose A and your matched participant chose B. What will be the matched participant's earnings from this table?''', widget=widgets.RadioSelect ) # Comprehension Question 2 ques2 = models.StringField( choices=['$20', '$7', '$14', '$15'], label='''Suppose that this decision table is selected for final payment. If in this table you chose B and your matched other participant also chose B. What will be your earnings from this table?''', widget=widgets.RadioSelect ) # round 1 payoffs for the decision table assigned from dataframe at the beginning of session aa_payoff_r1 = models.IntegerField() ab_payoff_r1 = models.IntegerField() ba_payoff_r1 = models.IntegerField() bb_payoff_r1 = models.IntegerField() # round 2 payoffs for the decision table assigned from dataframe at the beginning of session aa_payoff_r2 = models.IntegerField() ab_payoff_r2 = models.IntegerField() ba_payoff_r2 = models.IntegerField() bb_payoff_r2 = models.IntegerField() # round 3 payoffs for the decision table assigned from dataframe at the beginning of session aa_payoff_r3 = models.IntegerField() ab_payoff_r3 = models.IntegerField() ba_payoff_r3 = models.IntegerField() bb_payoff_r3 = models.IntegerField() # round 4 payoffs for the decision table assigned from dataframe at the beginning of session aa_payoff_r4 = models.IntegerField() ab_payoff_r4 = models.IntegerField() ba_payoff_r4 = models.IntegerField() bb_payoff_r4 = models.IntegerField() # this player's decisions for each round - formfield for the decision pages decision_r1 = models.StringField( choices=['Option A', 'Option B'], label='''Please indicate your choice in this decision table''', doc="""This player's decision""", widget=widgets.RadioSelect ) decision_r2 = models.StringField( choices=['Option A', 'Option B'], label='''Please indicate your choice in this decision table''', doc="""This player's decision""", widget=widgets.RadioSelect ) decision_r3 = models.StringField( choices=['Option A', 'Option B'], label='''Please indicate your choice in this decision table''', doc="""This player's decision""", widget=widgets.RadioSelect ) decision_r4 = models.StringField( choices=['Option A', 'Option B'], label='''Please indicate your choice in this decision table''', doc="""This player's decision""", widget=widgets.RadioSelect ) # partner IDs assigned from dataframe at the beginning of session partner_r1 = models.IntegerField() partner_r2 = models.IntegerField() partner_r3 = models.IntegerField() partner_r4 = models.IntegerField() # partner and their decision partner_decision_r1 = models.StringField( choices=['Option A', 'Option B'] ) partner_decision_r2 = models.StringField( choices=['Option A', 'Option B'] ) partner_decision_r3 = models.StringField( choices=['Option A', 'Option B'] ) partner_decision_r4 = models.StringField( choices=['Option A', 'Option B'] ) # payment selection dummy assigned from dataframe at the beginning of session selection_r1 = models.IntegerField() selection_r2 = models.IntegerField() selection_r3 = models.IntegerField() selection_r4 = models.IntegerField() # payments from each round - will be calculated at the end of the session payoff_r1 = models.IntegerField() # raw payoff fields based on decisions payoff_r2 = models.IntegerField() payoff_r3 = models.IntegerField() payoff_r4 = models.IntegerField() payment_r1 = models.IntegerField() #actual payments payment_r2 = models.IntegerField() payment_r3 = models.IntegerField() payment_r4 = models.IntegerField() participation_fee = models.IntegerField(initial=6) total_payment = models.IntegerField() # Demographics description = models.LongStringField( label='''Please describe briefly how you made decisions in this study''' ) age = models.IntegerField( label='''How old are you?''' ) gender = models.StringField( choices=['Female', 'Male', 'Other'], label='''What gender do you identify with?''', doc="""This player's gender""", widget=widgets.RadioSelect ) college_year = models.StringField( choices=['Freshman', 'Sophomore', 'Junior', 'Senior or Higher', 'Other'], label='''What is your year in college?''', doc="""This player's year in college""", widget=widgets.RadioSelect ) current_major = models.StringField( choices=['Natural Sciences or Engineering', 'Social Sciences', 'Business', 'Other'], label='''What is your current major?''', doc="""This player's current major""", widget=widgets.RadioSelect )