from otree.api import * doc = """ PANAS (positive and negative affect schedule) """ class Constants(BaseConstants): name_in_url = 'panas' players_per_group = None num_rounds = 1 fields = [ 'interested', 'distressed', 'excited', 'upset', 'strong', 'guilty', 'scared', 'hostile', 'enthusiastic', 'proud', 'irritable', 'alert', 'ashamed', 'inspired', 'nervous', 'determined', 'attentive', 'jittery', 'active', 'afraid', ] positive_fields = [ 'interested', 'excited', 'strong', 'enthusiastic', 'proud', 'alert', 'inspired', 'determined', 'attentive', 'active', ] negative_fields = [ 'distressed', 'upset', 'guilty', 'scared', 'hostile', 'irritable', 'ashamed', 'nervous', 'jittery', 'afraid', ] # make sure each field is counted exactly once assert sorted(fields) == sorted(positive_fields + negative_fields) class Subsession(BaseSubsession): pass class Group(BaseGroup): pass def make_q(label): return models.IntegerField(label=label, choices=[1, 2, 3, 4, 5], widget=widgets.RadioSelect) class Player(BasePlayer): interested = make_q('Interested') distressed = make_q('Distressed') excited = make_q('Excited') upset = make_q('Upset') strong = make_q('Strong') guilty = make_q('Guilty') scared = make_q('Scared') hostile = make_q('Hostile') enthusiastic = make_q('Enthusiastic') proud = make_q('Proud') irritable = make_q('Irritable') alert = make_q('Alert') ashamed = make_q('Ashamed') inspired = make_q('Inspired') nervous = make_q('Nervous') determined = make_q('Determined') attentive = make_q('Attentive') jittery = make_q('Jittery') active = make_q('Active') afraid = make_q('Afraid') positive_affect_score = models.IntegerField() negative_affect_score = models.IntegerField() # PAGES class Survey(Page): form_model = 'player' form_fields = Constants.fields @staticmethod def before_next_page(player: Player, timeout_happened): player.positive_affect_score = sum(getattr(player, f) for f in Constants.positive_fields) player.negative_affect_score = sum(getattr(player, f) for f in Constants.negative_fields) class Results(Page): pass page_sequence = [Survey, Results]