from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'motivation_survey' players_per_group = None num_rounds = 1 class Subsession(BaseSubsession): def vars_for_admin_report(self): number = 0 social_you_l = [] social_others_l = [] money_you_l = [] money_others_l = [] recognition_you_l = [] recognition_others_l = [] autonomy_you_l = [] autonomy_others_l = [] working_env_you_l = [] working_env_others_l = [] for p in self.get_players(): if p.social_impact_you != None: social_you_l.append(p.social_impact_you) if p.social_impact_others != None: social_others_l.append(p.social_impact_others) if p.money_you != None: money_you_l.append(p.money_you) if p.money_others != None: money_others_l.append(p.money_others) if p.recognition_you != None: recognition_you_l.append(p.recognition_you) if p.recognition_others != None: recognition_others_l.append(p.recognition_others) if p.autonomy_you != None: autonomy_you_l.append(p.autonomy_you) if p.autonomy_others != None: autonomy_others_l.append(p.autonomy_others) if p.working_env_you != None: working_env_you_l.append(p.working_env_you) if p.working_env_others != None: working_env_others_l.append(p.working_env_others) social_you_mean = round(sum(social_you_l)/len(social_you_l),2) if len(social_you_l)>0 else 0 social_others_mean = round(sum(social_others_l) / len(social_others_l),2) if len(social_others_l) > 0 else 0 money_you_mean = round(sum(money_you_l) / len(money_you_l),2) if len(money_you_l) > 0 else 0 money_others_mean = round(sum(money_others_l) / len(money_others_l),2) if len(money_others_l) > 0 else 0 recognition_you_mean = round(sum(recognition_you_l) / len(recognition_you_l),2) if len(recognition_you_l) > 0 else 0 recognition_others_mean = round(sum(recognition_others_l) / len(recognition_others_l),2) if len(recognition_others_l) > 0 else 0 autonomy_you_mean = round(sum(autonomy_you_l) / len(autonomy_you_l),2) if len(autonomy_you_l) > 0 else 0 autonomy_others_mean = round(sum(autonomy_others_l) / len(autonomy_others_l),2) if len(autonomy_others_l) > 0 else 0 working_env_you_mean = round(sum(working_env_you_l) / len(working_env_you_l),2) if len(working_env_you_l) > 0 else 0 working_env_others_mean = round(sum(working_env_others_l) / len(working_env_others_l),2) if len(working_env_others_l) > 0 else 0 # for p in self.get_players(): # number=+1 # social_you_l.append(p.social_impact_you) # if len(social_you_l): # social_you_mean = sum(social_you_l)/len(social_you_l) # else: # social_you_mean = 0 # social_others_l.append(p.social_impact_others) # if len(social_you_l): # social_others_mean = sum(social_others_l) / len(social_others_l) # else: # social_others_mean = 0 # money_you_l.append(p.money_you) # if len(social_you_l): # money_you_mean = sum(money_you_l) / len(money_you_l) # else: # money_you_mean = 0 # money_others_l.append(p.money_others) # if len(social_you_l): # money_others_mean = sum(money_others_l) / len(money_others_l) # else: # money_others_mean = 0 # recognition_you_l.append(p.recognition_you) # if len(social_you_l): # recognition_you_mean = sum(recognition_you_l) / len(recognition_you_l) # else: # recognition_you_mean = 0 # recognition_others_l.append(p.recognition_others) # if len(social_you_l): # recognition_others_mean = sum(recognition_others_l) / len(recognition_others_l) # else: # recognition_others_mean = 0 # autonomy_you_l.append(p.autonomy_you) # if len(social_you_l): # autonomy_you_mean = sum(autonomy_you_l) / len(autonomy_you_l) # else: # autonomy_you_mean = 0 # autonomy_others_l.append(p.autonomy_others) # if len(social_you_l): # autonomy_others_mean = sum(autonomy_others_l) / len(autonomy_others_l) # else: # autonomy_others_mean = 0 # working_env_you_l.append(p.working_env_you) # if len(social_you_l): # working_env_you_mean = sum(working_env_you_l) / len(working_env_you_l) # else: # working_env_you_mean = 0 # working_env_others_l.append(p.working_env_others) # if len(social_you_l): # working_env_others_mean = sum(working_env_others_l) / len(working_env_others_l) # else: # working_env_others_mean = 0 return { 'number': number, 'social_you_mean': social_you_mean, 'social_you_list': social_you_l, 'social_others_mean': social_others_mean, 'social_others_list': social_others_l, 'money_you_mean': money_you_mean, 'money_you_list': money_you_l, 'money_others_mean': money_others_mean, 'money_others_list': money_others_l, 'recognition_you_mean': recognition_you_mean, 'recognition_you_list': recognition_you_l, 'recognition_others_mean': recognition_others_mean, 'recognition_others_list': recognition_others_l, 'autonomy_you_mean': autonomy_you_mean, 'autonomy_you_list': autonomy_you_l, 'autonomy_others_mean': autonomy_others_mean, 'autonomy_others_list': autonomy_others_l, 'working_env_you_mean': working_env_you_mean, 'working_env_you_list': working_env_you_l, 'working_env_others_mean': working_env_others_mean, 'working_env_others_list': working_env_others_l, } class Group(BaseGroup): pass class Player(BasePlayer): def set_payoff(self): """Calculate payoff, which is zero for the survey""" self.payoff = 0 # def make_field(label): # return models.PositiveIntegerField( # choices=range(0,10+1), # widget=widgets.RadioSelectHorizontal(), # verbose_name=label, # ) # # social_impact_you = make_field('Social impact (e.g., want to make a difference for the world)') # social_impact_others = make_field('Social impact (e.g., want to make a difference for the world)') # money_you = make_field('Social impact (e.g., want to make a difference for the world)') social_impact_you = models.PositiveIntegerField( choices=range(0,10+1), widget=widgets.RadioSelectHorizontal(), verbose_name='Social impact (e.g., want to make a difference for the world)') social_impact_others = models.PositiveIntegerField( choices=range(0,10+1), widget=widgets.RadioSelectHorizontal(), verbose_name='Social impact (e.g., want to make a difference for the world)') money_you = models.PositiveIntegerField( choices=range(0, 10 + 1), widget=widgets.RadioSelectHorizontal(), verbose_name='Money and prestige (e.g., reach high socio-economic status)') money_others = models.PositiveIntegerField( choices=range(0, 10 + 1), widget=widgets.RadioSelectHorizontal(), verbose_name='Money and prestige (e.g., reach high socio-economic status)') recognition_you = models.PositiveIntegerField( choices=range(0, 10 + 1), widget=widgets.RadioSelectHorizontal(), verbose_name='''Intellectual challenge & recognition (e.g., apply your skills and talent to solve a problem, being recognized for your competence)''') recognition_others = models.PositiveIntegerField( choices=range(0, 10 + 1), widget=widgets.RadioSelectHorizontal(), verbose_name='''Intellectual challenge & recognition (e.g., apply your skills and talent to solve a problem, being recognized for your competence)''') autonomy_you = models.PositiveIntegerField( choices=range(0, 10 + 1), widget=widgets.RadioSelectHorizontal(), verbose_name='''Autonomy (e.g., being able of making decisions, taking initiatives, being independent, organize your work as you like)''') autonomy_others = models.PositiveIntegerField( choices=range(0, 10 + 1), widget=widgets.RadioSelectHorizontal(), verbose_name='''Autonomy (e.g., being able of making decisions, taking initiatives, being independent, organize your work as you like)''') working_env_you = models.PositiveIntegerField( choices=range(0, 10 + 1), widget=widgets.RadioSelectHorizontal(), verbose_name='''Nice working environment (e.g., being treated fairly, getting along well with boss and colleagues, non-monetary perks like good mensa)''') working_env_others = models.PositiveIntegerField( choices=range(0, 10 + 1), widget=widgets.RadioSelectHorizontal(), verbose_name='''Nice working environment (e.g., being treated fairly, getting along well with boss and colleagues, non-monetary perks like good mensa)''')