from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'job_questionnaire' players_per_group = None num_rounds = 5 class Subsession(BaseSubsession): def creating_session(self): for p in self.get_players(): if self.round_number == 1: p.rated_company = random.choice(['Münchner Bank eG', 'Umweltbank AG']) if p.rated_company == 'Münchner Bank eG': p.company_description = "die älteste Genossenschaftsbank Bayerns" if p.rated_company == 'Umweltbank AG': p.company_description = "Deutschlands grünste Bank, die mit ihren Kundeneinlagen ausschließlich ökologische Kreditprojekte fördert" elif self.round_number == 2: p.rated_company = random.choice(['RWE AG', 'Innogy SE']) if p.rated_company == 'RWE AG': p.company_description = "ein Energieunternehmen mit Energieproduktion durch konventionelle fossile Kohle- und Gaskraftwerke" if p.rated_company == 'Innogy SE': p.company_description = "ein Energieunternehmen, das Energie aus erneuerbaren Quellen erzeugt, Verteilnetze betreibt und Energie vertreibt" elif self.round_number == 3: p.rated_company = random.choice(['Bestseller A/S', 'armedangels GmbH']) if p.rated_company == 'Bestseller A/S': p.company_description = "ein Textileinzelhandelsunternehmen, wozu u.a. die Marken Vero Moda, Only, Jack & Jones gehören" if p.rated_company == 'armedangels GmbH': p.company_description = "ein Modelabel, das nachhaltige Mode kreiert und produziert, die sowohl ethisch als auch modisch ist" elif self.round_number == 4: p.rated_company = random.choice(['Porsche AG', 'Tesla Inc.']) if p.rated_company == 'Porsche AG': p.company_description = "ein deutscher Kraftfahrzeughersteller, der vor allem Sportwagen produziert" if p.rated_company == 'Tesla Inc.': p.company_description = "ein Unternehmen, das Elektroautos sowie Stromspeicher- und Photovoltaikanlagen produziert" elif self.round_number == 5: p.rated_company = random.choice(['Interessenvertretung DEBRIV Bundesverband Braunkohle', 'Interessenvertretung Bund für Umwelt und Naturschutz - BUND e.V.']) if p.rated_company == 'Interessenvertretung DEBRIV Bundesverband Braunkohle': p.company_description = "der Branchenverband der deutschen Braunkohlewirtschaft" if p.rated_company == 'Interessenvertretung Bund für Umwelt und Naturschutz - BUND e.V.': p.company_description = "eine nichtstaatliche Umwelt- und Naturschutzorganisation, die für den Schutz unserer Natur und Umwelt eintritt." def set_payoffs(self): ### Choose random round ### random_round = random.randint(1,5) bonus_per_question = 1 ###################################################################################################### ### Create count variables which count how many votes each choice got ### salary_meaning_question_choice_1_count = 0 salary_meaning_question_choice_2_count = 0 salary_meaning_question_choice_3_count = 0 salary_meaning_question_choice_4_count = 0 salary_meaning_question_choice_5_count = 0 ### Count total votes for each choice ### players = self.get_players() for p in players: if p.in_round(random_round).salary_meaning_question == 1: salary_meaning_question_choice_1_count += 1 elif p.in_round(random_round).salary_meaning_question == 2: salary_meaning_question_choice_2_count += 1 elif p.in_round(random_round).salary_meaning_question == 3: salary_meaning_question_choice_3_count += 1 elif p.in_round(random_round).salary_meaning_question == 4: salary_meaning_question_choice_4_count += 1 elif p.in_round(random_round).salary_meaning_question == 5: salary_meaning_question_choice_5_count += 1 ### Find choice with most votes ### choice_frequencies = { "choice_1": salary_meaning_question_choice_1_count, "choice_2": salary_meaning_question_choice_2_count, "choice_3": salary_meaning_question_choice_3_count, "choice_4": salary_meaning_question_choice_4_count, "choice_5": salary_meaning_question_choice_5_count, } modus_choice = max(choice_frequencies, key=choice_frequencies.get) ### Check if player chose this choice ### for p in players: player_choice = p.in_round(random_round).salary_meaning_question if player_choice == 1: player_choice = "choice_1" elif player_choice == 2: player_choice = "choice_2" elif player_choice == 3: player_choice = "choice_3" elif player_choice == 4: player_choice = "choice_4" elif player_choice == 5: player_choice = "choice_5" if player_choice == modus_choice: p.payoff += c(bonus_per_question) ###################################################################################################### ### Create count variables which count how many votes each choice got ### competitiveness_question_choice_1_count = 0 competitiveness_question_choice_2_count = 0 competitiveness_question_choice_3_count = 0 competitiveness_question_choice_4_count = 0 competitiveness_question_choice_5_count = 0 ### Count total votes for each choice ### players = self.get_players() for p in players: if p.in_round(random_round).competitiveness_question == 1: competitiveness_question_choice_1_count += 1 elif p.in_round(random_round).competitiveness_question == 2: competitiveness_question_choice_2_count += 1 elif p.in_round(random_round).competitiveness_question == 3: competitiveness_question_choice_3_count += 1 elif p.in_round(random_round).competitiveness_question == 4: competitiveness_question_choice_4_count += 1 elif p.in_round(random_round).competitiveness_question == 5: competitiveness_question_choice_5_count += 1 ### Find choice with most votes ### choice_frequencies = { "choice_1": competitiveness_question_choice_1_count, "choice_2": competitiveness_question_choice_2_count, "choice_3": competitiveness_question_choice_3_count, "choice_4": competitiveness_question_choice_4_count, "choice_5": competitiveness_question_choice_5_count, } modus_choice = max(choice_frequencies, key=choice_frequencies.get) ### Check if player chose this choice ### for p in players: player_choice = p.in_round(random_round).competitiveness_question if player_choice == 1: player_choice = "choice_1" elif player_choice == 2: player_choice = "choice_2" elif player_choice == 3: player_choice = "choice_3" elif player_choice == 4: player_choice = "choice_4" elif player_choice == 5: player_choice = "choice_5" if player_choice == modus_choice: p.payoff += c(bonus_per_question) ###################################################################################################### ### Create count variables which count how many votes each choice got ### q1_choice_1_count = 0 q1_choice_2_count = 0 q1_choice_3_count = 0 q1_choice_4_count = 0 q1_choice_5_count = 0 ### Count total votes for each choice ### players = self.get_players() for p in players: if p.in_round(random_round).q1 == 1: q1_choice_1_count += 1 elif p.in_round(random_round).q1 == 2: q1_choice_2_count += 1 elif p.in_round(random_round).q1 == 3: q1_choice_3_count += 1 elif p.in_round(random_round).q1 == 4: q1_choice_4_count += 1 elif p.in_round(random_round).q1 == 5: q1_choice_5_count += 1 ### Find choice with most votes ### choice_frequencies = { "choice_1": q1_choice_1_count, "choice_2": q1_choice_2_count, "choice_3": q1_choice_3_count, "choice_4": q1_choice_4_count, "choice_5": q1_choice_5_count, } modus_choice = max(choice_frequencies, key=choice_frequencies.get) ### Check if player chose this choice ### for p in players: player_choice = p.in_round(random_round).q1 if player_choice == 1: player_choice = "choice_1" elif player_choice == 2: player_choice = "choice_2" elif player_choice == 3: player_choice = "choice_3" elif player_choice == 4: player_choice = "choice_4" elif player_choice == 5: player_choice = "choice_5" if player_choice == modus_choice: p.payoff += c(bonus_per_question) ###################################################################################################### ### Create count variables which count how many votes each choice got ### q2_choice_1_count = 0 q2_choice_2_count = 0 q2_choice_3_count = 0 q2_choice_4_count = 0 q2_choice_5_count = 0 ### Count total votes for each choice ### players = self.get_players() for p in players: if p.in_round(random_round).q2 == 1: q2_choice_1_count += 1 elif p.in_round(random_round).q2 == 2: q2_choice_2_count += 1 elif p.in_round(random_round).q2 == 3: q2_choice_3_count += 1 elif p.in_round(random_round).q2 == 4: q2_choice_4_count += 1 elif p.in_round(random_round).q2 == 5: q2_choice_5_count += 1 ### Find choice with most votes ### choice_frequencies = { "choice_1": q2_choice_1_count, "choice_2": q2_choice_2_count, "choice_3": q2_choice_3_count, "choice_4": q2_choice_4_count, "choice_5": q2_choice_5_count, } modus_choice = max(choice_frequencies, key=choice_frequencies.get) ### Check if player chose this choice ### for p in players: player_choice = p.in_round(random_round).q2 if player_choice == 1: player_choice = "choice_1" elif player_choice == 2: player_choice = "choice_2" elif player_choice == 3: player_choice = "choice_3" elif player_choice == 4: player_choice = "choice_4" elif player_choice == 5: player_choice = "choice_5" if player_choice == modus_choice: p.payoff += c(bonus_per_question) ###################################################################################################### ### Create count variables which count how many votes each choice got ### q3_choice_1_count = 0 q3_choice_2_count = 0 q3_choice_3_count = 0 q3_choice_4_count = 0 q3_choice_5_count = 0 ### Count total votes for each choice ### players = self.get_players() for p in players: if p.in_round(random_round).q3 == 1: q3_choice_1_count += 1 elif p.in_round(random_round).q3 == 2: q3_choice_2_count += 1 elif p.in_round(random_round).q3 == 3: q3_choice_3_count += 1 elif p.in_round(random_round).q3 == 4: q3_choice_4_count += 1 elif p.in_round(random_round).q3 == 5: q3_choice_5_count += 1 ### Find choice with most votes ### choice_frequencies = { "choice_1": q3_choice_1_count, "choice_2": q3_choice_2_count, "choice_3": q3_choice_3_count, "choice_4": q3_choice_4_count, "choice_5": q3_choice_5_count, } modus_choice = max(choice_frequencies, key=choice_frequencies.get) ### Check if player chose this choice ### for p in players: player_choice = p.in_round(random_round).q3 if player_choice == 1: player_choice = "choice_1" elif player_choice == 2: player_choice = "choice_2" elif player_choice == 3: player_choice = "choice_3" elif player_choice == 4: player_choice = "choice_4" elif player_choice == 5: player_choice = "choice_5" if player_choice == modus_choice: p.payoff += c(bonus_per_question) ###################################################################################################### ### Create count variables which count how many votes each choice got ### q4_choice_1_count = 0 q4_choice_2_count = 0 q4_choice_3_count = 0 q4_choice_4_count = 0 q4_choice_5_count = 0 ### Count total votes for each choice ### players = self.get_players() for p in players: if p.in_round(random_round).q4 == 1: q4_choice_1_count += 1 elif p.in_round(random_round).q4 == 2: q4_choice_2_count += 1 elif p.in_round(random_round).q4 == 3: q4_choice_3_count += 1 elif p.in_round(random_round).q4 == 4: q4_choice_4_count += 1 elif p.in_round(random_round).q4 == 5: q4_choice_5_count += 1 ### Find choice with most votes ### choice_frequencies = { "choice_1": q4_choice_1_count, "choice_2": q4_choice_2_count, "choice_3": q4_choice_3_count, "choice_4": q4_choice_4_count, "choice_5": q4_choice_5_count, } modus_choice = max(choice_frequencies, key=choice_frequencies.get) ### Check if player chose this choice ### for p in players: player_choice = p.in_round(random_round).q4 if player_choice == 1: player_choice = "choice_1" elif player_choice == 2: player_choice = "choice_2" elif player_choice == 3: player_choice = "choice_3" elif player_choice == 4: player_choice = "choice_4" elif player_choice == 5: player_choice = "choice_5" if player_choice == modus_choice: p.payoff += c(bonus_per_question) ###################################################################################################### ### Create count variables which count how many votes each choice got ### q5_choice_1_count = 0 q5_choice_2_count = 0 q5_choice_3_count = 0 q5_choice_4_count = 0 q5_choice_5_count = 0 ### Count total votes for each choice ### players = self.get_players() for p in players: if p.in_round(random_round).q5 == 1: q5_choice_1_count += 1 elif p.in_round(random_round).q5 == 2: q5_choice_2_count += 1 elif p.in_round(random_round).q5 == 3: q5_choice_3_count += 1 elif p.in_round(random_round).q5 == 4: q5_choice_4_count += 1 elif p.in_round(random_round).q5 == 5: q5_choice_5_count += 1 ### Find choice with most votes ### choice_frequencies = { "choice_1": q5_choice_1_count, "choice_2": q5_choice_2_count, "choice_3": q5_choice_3_count, "choice_4": q5_choice_4_count, "choice_5": q5_choice_5_count, } modus_choice = max(choice_frequencies, key=choice_frequencies.get) ### Check if player chose this choice ### for p in players: player_choice = p.in_round(random_round).q5 if player_choice == 1: player_choice = "choice_1" elif player_choice == 2: player_choice = "choice_2" elif player_choice == 3: player_choice = "choice_3" elif player_choice == 4: player_choice = "choice_4" elif player_choice == 5: player_choice = "choice_5" if player_choice == modus_choice: p.payoff += c(bonus_per_question) ###################################################################################################### ### Create count variables which count how many votes each choice got ### q6_choice_1_count = 0 q6_choice_2_count = 0 q6_choice_3_count = 0 q6_choice_4_count = 0 q6_choice_5_count = 0 ### Count total votes for each choice ### players = self.get_players() for p in players: if p.in_round(random_round).q6 == 1: q6_choice_1_count += 1 elif p.in_round(random_round).q6 == 2: q6_choice_2_count += 1 elif p.in_round(random_round).q6 == 3: q6_choice_3_count += 1 elif p.in_round(random_round).q6 == 4: q6_choice_4_count += 1 elif p.in_round(random_round).q6 == 5: q6_choice_5_count += 1 ### Find choice with most votes ### choice_frequencies = { "choice_1": q6_choice_1_count, "choice_2": q6_choice_2_count, "choice_3": q6_choice_3_count, "choice_4": q6_choice_4_count, "choice_5": q6_choice_5_count, } modus_choice = max(choice_frequencies, key=choice_frequencies.get) ### Check if player chose this choice ### for p in players: player_choice = p.in_round(random_round).q6 if player_choice == 1: player_choice = "choice_1" elif player_choice == 2: player_choice = "choice_2" elif player_choice == 3: player_choice = "choice_3" elif player_choice == 4: player_choice = "choice_4" elif player_choice == 5: player_choice = "choice_5" if player_choice == modus_choice: p.payoff += c(bonus_per_question) ###################################################################################################### ### Create count variables which count how many votes each choice got ### q7_choice_1_count = 0 q7_choice_2_count = 0 q7_choice_3_count = 0 q7_choice_4_count = 0 q7_choice_5_count = 0 ### Count total votes for each choice ### players = self.get_players() for p in players: if p.in_round(random_round).q7 == 1: q7_choice_1_count += 1 elif p.in_round(random_round).q7 == 2: q7_choice_2_count += 1 elif p.in_round(random_round).q7 == 3: q7_choice_3_count += 1 elif p.in_round(random_round).q7 == 4: q7_choice_4_count += 1 elif p.in_round(random_round).q7 == 5: q7_choice_5_count += 1 ### Find choice with most votes ### choice_frequencies = { "choice_1": q7_choice_1_count, "choice_2": q7_choice_2_count, "choice_3": q7_choice_3_count, "choice_4": q7_choice_4_count, "choice_5": q7_choice_5_count, } modus_choice = max(choice_frequencies, key=choice_frequencies.get) ### Check if player chose this choice ### for p in players: player_choice = p.in_round(random_round).q7 if player_choice == 1: player_choice = "choice_1" elif player_choice == 2: player_choice = "choice_2" elif player_choice == 3: player_choice = "choice_3" elif player_choice == 4: player_choice = "choice_4" elif player_choice == 5: player_choice = "choice_5" if player_choice == modus_choice: p.payoff += c(bonus_per_question) class Group(BaseGroup): pass def create_skill_question(label): return models.IntegerField( choices = [ [1, ""], [2, ""], [3, ""], [4, ""], [5, ""] ], label = label, widget = widgets.RadioSelectHorizontal, ) class Player(BasePlayer): rated_company = models.TextField() company_description = models.TextField() salary_meaning_question = models.IntegerField( choices = [ [1, ""], [2, ""], [3, ""], [4, ""], [5, ""], ], widget = widgets.RadioSelectHorizontal ) competitiveness_question = models.IntegerField( choices = [ [1, ""], [2, ""], [3, ""], [4, ""], [5, ""], ], widget = widgets.RadioSelectHorizontal ) q1 = create_skill_question("Kommunikationsfähigkeit (auch in anderen Sprachen)") q2 = create_skill_question("Teamfähigkeit") q3 = create_skill_question("Interkulturelle Kompetenz") q4 = create_skill_question("Konfliktfähigkeit") q5 = create_skill_question("Leistungsbereitschaft und Ergebnisorientierung") q6 = create_skill_question("Selbstvertrauen") q7 = create_skill_question("Kreativität, Flexibilität und Innovationsfähigkeit")