import decimal import random from django.db import models as django_models from otree.api import * from . import models # from django.core.mail import send_mail # from otree import widgets author = '' doc = """ Start Page for Online Experiments """ class Constants(BaseConstants): name_in_url = 'IajrWRoi' players_per_group = None num_rounds = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): consent = models.IntegerField( label='Consent declaration:', initial=None, choices=[ [ 1, 'I have read and understood the stated terms. I had enough time to make a decision. Herewith, I consent to participate in this study.', ], [0, 'I choose not to participate in this study.'], ], widget=widgets.RadioSelect, ) prolific_id = models.StringField() # Save user's browser data on StartPage Page, # before mobiles are screened out. user_agent = models.StringField() window_height = models.StringField() window_width = models.StringField() is_iPad = models.BooleanField() # warnings/time spent Intro_warnings = models.IntegerField() Intro_time_spent = models.FloatField(blank=True) # FUNCTIONS # PAGES class Consent(Page): form_model = 'player' form_fields = [ 'consent', 'window_height', 'window_width', 'user_agent', 'is_iPad', ] @staticmethod def js_vars(player: Player): return dict(page_name='Consent') @staticmethod def before_next_page(player: Player, timeout_happened): try: player.prolific_id = player.participant.label player.participant.vars['prolific_id'] = player.prolific_id except TypeError: player.prolific_id = 'No_ID_detected' class Intro(Page): form_model = 'player' form_fields = [ 'Intro_warnings', 'Intro_time_spent', ] @staticmethod def js_vars(player: Player): return dict(page_name='Intro') @staticmethod def vars_for_template(player: Player): conversion = player.session.config['real_world_currency_per_point'] participation_fee = player.session.config['participation_fee'] points = 100 money = (points * conversion) * 100 reward = player.session.config['prolific_reward'] return dict( conversion=conversion, participation_fee=participation_fee, points=cu(points), money=money, reward=reward, ) class ScreenOutID(Page): """Page to screen out participants who do not consent.""" @staticmethod def is_displayed(player: Player): return player.prolific_id == 'No_ID_detected' class ScreenOutConsent(Page): """Page to screen out participants who do not consent.""" @staticmethod def is_displayed(player: Player): return player.consent == 0 class ScreenOutDevice(Page): """Page to screen out participants who do not have proper device.""" @staticmethod def is_displayed(player: Player): if ( any( x in player.user_agent for x in [ 'iPhone', 'iPad', 'Android', 'Mobi', 'PlayBook', 'BlackBerry', 'Edge', 'MSIE', 'Trident', ] ) or player.is_iPad is True ): return True else: return False page_sequence = [ Consent, ScreenOutConsent, ScreenOutDevice, ScreenOutID, Intro, ]