from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage import settings from .models import Constants import time import boto3 def vars_for_all_templates(self): return { 'experiment_date': self.session.config.get('experiment_starting_time', ''), } class Recruitment(Page): live_method = 'live_method' form_model = 'player' form_fields = ['workerid','session_time'] # form_fields = ['workerid','t10','t15','t20','t25','t30','t35','t40','t45','t50'] # def error_message(player, values): # if ((values['t10'] is None) and (values['t15'] is None) and (values['t20'] is None) # and (values['t25'] is None) and (values['t30'] is None) and (values['t35'] is None) # and (values['t40'] is None) and (values['t45'] is None) and (values['t50'] is None)): # return 'You must select at least one time slot.' def js_vars(self): return dict( data_received=self.player.data_received, ) def is_displayed(self): self.player.workerid = self.participant.label return 1 def before_next_page(self): if not self.timeout_happened: # qvalues = [10,15,20,25,30,35,40,45,50] # tvalues = [self.player.t10, self.player.t15, self.player.t20, self.player.t25, self.player.t30, # self.player.t35, self.player.t40, self.player.t45, self.player.t50] # for qv,tv in zip(qvalues,tvalues): # if tv: # qvalue = qv # print(self.player, qvalue) # break if not self.session.config.get('debug',False): access_key_id = self.session.config['access_key_id'] secret_access_key = self.session.config['secret_access_key'] if self.session.config.get('sandbox',False): # sandbox Qid = self.session.config['Qid_sandbox'] mturk = boto3.client( service_name='mturk', aws_access_key_id=access_key_id, aws_secret_access_key=secret_access_key, region_name='us-east-1', endpoint_url="https://mturk-requester-sandbox.us-east-1.amazonaws.com", ) else: # live production Qid = self.session.config['Qid'] mturk = boto3.client( service_name='mturk', aws_access_key_id=access_key_id, aws_secret_access_key=secret_access_key, region_name='us-east-1', ) mturk.associate_qualification_with_worker( QualificationTypeId=Qid, WorkerId=self.player.workerid, IntegerValue=self.player.session_time, SendNotification=False ) self.participant.vars['workerid'] = self.player.workerid user_agent_string = self.request.META['HTTP_USER_AGENT'] self.player.agent_string = user_agent_string print('User agent string:', user_agent_string) # This part checks for the operating system if 'Macintosh' in user_agent_string: self.player.machine = 'Macintosh' elif 'Windows' in user_agent_string: self.player.machine = 'Windows' else: self.player.machine = 'Other' # This part checks for the browser if 'Chrome' in user_agent_string: self.player.browser = 'Chrome' elif 'Edge' in user_agent_string: self.player.browser = 'Edge' elif 'Firefox' in user_agent_string: self.player.browser = 'Firefox' elif 'Safari' in user_agent_string and 'Chrome' not in user_agent_string and 'Edge' not in user_agent_string: self.player.browser = 'Safari' elif 'MSIE' in user_agent_string: self.player.browser = 'InternetExplorer' else: self.player.browser = 'Other' print('setting consent: ',self.player.consent) self.player.consent = True print('after setting consent: ',self.player.consent) class EndInfo(Page): form_model = 'player' form_fields = ['workerid','session_time'] def js_vars(self): return dict( data_received=self.player.data_received, ) page_sequence = [ Recruitment, EndInfo, ]