from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants from random import shuffle from .iat_category_words import word_bundles from sel_measures import iat_blocks LEFT, RIGHT = iat_blocks.LEFT, iat_blocks.RIGHT FIRST, SECOND = iat_blocks.LEFT, iat_blocks.RIGHT class TaskCInstructions(Page): template_name = 'sel_measures/CreativityInstructions.html' def is_displayed(self): return not self.participant.vars.get('is_teacher') class TaskC(Page): template_name = 'sel_measures/Creativity.html' timeout_seconds = 60 * Constants.creativity_min_for_task timer_text = "Remaining time" form_model = 'player' form_fields = ['creativity'] def is_displayed(self): return not self.participant.vars.get('is_teacher') class TaskIInstructions(Page): template_name = 'sel_measures/IATIntroduction.html' def vars_for_template(self): vars_to_return = {} main_category_keys = list(word_bundles[self.player.iat_version]['main_category'].keys()) sub_category_keys = list(word_bundles[self.player.iat_version]['sub_category'].keys()) vars_to_return['main_categories'] = main_category_keys vars_to_return['sub_categories'] = sub_category_keys index = 0 for main_key in main_category_keys: index += 1 key = 'main_' + str(index) vars_to_return[key] = main_key key += '_keywords' vars_to_return[key] = word_bundles[self.player.iat_version]['main_category'][main_key] index = 0 for sub_key in sub_category_keys: index += 1 key = 'sub_' + str(index) vars_to_return[key] = sub_key key += '_keywords' vars_to_return[key] = word_bundles[self.player.iat_version]['sub_category'][sub_key] return vars_to_return def before_next_page(self): self.participant.vars['blocks'] = iat_blocks.Blocks(self.player.iat_version) class TaskI(Page): template_name = 'sel_measures/IAT.html' def vars_for_template(self): blocks = [[i for i in b.iat_items] for b in self.participant.vars['blocks'].iat_block_list] correct_sides = [[cs for cs in b.correct_side] for b in self.participant.vars['blocks'].iat_block_list] categories_names_from_blocks = [b.get_category_names() for b in self.participant.vars['blocks'].iat_block_list] categories_names = [] for b in categories_names_from_blocks: categories_for_block = {'main': {'left': None, 'right': None}, 'sub': {'left': None, 'right': None}} for c, v in b.items(): if 'left_main' in c: categories_for_block['main']['left'] = v elif 'right_main' in c: categories_for_block['main']['right'] = v elif 'left_sub' in c: categories_for_block['sub']['left'] = v elif 'right_sub' in c: categories_for_block['sub']['right'] = v categories_names.append(categories_for_block) if self.participant.vars.setdefault('is_mobile', self.request.user_agent.is_mobile) or \ self.participant.vars.setdefault('is_tablet', self.request.user_agent.is_tablet): is_touch = True else: is_touch = False vars_for_return = { 'blocks': blocks, 'correct_sides': correct_sides, 'categories_names': categories_names, 'is_touch': is_touch, 'iat_tables': 'iat_tables' } default_iat_block = iat_blocks.Block(iat_blocks.Blocks.block_set['both'], self.player.iat_version) category_names = default_iat_block.get_category_names() word_bundle = word_bundles[self.player.iat_version] vars_for_return['main_items'] = word_bundle['main_category'][category_names['left_main_category']] \ + word_bundle['main_category'][category_names['right_main_category']] vars_for_return['sub_items'] = word_bundle['sub_category'][category_names['left_sub_category']] \ + word_bundle['sub_category'][category_names['right_sub_category']] # vars_for_return['seed_for_refresh_js_cache'] = random.random() # TODO: delete after production vars_for_return['seed_for_refresh_js_cache'] = 0 return vars_for_return form_model = 'player' form_fields = ['iat_tables'] class TaskTrDecision(Page): template_name = 'sel_measures/TrolleyProblem.html' form_model = 'player' form_fields = ['trolley_decision'] class TaskADecision(Page): template_name = 'sel_measures/AmbiguityDecision.html' form_model = 'player' form_fields = ['ambiguity_decision'] def before_next_page(self): self.player.set_ambiguity_payoff() class TaskBF(Page): template_name = 'sel_measures/BigFive.html' form_model = 'player' form_fields = Constants.bigfive_items def vars_for_template(self): touch = False if self.participant.vars.setdefault('is_mobile', self.request.user_agent.is_mobile) or \ self.participant.vars.setdefault('is_tablet', self.request.user_agent.is_tablet): touch = True return {'touch': touch} def is_displayed(self): return not self.participant.vars.get('is_teacher') class TaskGInstructions(Page): template_name = 'sel_measures/GritInstructions.html' form_model = 'player' form_fields = ['grit_decision'] class TaskG(Page): template_name = 'sel_measures/GritTask.html' timeout_seconds = 60 * Constants.grit_time_for_task form_model = 'player' form_fields = ['grit_num_correct'] def before_next_page(self): self.player.set_grit_payoff() class TaskGResults(Page): template_name = 'sel_measures/GritFeedback.html' class RsQuestions(Page): template_name = 'sel_measures/RiskyBehaviour.html' form_model = 'player' form_fields = ['risky_smoke', 'risky_drink'] def is_displayed(self): return not self.participant.vars.get('is_teacher') class TaskScDecision(Page): template_name = 'sel_measures/SelfConfidenceDecision.html' form_model = 'player' form_fields = ['self_confidence', 'ses_no', 'math_no'] def is_displayed(self): return not self.participant.vars.get('is_teacher') def vars_for_template(self): if self.participant.vars.get('year') == 1: topics = ['French', 'Mathematics', 'Numerical Sciences and Technology', 'Economic and Social Sciences'] topics_labels = ['French', 'Mathematics', 'Digital_Sciences_and_Technology', 'Economic_and_Social_Sciences'] elif self.participant.vars.get('year') == 2: topics = ['French', 'Sciences', 'Economic and Social Sciences'] topics_labels = ['French', 'Sciences', 'Economics and Social sciences'] else: topics = ['Philosophy', 'Mathematics', 'Economic_and_Social_Sciences'] topics_labels = ['Philosophy', 'Mathematics', 'Economic_and_Social_Sciences'] tt = list(zip(topics, topics_labels)) touch = False if self.participant.vars.setdefault('is_mobile', self.request.user_agent.is_mobile) or \ self.participant.vars.setdefault('is_tablet', self.request.user_agent.is_tablet): touch = True return {'topics': tt, 'topics_labels': topics_labels, 'is_in_year': self.participant.vars.get('year'), 'touch': touch} class TaskWDecision(Page): template_name = 'sel_measures/WasonDecision.html' form_model = 'player' form_fields = [f'wason_card_{c}' for c in Constants.wason_cards] def vars_for_template(self): return { 'cards': [(f'wason_card_{c}', c.upper()) for c in Constants.wason_cards] } def before_next_page(self): self.player.set_wason_is_correct() class TaskGngInstructions(Page): template_name = 'sel_measures/GoNoGoInstructions.html' def vars_for_template(self): if self.participant.vars.setdefault('is_mobile', self.request.user_agent.is_mobile) or \ self.participant.vars.setdefault('is_tablet', self.request.user_agent.is_tablet): is_touch = True command_type = 'gray area' else: is_touch = False command_type = "space bar" return { 'is_touch': is_touch, 'command_type': command_type } class TaskGng(Page): template_name = 'sel_measures/GoNoGoTask.html' form_model = 'player' form_fields = ['gonogo_trials'] def vars_for_template(self): if self.participant.vars.setdefault('is_mobile', self.request.user_agent.is_mobile) or \ self.participant.vars.setdefault('is_tablet', self.request.user_agent.is_tablet): is_touch = True command_type = 'gray area' else: is_touch = False command_type = "space bar" return { 'trials': self.participant.vars['gonogo_trials'], 'is_touch': is_touch, 'command_type': command_type } class TaskEm(Page): template_name = 'sel_measures/Empathy.html' form_model = 'player' form_fields = [f'empathy_{n}' for n in range(len(Constants.empathy_labels))] def vars_for_template(self): touch = False if self.participant.vars.setdefault('is_mobile', self.request.user_agent.is_mobile) or \ self.participant.vars.setdefault('is_tablet', self.request.user_agent.is_tablet): touch = True return {'touch': touch} def is_displayed(self): return not self.participant.vars.get('is_teacher') class TaskCr(Page): template_name = 'sel_measures/Curiosity.html' form_model = 'player' form_fields = [f'curiosity_{n}' for n in range(len(Constants.curiosity_labels))] def vars_for_template(self): touch = False if self.participant.vars.setdefault('is_mobile', self.request.user_agent.is_mobile) or \ self.participant.vars.setdefault('is_tablet', self.request.user_agent.is_tablet): touch = True return {'touch': touch} def is_displayed(self): return not self.participant.vars.get('is_teacher') def before_next_page(self): players_with_text = self.subsession.player_set.exclude(id_in_group=self.player.id_in_group)\ .filter(creativity__isnull=False).order_by('creativity_num_evaluations') if len(players_with_text) >= 2: self.participant.vars['do_rating_creativity'] = True texts_pair = players_with_text[:2] shuffle(texts_pair) self.player.rating_text_left = texts_pair[0].id_in_subsession self.player.rating_text_right = texts_pair[1].id_in_subsession else: self.participant.vars['do_rating_creativity'] = False class RatingCInstructions(Page): def is_displayed(self): if self.participant.vars.get('do_rating_creativity') and not self.participant.vars.get('is_teacher'): return True else: return False class RatingC(Page): form_model = 'player' form_fields = ['creativity_rating'] def is_displayed(self): if self.participant.vars.get('do_rating_creativity') and not self.participant.vars.get('is_teacher'): return True else: return False def vars_for_template(self): left_text = next(p for p in self.subsession.get_players() if p.id_in_subsession == self.player.rating_text_left) right_text = next(p for p in self.subsession.get_players() if p.id_in_subsession == self.player.rating_text_right) names = False left_name = None right_name = None if self.player.creativity_rating_see_names: if left_text.participant.vars.get('data'): if left_text.participant.vars.get('data').get('not_in_db') is not False: left_name = left_text.participant.vars['data']['first_name'] if right_text.participant.vars.get('data'): if right_text.participant.vars.get('data').get('not_in_db') is not False: right_name = right_text.participant.vars['data']['first_name'] if left_name and right_name: names = True return { 'names': names, 'left_name': left_name, 'right_name': right_name, 'text_left': left_text.creativity, 'text_right': right_text.creativity } def before_next_page(self): left_text = next(p for p in self.subsession.get_players() if p.id_in_subsession == self.player.rating_text_left) right_text = next(p for p in self.subsession.get_players() if p.id_in_subsession == self.player.rating_text_right) left_text.creativity_num_evaluations += 1 right_text.creativity_num_evaluations += 1 class RatingCEstimationInstructions(Page): def is_displayed(self): if self.participant.vars.get('do_rating_creativity') and self.player.creativity_rating_with_incentive and not self.participant.vars.get('is_teacher'): return True else: return False class RatingCEstimation(Page): form_model = 'player' form_fields = ['creativity_rating_estimate'] def is_displayed(self): if self.participant.vars.get('do_rating_creativity') and self.player.creativity_rating_with_incentive and not self.participant.vars.get('is_teacher'): return True else: return False def vars_for_template(self): left_text = next(p for p in self.subsession.get_players() if p.id_in_subsession == self.player.rating_text_left) right_text = next(p for p in self.subsession.get_players() if p.id_in_subsession == self.player.rating_text_right) return { 'text_left': left_text.creativity, 'text_right': right_text.creativity } class Tech(Page): form_model = 'player' form_fields = ['technical_issues', 'distractions'] class Email(Page): form_model = 'player' form_fields = ['email'] def vars_for_template(self): return { 'is_creteil': self.participant.vars.get('is_creteil'), 'is_teacher': self.participant.vars.get('is_teacher') } class Comments(Page): form_model = 'player' form_fields = ['comments'] class GoodBye(Page): def vars_for_template(self): tasks_with_payoff = ['ambiguity', 'grit'] self.player.payoff = sum( p for p in [getattr(self.player, t + '_payoff') for t in tasks_with_payoff] if p is not None) return {'total_credits_so_far': self.player.payoff, 'is_creteil': self.participant.vars.get('is_creteil')} page_sequence = [ TaskCInstructions, TaskC, TaskIInstructions, TaskI, TaskTrDecision, TaskADecision, TaskBF, TaskGInstructions, TaskG, TaskGResults, RsQuestions, TaskScDecision, TaskWDecision, TaskGngInstructions, TaskGng, TaskEm, TaskCr, RatingCInstructions, RatingC, RatingCEstimationInstructions, RatingCEstimation, Tech, Email, Comments, GoodBye ]