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 = 'BSW2_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): # No real 'role' that needs to be matched separately, so just group by time def get_players_for_group(self, waiting_players): mgrs = [p for p in waiting_players] if len(mgrs) > 1: return [mgrs[0], mgrs[1]] class Group(BaseGroup): pass class Project(models.Model): project_id = models.IntegerField() outcome_id = models.IntegerField() outcome = models.IntegerField() def project_results(self, projectid, outcomeid): return self.objects.filter(project_id = projectid, outcome_id = outcomeid) class ProjectDisplay(models.Model): project_id = models.IntegerField() first_outcome = models.IntegerField() first_odds = models.IntegerField() second_outcome = models.IntegerField() second_odds = models.IntegerField() class Player(BasePlayer): def get_partner(self): return self.get_others_in_group()[0] condition = models.IntegerField() partner_id = models.IntegerField() pair_order = models.CharField() paying_selection = models.IntegerField() # "Baseline" project is denoted as project 1, so that I can keep integer fields p1v2 = models.IntegerField() p3v4 = models.IntegerField() p5v6 = models.IntegerField() p7v8 = models.IntegerField() p9v10 = models.IntegerField() p11v12 = models.IntegerField() p13v14 = models.IntegerField() p15v16 = models.IntegerField() p17v18 = models.IntegerField() p19v20 = models.IntegerField() p21v22 = models.IntegerField() p23v24 = models.IntegerField() p25v26 = models.IntegerField() p27v28 = models.IntegerField() p29v30 = models.IntegerField() # ... p1v2a = models.IntegerField() p3v4a = models.IntegerField() p5v6a = models.IntegerField() p7v8a = models.IntegerField() p9v10a = models.IntegerField() p11v12a = models.IntegerField() p13v14a = models.IntegerField() p15v16a = models.IntegerField() p17v18a = models.IntegerField() p19v20a = models.IntegerField() p21v22a = models.IntegerField() p23v24a = models.IntegerField() p25v26a = models.IntegerField() p27v28a = models.IntegerField() p29v30a = models.IntegerField() p1v2_time = models.CharField() p3v4_time = models.CharField() p5v6_time = models.CharField() p7v8_time = models.CharField() p9v10_time = models.CharField() p11v12_time = models.CharField() p13v14_time = models.CharField() p15v16_time = models.CharField() p17v18_time = models.CharField() p19v20_time = models.CharField() p21v22_time = models.CharField() p23v24_time = models.CharField() p25v26_time = models.CharField() p27v28_time = models.CharField() p29v30_time = models.CharField() # New fields for getting them paid on all 10 project selections implemented_project_1 = models.IntegerField() implemented_project_2 = models.IntegerField() implemented_project_3 = models.IntegerField() implemented_project_4 = models.IntegerField() implemented_project_5 = models.IntegerField() implemented_project_6 = models.IntegerField() implemented_project_7 = models.IntegerField() implemented_project_8 = models.IntegerField() implemented_project_9 = models.IntegerField() implemented_project_10 = models.IntegerField() implemented_project_11 = models.IntegerField() implemented_project_12 = models.IntegerField() implemented_project_13 = models.IntegerField() implemented_project_14 = models.IntegerField() implemented_project_15 = models.IntegerField() implemented_project_outcome_1 = models.IntegerField() implemented_project_outcome_2 = models.IntegerField() implemented_project_outcome_3 = models.IntegerField() implemented_project_outcome_4 = models.IntegerField() implemented_project_outcome_5 = models.IntegerField() implemented_project_outcome_6 = models.IntegerField() implemented_project_outcome_7 = models.IntegerField() implemented_project_outcome_8 = models.IntegerField() implemented_project_outcome_9 = models.IntegerField() implemented_project_outcome_10 = models.IntegerField() implemented_project_outcome_11 = models.IntegerField() implemented_project_outcome_12 = models.IntegerField() implemented_project_outcome_13 = models.IntegerField() implemented_project_outcome_14 = models.IntegerField() implemented_project_outcome_15 = models.IntegerField() partner_outcome_1 = models.IntegerField() partner_outcome_2 = models.IntegerField() partner_outcome_3 = models.IntegerField() partner_outcome_4 = models.IntegerField() partner_outcome_5 = models.IntegerField() partner_outcome_6 = models.IntegerField() partner_outcome_7 = models.IntegerField() partner_outcome_8 = models.IntegerField() partner_outcome_9 = models.IntegerField() partner_outcome_10 = models.IntegerField() partner_outcome_11 = models.IntegerField() partner_outcome_12 = models.IntegerField() partner_outcome_13 = models.IntegerField() partner_outcome_14 = models.IntegerField() partner_outcome_15 = models.IntegerField() cost_1 = models.IntegerField() cost_2 = models.IntegerField() cost_3 = models.IntegerField() cost_4 = models.IntegerField() cost_5 = models.IntegerField() cost_6 = models.IntegerField() cost_7 = models.IntegerField() cost_8 = models.IntegerField() cost_9 = models.IntegerField() cost_10 = models.IntegerField() cost_11 = models.IntegerField() cost_12 = models.IntegerField() cost_13 = models.IntegerField() cost_14 = models.IntegerField() cost_15 = models.IntegerField() profit_1 = models.IntegerField() profit_2 = models.IntegerField() profit_3 = models.IntegerField() profit_4 = models.IntegerField() profit_5 = models.IntegerField() profit_6 = models.IntegerField() profit_7 = models.IntegerField() profit_8 = models.IntegerField() profit_9 = models.IntegerField() profit_10 = models.IntegerField() profit_11 = models.IntegerField() profit_12 = models.IntegerField() profit_13 = models.IntegerField() profit_14 = models.IntegerField() profit_15 = models.IntegerField() total_wait_time = models.IntegerField() peq_group_attachment = models.CharField(initial=None, choices=[('0', '0 = Strongly disagree.'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5 = Neither agree nor disagree.'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10 = Strongly agree.')], verbose_name='') peq_group_exit = models.CharField(initial=None, choices=[('0', '0 = Strongly disagree.'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5 = Neither agree nor disagree.'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10 = Strongly agree.')], verbose_name='') peq_group_member_similarity = models.CharField(initial=None, choices=[('0', '0 = Strongly disagree.'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5 = Neither agree nor disagree.'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10 = Strongly agree.')], verbose_name='') peq_group_salience = models.CharField(initial=None, choices=[('0', '0 = Strongly disagree.'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5 = Neither agree nor disagree.'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10 = Strongly agree.')], verbose_name='') peq_relational_identification = models.CharField(initial=None, choices=[('0', '0 = Strongly disagree.'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5 = Neither agree nor disagree.'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10 = Strongly agree.')], verbose_name='') peq_group_member_success = models.CharField(initial=None, choices=[('0', '0 = Strongly disagree.'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5 = Neither agree nor disagree.'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10 = Strongly agree.')], verbose_name='') peq_choice_difficulty = models.CharField(initial=None, choices=[('0', '0 = Not at all - there was always a clear "best" choice for me.'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5 = Somewhat difficult - some of the project options seemed equally attractive.'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10 = Extremely difficult - the two projects often seemed equally attractive.')], verbose_name='') peq_expected_bonus = models.FloatField(verbose_name='') peq_compensation_satisfaction = models.CharField(initial=None, choices=[('0', '0 = Not at all satisfied.'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5 = Somewhat satisfied.'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10 = Very satisfied.')], verbose_name='') peq_allocation_fairness = models.CharField(initial=None, choices=[('0', '0 = Not fair at all.'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5 = Somewhat fair.'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10 = Extremely fair.')], verbose_name='') peq_perceived_control = models.CharField(initial=None, choices=[('0', '0 = No control at all.'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5 = A fair amount of control.'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10 = A great deal of control.')], verbose_name='') total_bonus = models.CharField() total_comp = models.CharField()