from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import numpy as np author = 'Alexander Schneeberger' doc = """ Moral Foundations Questionaire """ class Constants(BaseConstants): name_in_url = 'MFQ' players_per_group = None num_rounds = 1 # Choice Set choices_1 = [ [5, 'Extremely relevant'], [4, 'Very relevant'], [3, 'Somewhat relevant'], [2, 'Slightly relevant'], [1, 'Not very relevant'], [0, 'Not at all relevant'], ] choices_2 = [ [5, 'Strongly agree'], [4, 'Moderately agree'], [3, 'Slightly agree'], [2, 'Slightly disagree'], [1, 'Moderately disagree'], [0, 'Strongly disagree'], ] class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): # Input - Indicate how relevant to morality Q1 = models.IntegerField(choices=Constants.choices_1) Q2 = models.IntegerField(choices=Constants.choices_1) Q3 = models.IntegerField(choices=Constants.choices_1) Q5 = models.IntegerField(choices=Constants.choices_1) Q6 = models.IntegerField(choices=Constants.choices_1) Q7 = models.IntegerField(choices=Constants.choices_1) Q8 = models.IntegerField(choices=Constants.choices_1) Q9 = models.IntegerField(choices=Constants.choices_1) Q11 = models.IntegerField(choices=Constants.choices_1) Q12 = models.IntegerField(choices=Constants.choices_1) Q13 = models.IntegerField(choices=Constants.choices_1) Q14 = models.IntegerField(choices=Constants.choices_1) Q16 = models.IntegerField(choices=Constants.choices_1) # Input - Indicate agreement or disagreement Q17 = models.IntegerField(choices=Constants.choices_2) Q18 = models.IntegerField(choices=Constants.choices_2) Q19 = models.IntegerField(choices=Constants.choices_2) Q21 = models.IntegerField(choices=Constants.choices_2) Q22 = models.IntegerField(choices=Constants.choices_2) Q23 = models.IntegerField(choices=Constants.choices_2) Q24 = models.IntegerField(choices=Constants.choices_2) Q25 = models.IntegerField(choices=Constants.choices_2) Q27 = models.IntegerField(choices=Constants.choices_2) Q28 = models.IntegerField(choices=Constants.choices_2) Q29 = models.IntegerField(choices=Constants.choices_2) Q30 = models.IntegerField(choices=Constants.choices_2) Q32 = models.IntegerField(choices=Constants.choices_2) # Background Harm = models.FloatField() Fairness = models.FloatField() Ingroup = models.FloatField() Purity = models.FloatField() Individualism = models.FloatField() Communalism = models.FloatField() Progressivism = models.FloatField() # Functions def calculate_scores(self): self.Harm = np.mean([self.Q1, self.Q7, self.Q12, self.Q17, self.Q23, self.Q28]) self.Fairness = np.mean([self.Q2, self.Q8, self.Q13, self.Q18, self.Q24, self.Q29]) self.Ingroup = np.mean([self.Q3, self.Q9, self.Q14, self.Q19, self.Q25, self.Q30]) self.Purity = np.mean([self.Q5, self.Q11, self.Q16, self.Q21, self.Q27, self.Q32]) self.Individualism = np.mean([self.Harm, self.Fairness]) self.Communalism = np.mean([self.Ingroup, self.Purity]) self.Progressivism = self.Individualism - self.Communalism