from otree.api import * import csv from email_validator import validate_email, EmailNotValidError import random class C(BaseConstants): NAME_IN_URL = 'Treatments' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): language = models.StringField( label="Which language do you prefer?", choices=["English", "German", "Arabic", "Farsi"], widget=widgets.RadioSelect, ) IDPlayer = models.StringField() treatmentGroup = models.IntegerField() MoreInformations = models.StringField( label="", choices=["Ja", "Nein"], widget=widgets.RadioSelect, blank=True ) Randompages = models.IntegerField() # Umfrage 1 Umfrage1Bundesregierung = models.StringField( label="", blank=True ) Umfrage1Bundestag = models.StringField( label="", blank=True ) Umfrage1Justiz = models.StringField( label="", blank=True ) Umfrage1Polizei = models.StringField( label="", blank=True ) Umfrage2Anlaufstelle = models.StringField( label="", blank=True ) Umfrage3BesserGehen = models.StringField( label="", blank=True ) Umfrage3Ueberfluessig = models.StringField( label="", blank=True ) Umfrage3Bekaempfen = models.StringField( label="", blank=True ) Umfrage4Arbeitsplatz = models.StringField( label="", blank=True ) Umfrage4Kampagne = models.StringField( label="", blank=True ) Umfrage4OnlineNachricht = models.StringField( label="", blank=True ) Umfrage4Verteidigen = models.StringField( label="", blank=True ) Umfrage5Muslim = models.StringField( label="", blank=True ) Umfrage5Trans = models.StringField( label="", blank=True ) Umfrage5Behinderung = models.StringField( label="", blank=True ) Umfrage6Gesetz = models.StringField( label="", choices=['Ja', 'Nein', 'KeineAhnung'], widget=widgets.RadioSelectHorizontal, blank=True ) Umfrage7Antidiskriminierungsstelle = models.StringField( label="", choices=['Ja', 'Nein', 'KeineAhnung'], widget=widgets.RadioSelectHorizontal, blank=True ) URLGeklickt = models.StringField( label="", blank=True, ) Email = models.StringField( label="", blank=True, ) class Languages(Page): form_model = 'player' form_fields = ["language"] @staticmethod def before_next_page(player: Player, timeout_happened): with open('participants_data.csv', encoding='utf-8-sig') as f: rows = list(csv.DictReader(f)) for row in rows: if row['ID'] == player.participant.label: player.IDPlayer = str(row['ID']) player.treatmentGroup = int(row['TreatmentGroup']) class Seite1(Page): form_field = ["Randompages"] @staticmethod def before_next_page(player: Player, timeout_happened): player.Randompages = random.randint(1, 6) class Seite3_Weitere_Informationen(Page): form_model = 'player' form_fields = ["MoreInformations"] @staticmethod def js_vars(player: Player): return { "PlayerLanguage": player.language } @staticmethod def is_displayed(player: Player): if player.treatmentGroup == 2 or player.treatmentGroup == 4 or player.treatmentGroup == 6: return True else: return False class Seite4(Page): pass class Umfrage1(Page): form_model = 'player' form_fields = ['Umfrage1Bundesregierung', 'Umfrage1Bundestag', 'Umfrage1Justiz', 'Umfrage1Polizei'] @staticmethod def vars_for_template(player: Player): zahlen = [1, 2, 3, 4] random.shuffle(zahlen) zahl1, zahl2, zahl3, zahl4 = zahlen return{ "Zahl1": zahl1, "Zahl2": zahl2, "Zahl3": zahl3, "Zahl4": zahl4 } class Umfrage2(Page): form_model = 'player' form_fields = ['Umfrage2Anlaufstelle'] class Umfrage3(Page): form_model = 'player' form_fields = ['Umfrage3BesserGehen', 'Umfrage3Ueberfluessig', 'Umfrage3Bekaempfen'] @staticmethod def vars_for_template(player: Player): zahlen = [5, 6, 7] random.shuffle(zahlen) zahl5, zahl6, zahl7 = zahlen return { "Zahl5": zahl5, "Zahl6": zahl6, "Zahl7": zahl7, } @staticmethod def is_displayed(player: Player): if player.Randompages == 1: return True else: return False class Umfrage3A(Page): form_model = 'player' form_fields = ['Umfrage3BesserGehen', 'Umfrage3Ueberfluessig', 'Umfrage3Bekaempfen'] @staticmethod def vars_for_template(player: Player): zahlen = [5, 6, 7] random.shuffle(zahlen) zahl5, zahl6, zahl7 = zahlen return { "Zahl5": zahl5, "Zahl6": zahl6, "Zahl7": zahl7, } @staticmethod def is_displayed(player: Player): if player.Randompages == 2: return True else: return False class Umfrage3B(Page): form_model = 'player' form_fields = ['Umfrage3BesserGehen', 'Umfrage3Ueberfluessig', 'Umfrage3Bekaempfen'] @staticmethod def vars_for_template(player: Player): zahlen = [5, 6, 7] random.shuffle(zahlen) zahl5, zahl6, zahl7 = zahlen return { "Zahl5": zahl5, "Zahl6": zahl6, "Zahl7": zahl7, } @staticmethod def is_displayed(player: Player): if player.Randompages == 3: return True else: return False class Umfrage3C(Page): form_model = 'player' form_fields = ['Umfrage3BesserGehen', 'Umfrage3Ueberfluessig', 'Umfrage3Bekaempfen'] @staticmethod def vars_for_template(player: Player): zahlen = [5, 6, 7] random.shuffle(zahlen) zahl5, zahl6, zahl7 = zahlen return { "Zahl5": zahl5, "Zahl6": zahl6, "Zahl7": zahl7, } @staticmethod def is_displayed(player: Player): if player.Randompages == 4: return True else: return False class Umfrage3D(Page): form_model = 'player' form_fields = ['Umfrage3BesserGehen', 'Umfrage3Ueberfluessig', 'Umfrage3Bekaempfen'] @staticmethod def vars_for_template(player: Player): zahlen = [5, 6, 7] random.shuffle(zahlen) zahl5, zahl6, zahl7 = zahlen return { "Zahl5": zahl5, "Zahl6": zahl6, "Zahl7": zahl7, } @staticmethod def is_displayed(player: Player): if player.Randompages == 5: return True else: return False class Umfrage3E(Page): form_model = 'player' form_fields = ['Umfrage3BesserGehen', 'Umfrage3Ueberfluessig', 'Umfrage3Bekaempfen'] @staticmethod def vars_for_template(player: Player): zahlen = [5, 6, 7] random.shuffle(zahlen) zahl5, zahl6, zahl7 = zahlen return { "Zahl5": zahl5, "Zahl6": zahl6, "Zahl7": zahl7, } @staticmethod def is_displayed(player: Player): if player.Randompages == 6: return True else: return False class Umfrage4(Page): form_model = 'player' form_fields = ['Umfrage4Arbeitsplatz', 'Umfrage4Kampagne', 'Umfrage4OnlineNachricht', 'Umfrage4Verteidigen'] @staticmethod def vars_for_template(player: Player): zahlen = [8, 9, 10, 11] random.shuffle(zahlen) zahl8, zahl9, zahl10, zahl11 = zahlen return { "Zahl8": zahl8, "Zahl9": zahl9, "Zahl10": zahl10, "Zahl11": zahl11 } @staticmethod def is_displayed(player: Player): if player.Randompages == 1: return True else: return False class Umfrage4A(Page): form_model = 'player' form_fields = ['Umfrage4Arbeitsplatz', 'Umfrage4Kampagne', 'Umfrage4OnlineNachricht', 'Umfrage4Verteidigen'] @staticmethod def vars_for_template(player: Player): zahlen = [8, 9, 10, 11] random.shuffle(zahlen) zahl8, zahl9, zahl10, zahl11 = zahlen return { "Zahl8": zahl8, "Zahl9": zahl9, "Zahl10": zahl10, "Zahl11": zahl11 } @staticmethod def is_displayed(player: Player): if player.Randompages == 2: return True else: return False class Umfrage4B(Page): form_model = 'player' form_fields = ['Umfrage4Arbeitsplatz', 'Umfrage4Kampagne', 'Umfrage4OnlineNachricht', 'Umfrage4Verteidigen'] @staticmethod def vars_for_template(player: Player): zahlen = [8, 9, 10, 11] random.shuffle(zahlen) zahl8, zahl9, zahl10, zahl11 = zahlen return { "Zahl8": zahl8, "Zahl9": zahl9, "Zahl10": zahl10, "Zahl11": zahl11 } @staticmethod def is_displayed(player: Player): if player.Randompages == 3: return True else: return False class Umfrage4C(Page): form_model = 'player' form_fields = ['Umfrage4Arbeitsplatz', 'Umfrage4Kampagne', 'Umfrage4OnlineNachricht', 'Umfrage4Verteidigen'] @staticmethod def vars_for_template(player: Player): zahlen = [8, 9, 10, 11] random.shuffle(zahlen) zahl8, zahl9, zahl10, zahl11 = zahlen return { "Zahl8": zahl8, "Zahl9": zahl9, "Zahl10": zahl10, "Zahl11": zahl11 } @staticmethod def is_displayed(player: Player): if player.Randompages == 4: return True else: return False class Umfrage4D(Page): form_model = 'player' form_fields = ['Umfrage4Arbeitsplatz', 'Umfrage4Kampagne', 'Umfrage4OnlineNachricht', 'Umfrage4Verteidigen'] @staticmethod def vars_for_template(player: Player): zahlen = [8, 9, 10, 11] random.shuffle(zahlen) zahl8, zahl9, zahl10, zahl11 = zahlen return { "Zahl8": zahl8, "Zahl9": zahl9, "Zahl10": zahl10, "Zahl11": zahl11 } @staticmethod def is_displayed(player: Player): if player.Randompages == 5: return True else: return False class Umfrage4E(Page): form_model = 'player' form_fields = ['Umfrage4Arbeitsplatz', 'Umfrage4Kampagne', 'Umfrage4OnlineNachricht', 'Umfrage4Verteidigen'] @staticmethod def vars_for_template(player: Player): zahlen = [8, 9, 10, 11] random.shuffle(zahlen) zahl8, zahl9, zahl10, zahl11 = zahlen return { "Zahl8": zahl8, "Zahl9": zahl9, "Zahl10": zahl10, "Zahl11": zahl11 } @staticmethod def is_displayed(player: Player): if player.Randompages == 6: return True else: return False class Umfrage5(Page): form_model = 'player' form_fields = ['Umfrage5Muslim', 'Umfrage5Trans', 'Umfrage5Behinderung'] @staticmethod def vars_for_template(player: Player): zahlen = [12, 13, 14] random.shuffle(zahlen) zahl12, zahl13, zahl14 = zahlen return { "Zahl12": zahl12, "Zahl13": zahl13, "Zahl14": zahl14, } @staticmethod def is_displayed(player: Player): if player.Randompages == 1: return True else: return False class Umfrage5A(Page): form_model = 'player' form_fields = ['Umfrage5Muslim', 'Umfrage5Trans', 'Umfrage5Behinderung'] @staticmethod def vars_for_template(player: Player): zahlen = [12, 13, 14] random.shuffle(zahlen) zahl12, zahl13, zahl14 = zahlen return { "Zahl12": zahl12, "Zahl13": zahl13, "Zahl14": zahl14, } @staticmethod def is_displayed(player: Player): if player.Randompages == 2: return True else: return False class Umfrage5B(Page): form_model = 'player' form_fields = ['Umfrage5Muslim', 'Umfrage5Trans', 'Umfrage5Behinderung'] @staticmethod def vars_for_template(player: Player): zahlen = [12, 13, 14] random.shuffle(zahlen) zahl12, zahl13, zahl14 = zahlen return { "Zahl12": zahl12, "Zahl13": zahl13, "Zahl14": zahl14, } @staticmethod def is_displayed(player: Player): if player.Randompages == 3: return True else: return False class Umfrage5C(Page): form_model = 'player' form_fields = ['Umfrage5Muslim', 'Umfrage5Trans', 'Umfrage5Behinderung'] @staticmethod def vars_for_template(player: Player): zahlen = [12, 13, 14] random.shuffle(zahlen) zahl12, zahl13, zahl14 = zahlen return { "Zahl12": zahl12, "Zahl13": zahl13, "Zahl14": zahl14, } @staticmethod def is_displayed(player: Player): if player.Randompages == 4: return True else: return False class Umfrage5D(Page): form_model = 'player' form_fields = ['Umfrage5Muslim', 'Umfrage5Trans', 'Umfrage5Behinderung'] @staticmethod def vars_for_template(player: Player): zahlen = [12, 13, 14] random.shuffle(zahlen) zahl12, zahl13, zahl14 = zahlen return { "Zahl12": zahl12, "Zahl13": zahl13, "Zahl14": zahl14, } @staticmethod def is_displayed(player: Player): if player.Randompages == 5: return True else: return False class Umfrage5E(Page): form_model = 'player' form_fields = ['Umfrage5Muslim', 'Umfrage5Trans', 'Umfrage5Behinderung'] @staticmethod def vars_for_template(player: Player): zahlen = [12, 13, 14] random.shuffle(zahlen) zahl12, zahl13, zahl14 = zahlen return { "Zahl12": zahl12, "Zahl13": zahl13, "Zahl14": zahl14, } @staticmethod def is_displayed(player: Player): if player.Randompages == 6: return True else: return False class Umfrage6(Page): form_model = 'player' form_fields = ['Umfrage6Gesetz'] class Umfrage7(Page): form_model = 'player' form_fields = ['Umfrage7Antidiskriminierungsstelle'] class Seite5WeitereInformationen(Page): form_model = 'player' form_fields = ['URLGeklickt'] @staticmethod def is_displayed(player: Player): if (player.treatmentGroup == 2 or player.treatmentGroup == 4 or player.treatmentGroup == 6) and player.MoreInformations == "Ja": return True else: return False class Gewinnspiel(Page): form_model = 'player' form_fields = ['Email'] class Ende(Page): pass page_sequence = [Languages, Seite1, Seite3_Weitere_Informationen, Seite4, Umfrage1, Umfrage3, Umfrage4, Umfrage5, Umfrage3A, Umfrage5A, Umfrage4A, Umfrage4B, Umfrage3B, Umfrage5B, Umfrage4C, Umfrage5C, Umfrage3C, Umfrage5D, Umfrage3D, Umfrage4D, Umfrage5E, Umfrage4E, Umfrage3E, Umfrage2, Umfrage6, Umfrage7, Seite5WeitereInformationen, Gewinnspiel, Ende]