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 = """ Cost Allocation Task """ class Constants(BaseConstants): name_in_url = 'BSW3_Task' 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, 3, 4]) 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) def group_by_arrival_time_method(self, waiting_players): mgrs = [p for p in waiting_players] if len(mgrs) > 1: return [mgrs[0], mgrs[1]] class Group(BaseGroup): pass class DecodeStrings(models.Model): id = models.IntegerField(null=False,primary_key=True) letters = models.CharField(max_length=50) numbers = models.CharField(max_length=50) def decode_results(self, s_id): return self.objects.filter(id = s_id) class Player(BasePlayer): def get_partner(self): return self.get_others_in_group()[0] condition = models.IntegerField() partner_id = models.IntegerField() pay_period = models.IntegerField() #Store num attempted/decoded per period...plus partner's performance for calcs num_attempted_1 = models.IntegerField() num_decoded_1 = models.IntegerField() event_1 = models.IntegerField(default=9) income_1 = models.IntegerField() cost_1 = models.IntegerField() profit_1 = models.IntegerField() partner_decoded_1 = models.IntegerField() partner_event_1 = models.IntegerField() partner_income_1 = models.IntegerField() partner_cost_1 = models.IntegerField() partner_profit_1 = models.IntegerField() results_view_time_1 = models.CharField() num_attempted_2 = models.IntegerField() num_decoded_2 = models.IntegerField() event_2 = models.IntegerField(default=9) income_2 = models.IntegerField() cost_2 = models.IntegerField() profit_2 = models.IntegerField() partner_decoded_2 = models.IntegerField() partner_event_2 = models.IntegerField() partner_income_2 = models.IntegerField() partner_cost_2 = models.IntegerField() partner_profit_2 = models.IntegerField() results_view_time_2 = models.CharField() num_attempted_3 = models.IntegerField() num_decoded_3 = models.IntegerField() event_3 = models.IntegerField(default=9) income_3 = models.IntegerField() cost_3 = models.IntegerField() profit_3 = models.IntegerField() partner_decoded_3 = models.IntegerField() partner_event_3 = models.IntegerField() partner_income_3 = models.IntegerField() partner_cost_3 = models.IntegerField() partner_profit_3 = models.IntegerField() results_view_time_3 = models.CharField() num_attempted_4 = models.IntegerField() num_decoded_4 = models.IntegerField() event_4 = models.IntegerField(default=9) income_4 = models.IntegerField() cost_4 = models.IntegerField() profit_4 = models.IntegerField() partner_decoded_4 = models.IntegerField() partner_event_4 = models.IntegerField() partner_income_4 = models.IntegerField() partner_cost_4 = models.IntegerField() partner_profit_4 = models.IntegerField() results_view_time_4 = models.CharField() total_wait_time = models.IntegerField() pay_profit = models.IntegerField() peq_group_attachment = models.CharField(initial=None, choices=[('1', '1 = Strongly disagree.'), ('2', '2 '), ('3', '3 '), ('4', '4 = Neither agree nor disagree '), ('5', '5 '), ('6', '6 '), ('7', '7 = Strongly agree.')], verbose_name='', widget=widgets.RadioSelectHorizontal()) peq_group_exit = models.CharField(initial=None, choices=[('1', '1 = Strongly disagree.'), ('2', '2 '), ('3', '3 '), ('4', '4 = Neither agree nor disagree '), ('5', '5 '), ('6', '6 '), ('7', '7 = Strongly agree.')], verbose_name='', widget=widgets.RadioSelectHorizontal()) peq_group_similarity = models.CharField(initial=None, choices=[('1', '1 = Strongly disagree.'), ('2', '2 '), ('3', '3 '), ('4', '4 = Neither agree nor disagree '), ('5', '5 '), ('6', '6 '), ('7', '7 = Strongly agree.')], verbose_name='', widget=widgets.RadioSelectHorizontal()) peq_group_salience = models.CharField(initial=None, choices=[('1', '1 = Strongly disagree.'), ('2', '2 '), ('3', '3 '), ('4', '4 = Neither agree nor disagree '), ('5', '5 '), ('6', '6 '), ('7', '7 = Strongly agree.')], verbose_name='', widget=widgets.RadioSelectHorizontal()) peq_relational_identification = models.CharField(initial=None, choices=[('1', '1 = Strongly disagree.'), ('2', '2 '), ('3', '3 '), ('4', '4 = Neither agree nor disagree '), ('5', '5 '), ('6', '6 '), ('7', '7 = Strongly agree.')], verbose_name='', widget=widgets.RadioSelectHorizontal()) peq_allocation_fairness = models.CharField(initial=None, choices=[('1', '1 = Not fair at all.'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('6', '6 = Somewhat fair.'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10'), ('11', '11 = Extremely fair.')], verbose_name='') peq_perceived_control = models.CharField(initial=None, choices=[('1', '1 = No control at all.'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('6', '6 = A fair amount of control.'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10'), ('11', '11 = A great deal of control.')], verbose_name='') peq_expected_bonus = models.FloatField(verbose_name='') peq_compensation_satisfaction = models.CharField(initial=None, choices=[('1', '1 = Not at all satisfied.'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('6', '6 = Somewhat satisfied.'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10'), ('11', '11 = Very satisfied.')], verbose_name='') peq_task_difficulty = models.CharField(initial=None, choices=[('1', '1 = Not at all difficult.'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('6', '6 = Somewhat difficult.'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10'), ('11', '11 = Very difficult.')], verbose_name='', widget=widgets.RadioSelect()) peq_task_enjoyment = models.CharField(initial=None, choices=[('1', '1 = Not at all.'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('6', '6 = A fair amount.'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10'), ('11', '11 = A great deal.')], verbose_name='', widget=widgets.RadioSelect()) peq_ind_competition = models.CharField(initial=None, choices=[('1', '1 = Not at all important.'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('6', '6 = Somewhat important.'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10'), ('11', '11 = Very important.')], verbose_name='', widget=widgets.RadioSelect()) peq_rpi_salience = models.CharField(initial=None, choices=[('1', '1 = Not at all.'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('6', '6 = A fair amount.'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10'), ('11', '11 = A great deal.')], verbose_name='', widget=widgets.RadioSelect()) peq_event_impact = models.CharField(initial=None, choices=[('1', '1 = The possibility of this event made me put forth much less effort.'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('6', '6 = The possibility of this event had no effect on my effort.'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10'), ('11', '11 = The possibility of this event made me put forth much more effort.')], verbose_name='') peq_group_effort = models.CharField(initial=None, choices=[('1', '1 = I definitely worked harder than my other group member.'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('6', '6 = My group member and I likely worked equally as hard as each other.'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10'), ('11', '11 = My group member definitely worked harder than I did.')], verbose_name='') peq_turk_income = models.CharField(initial=None, choices=[('1', '1 = My work on MTurk is for fun or interest only - I ' 'don`t rely on it for income.'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('6', '6 = My work on MTurk supplements my household`s' ' primary income.'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10'), ('11', '11 = My work on MTurk generates a significant' ' portion of my household`s total income.')], verbose_name='') peq_risk_attitude = models.CharField(initial=None, choices=[('1', '1 = I`m not at all willing to take risks.'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('6', '6 = I`m somewhat willing to take risks.'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10'), ('11', '11 = I`m very willing to take risks.')], verbose_name='') peq_others_risk = models.CharField(initial=None, choices=[('1', '1 = Others are far less willing to take risks.'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('6', '6 = Others are equally willing to take risks.'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10'), ('11', '11 = Others are far more willing to take risks.')], verbose_name='') peq_affect_excited = models.CharField(initial=None, choices=[('1', '1 = Not at all.'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('6', '6 = Moderately.'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10'), ('11', '11 = Extremely.')], verbose_name='', widget=widgets.RadioSelectHorizontal()) peq_affect_upset = models.CharField(initial=None, choices=[('1', '1 = Not at all.'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('6', '6 = Moderately.'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10'), ('11', '11 = Extremely.')], verbose_name='', widget=widgets.RadioSelectHorizontal()) peq_affect_proud = models.CharField(initial=None, choices=[('1', '1 = Not at all.'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('6', '6 = Moderately.'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10'), ('11', '11 = Extremely.')], verbose_name='', widget=widgets.RadioSelectHorizontal()) peq_affect_irritable = models.CharField(initial=None, choices=[('1', '1 = Not at all.'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('6', '6 = Moderately.'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10'), ('11', '11 = Extremely.')], verbose_name='', widget=widgets.RadioSelectHorizontal()) peq_affect_inspired = models.CharField(initial=None, choices=[('1', '1 = Not at all.'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('6', '6 = Moderately.'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10'), ('11', '11 = Extremely.')], verbose_name='', widget=widgets.RadioSelectHorizontal()) peq_affect_nervous = models.CharField(initial=None, choices=[('1', '1 = Not at all.'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('6', '6 = Moderately.'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10'), ('11', '11 = 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='', widget=widgets.RadioSelect()) task_bonus = models.FloatField() wait_bonus = models.FloatField() total_comp = models.FloatField()