from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random import itertools from random import shuffle # author = 'Dan Way' doc = """ Public Good """ class Constants(BaseConstants): name_in_url = 'pg' players_per_group = 2 num_rounds = 1 class Subsession(BaseSubsession): def creating_session(self): if 'condition' in self.session.config: for g in self.get_groups(): p1 = g.get_player_by_id(1) p2 = g.get_player_by_id(2) p1.participant.vars['condition'] = self.session.config['condition'] p2.participant.vars['condition'] = self.session.config['condition'] p1.participant.vars['counterbal'] = 1 # Counterbalance in case we need it p2.participant.vars['counterbal'] = 2 else: conditions = itertools.cycle([1, 2]) counterbal = itertools.cycle([1, 2]) for g in self.get_groups(): # g.condition = next(conditions) p1 = g.get_player_by_id(1) p2 = g.get_player_by_id(2) p1.participant.vars['condition'] = next(conditions) p2.participant.vars['condition'] = p1.participant.vars['condition'] p1.participant.vars['counterbal'] = next(counterbal) p2.participant.vars['counterbal'] = next(counterbal) class Group(BaseGroup): pass class Player(BasePlayer): condition = models.IntegerField() kc1 = models.CharField(initial=None, choices=['True', 'False'], verbose_name='', widget=widgets.RadioSelect()) kc2 = models.CharField(initial=None, choices=['True', 'False'], verbose_name='', widget=widgets.RadioSelect()) kc3 = models.CharField(initial=None, choices=['True', 'False'], verbose_name='', widget=widgets.RadioSelect()) kc4 = models.CharField(initial=None, choices=[('a', 'a. 1'), ('b', 'b. 2'), ('c', 'c. 3'), ('d', 'd. 4')], verbose_name='', widget=widgets.RadioSelect()) tokens_kept = models.IntegerField(verbose_name='') tokens_contributed = models.IntegerField(verbose_name='') decision_time = models.CharField() group_number = models.IntegerField() # For when I form groups after the fact task_1_bonus = models.CharField() total_bonus = models.CharField() group_comp = models.CharField(initial='TBD') wait_bonus = models.CharField() total_comp = models.CharField() peq_pg_choice_difficulty = models.CharField(initial=None, choices=[('0', '0 = Not at all - there was a clear "best" choice for me.'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5 = Somewhat difficult - both options seemed like an equally good choice.'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10 = Extremely difficult - the "best" choice was not clear to me.')], verbose_name='') peq_importance_group_pay = models.CharField(initial=None, choices=[('0', '0 = Not at all important.'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5 = Somewhat important.'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10 = Very important.')], verbose_name='') peq_importance_individual_pay = models.CharField(initial=None, choices=[('0', '0 = Not at all important.'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5 = Somewhat important.'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10 = Very important.')], verbose_name='') peq_importance_guilt_avoidance = models.CharField(initial=None, choices=[('0', '0 = Not at all important.'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5 = Somewhat important.'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10 = Very important.')], verbose_name='') peq_importance_group_letdown = models.CharField(initial=None, choices=[('0', '0 = Not at all important.'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5 = Somewhat important.'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10 = Very important.')], verbose_name='') peq_importance_others_preference = models.CharField(initial=None, choices=[('0', '0 = Not at all important.'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5 = Somewhat important.'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10 = Very important.')], verbose_name='') peq_pg_expected_bonus = models.FloatField(verbose_name='') peq_pg_compensation_satisfaction = models.CharField(initial=None, choices=[('0', '0 = Not at all satisfied.'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10 = Very satisfied.')], verbose_name='') peq_open_ended = models.TextField(verbose_name = '') peq_expected_cooperation = models.CharField(initial=None, choices=[('0', '0 = I did not them others to contribute any tokens to ' 'the group pot.'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5 = I expected them to contribute some tokens to the ' 'group pot.'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10 = I expected them to contribute all of their tokens ' 'to the group pot.')], verbose_name='') peq_turk_income = models.CharField(initial=None, choices=[('0', '0 = My work on MTurk is for fun or interest only - I ' 'don`t rely on it for income.'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5 = My work on MTurk supplements my household`s' ' primary income.'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10 = My work on MTurk generates a significant' ' portion of my household`s total income.')], verbose_name='') peq_risk_attitude = models.CharField(initial=None, choices=[('0', '0 = I`m not at all willing to take risks.'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5 = I`m somewhat willing to take risks.'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10 = I`m very willing to take risks.')], verbose_name='') peq_others_risk = models.CharField(initial=None, choices=[('0', '0 = Others are far less willing to take risks.'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5 = Others are equally willing to take risks.'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10 = Others are far more willing to take risks.')], verbose_name='') peq_affect_excited = models.CharField(initial=None, choices=[('0', '0 = Not at all.'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5 = Moderately.'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10 = Extremely.')], verbose_name='', widget=widgets.RadioSelectHorizontal()) peq_affect_upset = models.CharField(initial=None, choices=[('0', '0 = Not at all.'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5 = Moderately.'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10 = Extremely.')], verbose_name='', widget=widgets.RadioSelectHorizontal()) peq_affect_proud = models.CharField(initial=None, choices=[('0', '0 = Not at all.'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5 = Moderately.'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10 = Extremely.')], verbose_name='', widget=widgets.RadioSelectHorizontal()) peq_affect_irritable = models.CharField(initial=None, choices=[('0', '0 = Not at all.'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5 = Moderately.'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10 = Extremely.')], verbose_name='', widget=widgets.RadioSelectHorizontal()) peq_affect_inspired = models.CharField(initial=None, choices=[('0', '0 = Not at all.'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5 = Moderately.'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10 = Extremely.')], verbose_name='', widget=widgets.RadioSelectHorizontal()) peq_affect_nervous = models.CharField(initial=None, choices=[('0', '0 = Not at all.'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5 = Moderately.'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10 = Extremely.')], verbose_name='', widget=widgets.RadioSelectHorizontal()) peq_gender = models.CharField(initial=None, choices=[('1', 'Male'), ('2', 'Female')], verbose_name='', widget=widgets.RadioSelect()) peq_age_range = models.CharField(initial=None, choices=[('1', '18-24'), ('2', '25-34'), ('3', '35-44'), ('4', '45-54'), ('5', '55-64'), ('6', '65 and older')], verbose_name='') peq_work_experience = models.IntegerField(verbose_name='') peq_education = models.CharField(initial=None, choices=[('1', 'Less than high school'), ('2', 'High school graduate'), ('3', 'Some college'), ('4', '2 year degree'), ('5', '4 year degree'), ('6', 'Graduate degree')], verbose_name='') worker_id = models.CharField(initial='e')