import random from django.utils.translation import gettext as _ from settings import LANGUAGE_CODE from ._builtin import Page from ._builtin import WaitPage from .models import Constants # Mother classes ======================================================================================================= class MyPage(Page): def vars_for_template(self): return dict( language=LANGUAGE_CODE ) def js_vars(self): return dict( fill_auto=self.session.config.get("fill_auto", False), language=LANGUAGE_CODE ) class MyGamePage(Page): def vars_for_template(self): total = 8 * Constants.a - 64 * Constants.b - 8 * (Constants.c + 30 * Constants.k) if LANGUAGE_CODE == "fr": instructions_example = ( f"Supposons que vous extrayez 8 jetons et que votre groupe extrait au total 30 jetons.\n " f"Votre gain sera égal à " f"\(({Constants.a} \\times 8 - {Constants.b} \\times 64) - (8 \\times ({Constants.c} + {Constants.k} \\times 30)) = {total}\) " f"ECU.") else: instructions_example = ( f"Suppose you extract 8 tokens and your group extract a total of 30 tokens.\n " f"Your payoff will be equal to " f"\(({Constants.a} \\times 8 - {Constants.b} \\times 64) - (8 \\times ({Constants.c} + {Constants.k} \\times 30)) = {total}\) " f"ECU.") minutes, secondes = divmod(Constants.communication_time, 60) communication_time = f"{minutes} minutes" if secondes > 0: communication_time += f" et {secondes} secondes" if LANGUAGE_CODE == "fr" else f" and {secondes} seconds" return dict( instructions_example=instructions_example, communication_time=communication_time, max_others=Constants.max_others, language=LANGUAGE_CODE ) def js_vars(self): return dict( fill_auto=self.session.config.get("fill_auto", False), max_extraction=Constants.max_extraction, max_others=Constants.max_others, a=Constants.a, b=Constants.b, c=Constants.c, k=Constants.k, players_per_group=Constants.players_per_group, language=LANGUAGE_CODE, decision_time=Constants.decision_time, result_time=Constants.result_time ) class MyQuestionnairePage(Page): def vars_for_template(self): return dict( language=LANGUAGE_CODE ) def js_vars(self): return dict( fill_auto=self.session.config.get("fill_auto", False), language=LANGUAGE_CODE ) # ====================================================================================================================== class WaitForPairing(WaitPage): group_by_arrival_time = True def is_displayed(self): return self.round_number == 1 class Instructions(MyGamePage): def is_displayed(self): return self.round_number == 1 class InstructionsWaitMonitor(MyGamePage): def is_displayed(self): return self.round_number == 1 and self.session.config.get("instructions_relues", False) class InstructionsWaitForAll(WaitPage): def is_displayed(self): return self.round_number == 1 class Communication(MyGamePage): timeout_seconds = Constants.communication_time timer_text = _("Remaining time") + " : " def is_displayed(self): return self.round_number == 1 and self.subsession.communication class Decision(MyGamePage): form_model = "player" form_fields = ["extraction"] class DecisionWaitForGroup(WaitPage): wait_for_all_groups = False after_all_players_arrive = "set_group_extraction_and_payoffs" class Results(MyGamePage): pass class ResultsWaitForAll(WaitPage): wait_for_all_groups = True class Final(MyGamePage): def is_displayed(self): return self.round_number == Constants.num_rounds class Questionnaire1(MyQuestionnairePage): form_model = "player" def get_form_fields(self): form_fields = ["part_or_excluded", "proud_or_shame", "committed", "motivated_for_coordination", "group_or_individual_pursue", "acted_for_group_or_perso", "follow_group"] random.shuffle(form_fields) return form_fields def is_displayed(self): return self.round_number == Constants.num_rounds class Questionnaire2(MyPage): form_model = "player" def get_form_fields(self): form_fields = [ 'game_emotion_1', 'game_emotion_2', 'game_emotion_3', 'game_Friendly', 'game_Respectful', 'game_Sympathy', 'game_CloseFeelings', 'game_Proud', 'game_Superior', 'game_Selfesteem', 'game_Topworld', 'game_Guilty', 'game_Indebted', 'game_Afraid', 'game_Ashamed', 'game_Disappointed', 'game_Frustrated', 'game_Angry', 'game_Sad'] random.shuffle(form_fields) return form_fields def is_displayed(self): return self.round_number == Constants.num_rounds class Questionnaire3(MyPage): form_model = "player" form_fields = ["game_part_of_group_scale", "game_part_of_group_img"] def is_displayed(self): return self.round_number == Constants.num_rounds class Questionnaire4(MyPage): form_model = "player" def get_form_fields(self): form_fields = [ 'game_Trustworthy', 'game_Fair', 'game_Selfish', 'game_Cooperative', 'game_Competitive', 'game_Understanding', 'game_Caring', 'game_Envious', 'game_Altruistic', 'game_Empathetic'] random.shuffle(form_fields) return form_fields def is_displayed(self): return self.round_number == Constants.num_rounds class Questionnaire5(MyPage): form_model = "player" def get_form_fields(self): form_fields = [ 'game_Trustworthy_others', 'game_Fair_others', 'game_Selfish_others', 'game_Cooperative_others', 'game_Competitive_others', 'game_Understanding_others', 'game_Caring_others', 'game_Envious_others', 'game_Altruistic_others', 'game_Empathetic_others', 'game_feel_others_behave', 'game_feel_others_influence', 'game_feel_others_reciprocity' ] random.shuffle(form_fields) return form_fields def is_displayed(self): return self.round_number == Constants.num_rounds class Questionnaire6(MyPage): form_model = "player" def get_form_fields(self): form_fields = ["game_communication_facility", "game_communication_clear", "game_communication_useful"] random.shuffle(form_fields) return form_fields def is_displayed(self): return self.round_number == Constants.num_rounds and self.subsession.communication page_sequence = [ WaitForPairing, Instructions, InstructionsWaitMonitor, InstructionsWaitForAll, Communication, Decision, DecisionWaitForGroup, Results, ResultsWaitForAll, Final, Questionnaire1, Questionnaire2, Questionnaire3, Questionnaire4, Questionnaire5, Questionnaire6 ]