from otree.api import * from country_list import countries_for_language countries = dict(countries_for_language('en')) from collections import OrderedDict import itertools import random import string def make_countries(): choices = [] for c in countries: cho = [] country = [(countries)[str(c)]] country = country[0] cho.append(country) cho.append(country) choices.append(cho) return choices #def make_fieldsBFF(questions): # res = [] # for q in questions: # res.append( # models.IntegerField( # choices=[(i, Constants.choices_map[i]) for i in range(1,6)], # label=q, # widget=widgets.RadioSelect, # ) # ) # return res #bff = [] #for i in range(1,5): # bff.append(str(i)) #import ( # models, widgets, BaseConstants, Page, WaitPage, BaseSubsession, BaseGroup, BasePlayer, # Currency as c, currency_range #) doc = "Thesis" class Constants(BaseConstants): name_in_url = 'Thesis' players_per_group = None num_rounds = 1 #with open("questions.txt", encoding='utf-8') as f: # questions_bff = f.readlines() #choices_map = OrderedDict( # ( # (1, "No or Very Rarely"), # (2, "Rarely"), # (3, "Occasionally"), # (4, "Frequently"), # (5, "Very Frequently"), # ) #) class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): treatment = models.StringField() condition = models.StringField() code = models.StringField() Consent = models.StringField( choices = [['Yes', 'Yes'], ['No', 'No']], label = 'Do you consent to take part to this experiment?', widget = widgets.RadioSelect, ) Consent_End = models.StringField( choices = [['Yes, end the experiment', 'Yes, end the experiment'], ['No, go back to the experiment', 'No, go back to the experiment']], label = 'Are you sure you do not consent to take part to the experiment?', widget = widgets.RadioSelect, ) Int1 = models.StringField( choices = [['Yes', 'Yes'], ['No', 'No']], label = 'Could you interact with Moviebot without any issue?:', widget = widgets.RadioSelect, ) Int1_No = models.LongStringField( label = 'What were the issues your encountered?', ) Int2 = models.StringField( choices = [ [1, 'None of them'], [2, 'Few of them'], [3, 'Half of them'], [4, 'Most of them'], [5, 'All of them']], label = 'Among the movies recommended by Moviebot, how many were you possibly interested to watch?:', widget = widgets.RadioSelect, ) Eco1 = models.StringField( choices = [['Yes', 'Yes'], ['No', 'No']], label = '', widget = widgets.RadioSelect, ) Eco1Y = models.StringField( choices = [ [1, 'Very Rarely'], [2, 'Rarely'], [3, 'Often'], [4, 'Really Often']], label = 'How often would you use it?', widget = widgets.RadioSelect, ) Eco1N = models.LongStringField( label = 'What would be the reason(s) for you to not use it for movies?', ) Eco2 = models.StringField( choices = [['Yes', 'Yes'], ['No', 'No']], label = '', widget = widgets.RadioSelect, ) Eco2Y = models.StringField( choices = [ [1, 'Very Rarely'], [2, 'Rarely'], [3, 'Often'], [4, 'Really Often']], label = 'How often would you use it?', widget = widgets.RadioSelect, ) Eco2N = models.LongStringField( label = 'What would be the reason(s) for you to not use it for clothes?', ) Eco3 = models.StringField( choices = [['Yes', 'Yes'], ['No', 'No']], label = '', widget = widgets.RadioSelect, ) Eco3Y = models.StringField( choices = [ [1, 'Very Rarely'], [2, 'Rarely'], [3, 'Often'], [4, 'Really Often']], label = 'How often would you use it?', widget = widgets.RadioSelect, ) Eco3N = models.LongStringField( label = 'What would be the reason(s) for you to not use it for trip plans?', ) Eco1_2 = models.StringField( choices = [['Yes', 'Yes'], ['No', 'No']], label = 'Would you consider using this technology to have movie recommendations?', widget = widgets.RadioSelect, ) Eco1Y_2 = models.StringField( choices = [ [1, 'Very Rarely'], [2, 'Rarely'], [3, 'Often'], [4, 'Really Often']], label = 'How often would you use it?', widget = widgets.RadioSelect, ) Eco1N_2 = models.LongStringField( label = 'What would be the reason(s) for you to not use it for movies?', ) Eco2_2 = models.StringField( choices = [['Yes', 'Yes'], ['No', 'No']], label = 'Would you consider using a similar technology recommending clothes instead of movies?', widget = widgets.RadioSelect, ) Eco2Y_2 = models.StringField( choices = [ [1, 'Very Rarely'], [2, 'Rarely'], [3, 'Often'], [4, 'Really Often']], label = 'How often would you use it?', widget = widgets.RadioSelect, ) Eco2N_2 = models.LongStringField( label = 'What would be the reason(s) for you to not use it for clothes?', ) Eco3_2 = models.StringField( choices = [['Yes', 'Yes'], ['No', 'No']], label = 'Would you consider using a similar technology recommending trip plans (for example when visiting a new country)?', widget = widgets.RadioSelect, ) Eco3Y_2 = models.StringField( choices = [ [1, 'Very Rarely'], [2, 'Rarely'], [3, 'Often'], [4, 'Really Often']], label = 'How often would you use it?', widget = widgets.RadioSelect, ) Eco3N_2 = models.LongStringField( label = 'What would be the reason(s) for you to not use it for trip plans?', ) Att1 = models.IntegerField( choices=[ [1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'Neither Agree nor Disagree'], [4, 'Agree'], [5, 'Strongly Agree']], label = '1. I can trust this technology:', widget = widgets.RadioSelectHorizontal, ) Att2 = models.IntegerField( choices=[ [1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'Neither Agree nor Disagree'], [4, 'Agree'], [5, 'Strongly Agree']], label = '2. There is a risk using this technology:', widget = widgets.RadioSelectHorizontal, ) Att3 = models.IntegerField( choices=[ [1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'Neither Agree nor Disagree'], [4, 'Agree'], [5, 'Strongly Agree']], label = '3. This technology is knowledgeable:', widget = widgets.RadioSelectHorizontal, ) Att4 = models.IntegerField( choices=[ [1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'Neither Agree nor Disagree'], [4, 'Agree'], [5, 'Strongly Agree']], label = '4. This technology understands my needs and preferences:', widget = widgets.RadioSelectHorizontal, ) Att1_2 = models.IntegerField( choices=[ [1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'Neither Agree nor Disagree'], [4, 'Agree'], [5, 'Strongly Agree']], label = '1. I can trust this technology:', widget = widgets.RadioSelectHorizontal, ) Att2_2 = models.IntegerField( choices=[ [1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'Neither Agree nor Disagree'], [4, 'Agree'], [5, 'Strongly Agree']], label = '2. There is a risk using this technology:', widget = widgets.RadioSelectHorizontal, ) Att3_2 = models.IntegerField( choices=[ [1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'Neither Agree nor Disagree'], [4, 'Agree'], [5, 'Strongly Agree']], label = '3. This technology is knowledgeable:', widget = widgets.RadioSelectHorizontal, ) Att4_2 = models.IntegerField( choices=[ [1, 'Strongly Disagree'], [2, 'Disagree'], [3, 'Neither Agree nor Disagree'], [4, 'Agree'], [5, 'Strongly Agree']], label = '4. This technology understands my needs and preferences:', widget = widgets.RadioSelectHorizontal, ) Online = models.IntegerField( choices=[ [1, 'No or Very Rarely'], [2, 'Rarely'], [3, 'Occasionally'], [4, 'Frequently'], [5, 'Very Frequently']], label = '', widget = widgets.RadioSelectHorizontal, ) Shopping = models.IntegerField( choices=[ [1, 'No or Very Rarely'], [2, 'Rarely'], [3, 'Occasionally'], [4, 'Frequently'], [5, 'Very Frequently']], label = '', widget = widgets.RadioSelectHorizontal, ) Food = models.IntegerField( choices=[ [1, 'No or Very Rarely'], [2, 'Rarely'], [3, 'Occasionally'], [4, 'Frequently'], [5, 'Very Frequently']], label = '', widget = widgets.RadioSelectHorizontal, ) Music = models.IntegerField( choices=[ [1, 'No or Very Rarely'], [2, 'Rarely'], [3, 'Occasionally'], [4, 'Frequently'], [5, 'Very Frequently']], label = '', widget = widgets.RadioSelectHorizontal, ) Movies = models.IntegerField( choices=[ [1, 'No or Very Rarely'], [2, 'Rarely'], [3, 'Occasionally'], [4, 'Frequently'], [5, 'Very Frequently']], label = '', widget = widgets.RadioSelectHorizontal, ) VA = models.IntegerField( choices=[ [1, 'No or Very Rarely'], [2, 'Rarely'], [3, 'Occasionally'], [4, 'Frequently'], [5, 'Very Frequently']], label = '', widget = widgets.RadioSelectHorizontal, ) Age = models.IntegerField( label = '' ) Gender = models.StringField( choices =['Female', 'Male', 'Other', 'Do not wish to tell'], label = '', widget = widgets.RadioSelect, ) Education = models.StringField( choices =['No schooling completed', 'Secondary School', 'High school graduate, diploma or the equivalent', 'Some college credit, no degree', 'Trade/technical/vocational training', 'Associate degree', 'Bachelor’s degree', 'Master’s degree', 'Professional degree', 'Doctorate degree'], label = '', widget = widgets.RadioSelect, ) Proact = models.StringField( choices =['Employed', 'Unemployed', 'Student', 'Retired'], label = '', widget = widgets.RadioSelect, ) Location = models.StringField( choices = make_countries(), label="", ) Code = models.StringField( label = 'Please enter your code:', ) Email = models.StringField( label = 'Please enter your email address:', ) def creating_session(self): import itertools treatments = itertools.cycle(['Moviebot', 'Placebo', 'Control']) #Assignement des participants à une condition for player in self.get_players(): player.treatment = next(treatments) print('set player.treatment to', player.treatment) conditions = itertools.cycle(['SocialFirst', 'PrivacyFirst']) #Assignement des participants à une condition for player in self.get_players(): player.condition = next(conditions) print('set player.condition to', player.condition) for player in self.get_players(): player.code = random.choice(string.ascii_letters) + random.choice(string.digits) + random.choice(string.punctuation) + random.choice(string.digits) + random.choice(string.ascii_letters) print ('set player.code to', player.code) # PAGES class Introduction(Page): form_model = 'player' form_fields = ['Consent'] #class Consent_Sure(Page): # form_model = 'player' # form_fields = ['Consent_End'] # def is_displayed(player): # if player.Consent == 'No': # return player.Consent == 'No' class NoConsent(Page): def is_displayed(player): return player.Consent == 'No' class AI(Page): def is_displayed(player): return player.treatment == 'Moviebot' pass class Moviebot(Page): form_model = 'player' timeout_seconds = 240 def is_displayed(player): return player.treatment == 'Moviebot' pass # webapp class InteractionQ(Page): form_model = 'player' form_fields = ['Int1', 'Int2'] def is_displayed(player): return player.treatment == 'Moviebot' pass class Int1_No(Page): form_model = 'player' form_fields = ['Int1_No'] def is_displayed(player): if player.treatment == 'Moviebot': return player.Int1 == 'No' pass class Placebo(Page): def is_displayed(player): return player.treatment == 'Placebo' pass class Control(Page): def is_displayed(player): return player.treatment == 'Control' pass class SocialFirst(Page): def is_displayed(player): return player.condition == 'SocialFirst' pass class SocialSecond(Page): def is_displayed(player): return player.condition == 'PrivacyFirst' pass class PrivacyFirst(Page): def is_displayed(player): return player.condition == 'PrivacyFirst' pass class PrivacySecond(Page): def is_displayed(player): return player.condition == 'SocialFirst' pass class Eco1(Page): form_model = 'player' form_fields = ['Eco1'] pass class Eco1Y(Page): form_model = 'player' form_fields = ['Eco1Y'] @staticmethod def is_displayed(player): return player.Eco1 == 'Yes' pass class Eco1N(Page): form_model = 'player' form_fields = ['Eco1N'] @staticmethod def is_displayed(player): return player.Eco1 == 'No' pass class Other1(Page): form_model = 'player' form_fields = ['OtherNO1'] @staticmethod def is_displayed(player): return player.Eco1N == 'Other' pass class Eco2(Page): form_model = 'player' form_fields = ['Eco2'] pass class Eco2Y(Page): form_model = 'player' form_fields = ['Eco2Y'] @staticmethod def is_displayed(player): return player.Eco2 == 'Yes' pass class Eco2N(Page): form_model = 'player' form_fields = ['Eco2N'] @staticmethod def is_displayed(player): return player.Eco2 == 'No' pass class Other2(Page): form_model = 'player' form_fields = ['OtherNO2'] @staticmethod def is_displayed(player): return player.Eco2N == 'Other' pass class Eco3(Page): form_model = 'player' form_fields = ['Eco3'] pass class Eco3Y(Page): form_model = 'player' form_fields = ['Eco3Y'] @staticmethod def is_displayed(player): return player.Eco3 == 'Yes' pass class Eco3N(Page): form_model = 'player' form_fields = ['Eco3N'] @staticmethod def is_displayed(player): return player.Eco3 == 'No' pass class Other3(Page): form_model = 'player' form_fields = ['OtherNO3'] @staticmethod def is_displayed(player): return player.Eco3N == 'Other' pass class Att(Page): form_model = 'player' form_fields = ['Att1', 'Att2', 'Att3', 'Att4'] pass class Eco1_2(Page): form_model = 'player' form_fields = ['Eco1_2'] pass class Eco1Y_2(Page): form_model = 'player' form_fields = ['Eco1Y_2'] @staticmethod def is_displayed(player): return player.Eco1_2 == 'Yes' pass class Eco1N_2(Page): form_model = 'player' form_fields = ['Eco1N_2'] @staticmethod def is_displayed(player): return player.Eco1_2 == 'No' pass class Other1_2(Page): form_model = 'player' form_fields = ['OtherNO1_2'] @staticmethod def is_displayed(player): return player.Eco1N_2 == 'Other' pass class Eco2_2(Page): form_model = 'player' form_fields = ['Eco2_2'] pass class Eco2Y_2(Page): form_model = 'player' form_fields = ['Eco2Y_2'] @staticmethod def is_displayed(player): return player.Eco2_2 == 'Yes' pass class Eco2N_2(Page): form_model = 'player' form_fields = ['Eco2N_2'] @staticmethod def is_displayed(player): return player.Eco2_2 == 'No' pass class Other2_2(Page): form_model = 'player' form_fields = ['OtherNO2_2'] @staticmethod def is_displayed(player): return player.Eco2N_2 == 'Other' pass class Eco3_2(Page): form_model = 'player' form_fields = ['Eco3_2'] pass class Eco3Y_2(Page): form_model = 'player' form_fields = ['Eco3Y_2'] @staticmethod def is_displayed(player): return player.Eco3_2 == 'Yes' pass class Eco3N_2(Page): form_model = 'player' form_fields = ['Eco3N_2'] @staticmethod def is_displayed(player): return player.Eco3_2 == 'No' pass class Other3_2(Page): form_model = 'player' form_fields = ['OtherNO3_2'] @staticmethod def is_displayed(player): return player.Eco3N_2 == 'Other' pass class Att_2(Page): form_model = 'player' form_fields = ['Att1_2', 'Att2_2', 'Att3_2', 'Att4_2'] pass class Demographics1(Page): form_model = 'player' form_fields = ['Online', 'VA'] pass class Demographics2(Page): form_model = 'player' form_fields = ['Shopping', 'Food', 'Music', 'Movies'] pass class Demographics3(Page): form_model = 'player' form_fields = ['Age', 'Gender', 'Education', 'Proact', 'Location'] pass class Results(Page): pass class End2(Page): pass class Intro(Page): form_model = 'player' form_fields = ['Code'] pass class Win(Page): form_model = 'player' form_fields = ['Email'] @staticmethod def is_displayed(player): return player.Code == 'z0{8F' pass class Lose(Page): form_model = 'player' form_fields = ['Email'] def is_displayed(player): return player.Code != 'z0{8F' pass class End(Page): pass page_sequence = [Intro, Win, Lose, End] # page_sequence = [SocialFirst, PrivacyFirst, PrivacySecond, SocialSecond, Results] # page_sequence = [AI, InteractionQ, Int1_No, Results] # page_sequence = [Introduction, Placebo, SocialFirst, Eco1, Eco1Y, Eco1N, Eco2, Eco2Y, Eco2N, Eco3, Eco3Y, Eco3N, Att, PrivacySecond, Eco1_2, Eco1Y_2, Eco1N_2, Eco2_2, Eco2Y_2, Eco2N_2, Eco3_2, Eco3Y_2, Eco3N_2, Att_2, Demographics1, Demographics2, Results] # page_sequence = [Introduction, NoConsent, AI, Placebo, Control, Moviebot, InteractionQ, Int1_No, PrivacyFirst, SocialFirst, Eco1, Eco1Y, Eco1N, Eco2, Eco2Y, Eco2N, Eco3, Eco3Y, Eco3N, Att, SocialSecond, PrivacySecond, Eco1_2, Eco1Y_2, Eco1N_2, Eco2_2, Eco2Y_2, Eco2N_2, Eco3_2, Eco3Y_2, Eco3N_2, Att_2, Demographics1, Demographics2, Demographics3, Results, End]