from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants class Instructions(Page): pass class Nutrition1(Page): form_model = 'player' form_fields = ['s1q1a', 's1q1b', 's1q1c', 's1q1d', 's1q1e', 's1q1f', 's1q1g', 's1q2' , 's1q3' , 's1q4' , 's1q5a', 's1q5b', 's1q5c', 's1q5d', 's1q5e', 's1q5f', 's1q5g', 's1q6'] class Nutrition2(Page): form_model = 'player' form_fields = [ 's2q1a', 's2q1b', 's2q1c', 's2q1d', 's2q1e', 's2q1f', 's2q1g', 's2q1h', 's2q1i', 's2q2' , 's2q3a', 's2q3b', 's2q3c'] # Function to count number of correct answers: def before_next_page(self): p = self.player p.total_correct = 0 for k, v in Constants.correct_answers_set2.items(): if getattr(p, k) == v: p.total_correct += 1 self.participant.vars['tot_correct'] = p.total_correct class Nutrition3(Page): form_model = 'player' form_fields = ['s3q1a', 's3q1b', 's3q1c', 's3q1d', 's3q1e', 's3q2a', 's3q2b', 's3q2c', 's3q2d', 's3q2e', 's3q2f', 's3q3a', 's3q3b', 's3q3c', 's3q3d', 's3q3e', 's3q3f', 's3q4a', 's3q4b', 's3q4c', 's3q4d', 's3q4e','s3q4f', 's3q5' , 's3q6', 's3q7a', 's3q7b', 's3q7c', 's3q7d','s3q8', 's3q9', 's3q10a', 's3q10b', 's3q10c', 's3q10d', 's3q10e', 's3q11'] # Function to count number of correct answers: def before_next_page(self): p = self.player p.total_correct = 0 for k, v in Constants.correct_answers_set3.items(): if getattr(p, k) == v: p.total_correct += 1 self.participant.vars['tot_correct'] = p.total_correct + self.participant.vars['tot_correct'] class Nutrition4(Page): form_model = 'player' form_fields = ['s4q1', 's4q2', 's4q3', 's4q4', 's4q5', 's4q6', 's4q7', 's4q8', 's4q9'] # Function to count number of correct answers: def before_next_page(self): p = self.player p.total_correct = 0 for k, v in Constants.correct_answers_set4.items(): if getattr(p, k) == v: p.total_correct += 1 self.participant.vars['tot_correct'] = p.total_correct + self.participant.vars['tot_correct'] p.nk_score = round(self.participant.vars['tot_correct']/57, 2) self.participant.vars['nk_score'] = p.nk_score class Scenarios1(Page): def is_displayed(self): return self.player.option == 1 form_model = 'player' form_fields = ['g1A', 'g1B', 'g1C', 'g2A', 'g2B', 'g2C'] # Function to count number of correct answers: class Scenarios2(Page): form_model = 'player' form_fields = ['g1A', 'g1B', 'g1C', 'g2A', 'g2B', 'g2C'] def is_displayed(self): return self.player.option == 2 class OtherQuestions(Page): form_model = 'player' form_fields = ['health', 'primary_shopper', 'loan', 'job', 'partner', 'obese', 'overweight', 'underweight'] def vars_for_template(self): image = Constants.sil_pic return {'image': image} page_sequence = [ Instructions, Nutrition1, Nutrition2, Nutrition3, Nutrition4, Scenarios1, Scenarios2, OtherQuestions, ]