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 = """ RPI in CSR """ class Constants(BaseConstants): name_in_url = 'gmw' players_per_group = 5 num_rounds = 1 class Subsession(BaseSubsession): def creating_session(self): if 'condition' in self.session.config: for g in self.get_groups(): #for p in g.get_players(): p1 = g.get_player_by_id(1) p2 = g.get_player_by_id(2) p3 = g.get_player_by_id(3) p4 = g.get_player_by_id(4) p5 = g.get_player_by_id(5) #...they'll be rematched later anyway p1.participant.vars['condition'] = self.session.config['condition'] p2.participant.vars['condition'] = self.session.config['condition'] p3.participant.vars['condition'] = self.session.config['condition'] p4.participant.vars['condition'] = self.session.config['condition'] p5.participant.vars['condition'] = self.session.config['condition'] def vars_for_admin_report(self): participants = [p.id for p in self.get_players()] totalcomp = [p.total_compensation for p in self.get_players()] payperiod = [p.pay_period for p in self.get_players()] return dict(participants=participants, totalcomp=totalcomp, payperiod=payperiod) class Group(BaseGroup): pass class Rank(models.Model): period_number = models.IntegerField() # 0 for practice, 1, 2, 3, 4... type = models.IntegerField() # 1=dollar, 2=impact, 3=return group_id = models.IntegerField() player_id = models.IntegerField() value = models.FloatField() rank = models.IntegerField() player_label = models.CharField() #label_for_1 = models.CharField() #label_for_2 = models.CharField() #label_for_3 = models.CharField() #label_for_4 = models.CharField() #label_for_5 = models.CharField() class Player(BasePlayer): participant_number = models.IntegerField(default=0) total_compensation = models.CharField(default='Not Finished') player_label = models.CharField() condition = models.IntegerField() pay_period = models.IntegerField() informed_consent = models.CharField(initial=None, choices=[('Yes', 'Yes'), ('No', 'No')], verbose_name='', widget=widgets.RadioSelect()) kc1 = models.CharField(initial=None, choices=['True', 'False'], verbose_name='', widget=widgets.RadioSelect()) kc2 = models.CharField(initial=None, choices=[('a', 'a. 2'), ('b', 'b. 3'), ('c', 'c. 4'), ('d', 'd. 5')], verbose_name='', widget=widgets.RadioSelect()) kc3 = models.CharField(initial=None, choices=['True', 'False'], verbose_name='', widget=widgets.RadioSelect()) kc4 = models.CharField(initial=None, choices=['True', 'False'], verbose_name='', widget=widgets.RadioSelect()) kc5 = models.CharField(initial=None, choices=[('a', 'a. $0'), ('b', 'b. $3'), ('c', 'c. $6'), ('d', 'd. $9')], verbose_name='', widget=widgets.RadioSelect()) kc6 = models.CharField(initial=None, choices=[('a', 'a. $0'), ('b', 'b. $3'), ('c', 'c. $6'), ('d', 'd. $9')], verbose_name='', widget=widgets.RadioSelect()) kc7 = models.CharField(initial=None, choices=[('a', 'a. Higher probability of success.'), ('b', 'b. Lower probability of success.')], verbose_name='', widget=widgets.RadioSelect()) kc8 = models.CharField(initial=None, choices=[('a', 'a. Higher probability of success.'), ('b', 'b. Lower probability of success.')], verbose_name='', widget=widgets.RadioSelect()) kc9 = models.CharField(initial=None, choices=['True', 'False'], verbose_name='', widget=widgets.RadioSelect()) kc10a = models.CharField(initial=None, choices=['True', 'False'], verbose_name='', widget=widgets.RadioSelect()) kc10b = models.CharField(initial=None, choices=['True', 'False'], verbose_name='', widget=widgets.RadioSelect()) kc10c = models.CharField(initial=None, choices=['True', 'False'], verbose_name='', widget=widgets.RadioSelect()) kc10d = models.CharField(initial=None, choices=['True', 'False'], verbose_name='', widget=widgets.RadioSelect()) practice_decision_time = models.CharField() practice_dollars_kept = models.FloatField(verbose_name='') practice_dollars_invested = models.FloatField(verbose_name='') practice_local_weight = models.IntegerField(verbose_name='') practice_state_weight = models.IntegerField(verbose_name='') practice_national_weight = models.IntegerField(verbose_name='') practice_impact_score = models.FloatField() #Store impact score after calc to ease with RPI practice_potential_return = models.FloatField() #Same for potential return practice_local_payoff = models.IntegerField() #Store outcome 0/1 of draw practice_state_payoff = models.IntegerField() practice_national_payoff = models.IntegerField() practice_dollar_rank = models.IntegerField() practice_impact_rank = models.IntegerField() practice_return_rank = models.IntegerField() charity_selection = models.CharField() #Store each period's decisions separately, but also use running totals for rankings... running_dollars_invested = models.FloatField() running_impact_score = models.FloatField() running_potential_return = models.FloatField() p1_decision_time = models.CharField() p1_dollars_kept = models.FloatField() p1_dollars_invested = models.FloatField() p1_local_weight = models.IntegerField() p1_state_weight = models.IntegerField() p1_national_weight = models.IntegerField() p1_dollar_rank = models.IntegerField() p1_impact_rank = models.IntegerField() p1_return_rank = models.IntegerField() #In periods 2-4, store cumulative investments, impact score, return for display to Ps and for rankings for RPI # conditions p2_decision_time = models.CharField() p2_dollars_kept = models.FloatField() p2_dollars_invested = models.FloatField() p2_local_weight = models.IntegerField() p2_state_weight = models.IntegerField() p2_national_weight = models.IntegerField() p2_dollar_rank = models.IntegerField() p2_impact_rank = models.IntegerField() p2_return_rank = models.IntegerField() p3_decision_time = models.CharField() p3_dollars_kept = models.FloatField() p3_dollars_invested = models.FloatField() p3_local_weight = models.IntegerField() p3_state_weight = models.IntegerField() p3_national_weight = models.IntegerField() p3_dollar_rank = models.IntegerField() p3_impact_rank = models.IntegerField() p3_return_rank = models.IntegerField() p4_decision_time = models.CharField() p4_dollars_kept = models.FloatField() p4_dollars_invested = models.FloatField() p4_local_weight = models.IntegerField() p4_state_weight = models.IntegerField() p4_national_weight = models.IntegerField() p4_dollar_rank = models.IntegerField() p4_impact_rank = models.IntegerField() p4_return_rank = models.IntegerField() state_project_payoff = models.IntegerField() national_project_payoff = models.IntegerField() charity_payment = models.FloatField() #PEQ feeling_performance = models.CharField(initial=None, choices=[('1', '1 = Very ashamed.'), ('2', '2 '), ('3', '3 '), ('4', '4 = Neither ashamed nor proud.'), ('5', '5 '), ('6', '6 '), ('7', '7 = Very proud.')], verbose_name='', widget=widgets.RadioSelectHorizontal()) ranking_salience = models.CharField(initial=None, choices=[('1', '1 = Never.'), ('2', '2 '), ('3', '3 '), ('4', '4 = Sometimes.'), ('5', '5 '), ('6', '6 '), ('7', '7 = Very often.')], verbose_name='', widget=widgets.RadioSelectHorizontal()) ranking_concern = models.CharField(initial=None, choices=[('1', '1 = Not at all nervous or concerned.'), ('2', '2 '), ('3', '3 '), ('4', '4 = Somewhat nervous or concerned.'), ('5', '5 '), ('6', '6 '), ('7', '7 = Very nervous or concerned.')], verbose_name='', widget=widgets.RadioSelectHorizontal()) ranking_interference = models.CharField(initial=None, choices=[('1', '1 = Not at all.'), ('2', '2 '), ('3', '3 '), ('4', '4 = Somewhat.'), ('5', '5 '), ('6', '6 '), ('7', '7 = Very much.')], verbose_name='', widget=widgets.RadioSelectHorizontal()) high_investment_desire = 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()) high_impact_desire = 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()) high_return_desire = 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()) look_good_concern = 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()) investment_comfort = 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()) impact_comfort = 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()) charitability_image = 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()) 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='') importance_prob_success = models.CharField(initial=None, choices=[('1', '1 = Not at all important.'), ('2', '2 '), ('3', '3 '), ('4', '4 = Somewhat important.'), ('5', '5 '), ('6', '6 '), ('7', '7 = Very important.')], verbose_name='', widget=widgets.RadioSelectHorizontal()) charity_inv_preference = models.CharField(initial=None, choices=[('1', '1 = Charity would strongly prefer projects with lower ' 'impact and higher probability of success.'), ('2', '2 '), ('3', '3 '), ('4', '4 = Charity would have no preference.'), ('5', '5 '), ('6', '6 '), ('7', '7 = Charity would strongly prefer projects with higher ' 'impact and lower probability of success.')], verbose_name='') csr_importance = 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()) general_charity_importance = models.CharField(initial=None, choices=[('1', '1 = Not at all important.'), ('2', '2 '), ('3', '3 '), ('4', '4 = Somewhat important.'), ('5', '5 '), ('6', '6 '), ('7', '7 = Very important.')], verbose_name='', widget=widgets.RadioSelectHorizontal()) charity_identification = models.CharField(initial=None, choices=[('1', '1 = Not at all.'), ('2', '2 '), ('3', '3 '), ('4', '4 = Somewhat.'), ('5', '5 '), ('6', '6 '), ('7', '7 = A great deal.')], verbose_name='', widget=widgets.RadioSelectHorizontal()) relative_importance_investment = models.CharField(initial=None, choices=[('1', '1 = Greater social impact is more important.'), ('2', '2 '), ('3', '3 '), ('4', '4 = Both are equally important.'), ('5', '5 '), ('6', '6 '), ('7', '7 = Investing more $ is more important.')], verbose_name='', widget=widgets.RadioSelectHorizontal()) project_failure_guilt = 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()) non_maximizing_guilt = 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()) investment_decision_difficulty = models.CharField(initial=None, choices=[('1', '1 = Not at all difficult.'), ('2', '2 '), ('3', '3 '), ('4', '4 = Somewhat difficult.'), ('5', '5 '), ('6', '6 '), ('7', '7 = Very difficult.')], verbose_name='', widget=widgets.RadioSelectHorizontal()) impact_decision_difficulty = models.CharField(initial=None, choices=[('1', '1 = Not at all difficult.'), ('2', '2 '), ('3', '3 '), ('4', '4 = Somewhat difficult.'), ('5', '5 '), ('6', '6 '), ('7', '7 = Very difficult.')], verbose_name='', widget=widgets.RadioSelectHorizontal()) ranking_processing_difficulty = models.CharField(initial=None, choices=[('1', '1 = Not at all difficult.'), ('2', '2 '), ('3', '3 '), ('4', '4 = Somewhat difficult.'), ('5', '5 '), ('6', '6 '), ('7', '7 = Very difficult.')], verbose_name='', widget=widgets.RadioSelectHorizontal()) inc_return_factors = models.CharField(initial=None, choices=[('a', 'a. Increasing the cumulative average social impact score.'), ('b', 'b. Increasing the cumulative dollar amount of investments.'), ('c', 'c. No difference.')], verbose_name='', widget=widgets.RadioSelect()) inc_return_extent = models.CharField(initial=None, choices=[('a', 'a. Somewhat easier.'), ('b', 'b. Moderately easier.'), ('c', 'c. Significantly easier.')], verbose_name='', widget=widgets.RadioSelect()) company_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()) peer_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()) investment_strategy = models.TextField(verbose_name='') strategy_change = models.TextField(verbose_name='') gender = models.CharField(initial=None, choices=[('a', 'a. Male'), ('b', 'b. Female'), ('c', 'c. Prefer not to say')], verbose_name='', widget=widgets.RadioSelect()) age = models.IntegerField(verbose_name='', min=18, max=50) major = models.CharField(initial=None, choices=[('a', 'a. Accounting'), ('b', 'b. Economics'), ('c', 'c. Financial Management'), ('d', 'd. Management'), ('e', 'e. Marketing'), ('f', 'f. Other') ], verbose_name='', widget=widgets.RadioSelect()) worker_id = models.CharField(initial='e') mturk_dupe = models.IntegerField()