from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import boto3 from os import environ author = 'Huanren Zhang' doc = """ MTurk Qualification HIT """ class Constants(BaseConstants): name_in_url = 'signup' players_per_group = None num_rounds = 1 wait_minutes = 1 class Subsession(BaseSubsession): def creating_session(self): pass class Group(BaseGroup): pass class Player(BasePlayer): t1 = models.BooleanField(initial=0,blank=True) t2 = models.BooleanField(initial=0,blank=True) t3 = models.BooleanField(initial=0,blank=True) t4 = models.BooleanField(initial=0,blank=True) consent = models.BooleanField(initial=0) data_received = models.IntegerField(initial=0) # on which page user data is received (0 represent not received) machine = models.StringField() browser = models.StringField() agent_string = models.StringField() ip = models.StringField(blank=True) language = models.StringField(blank=True) region = models.StringField(blank=True) locality = models.StringField(blank=True) city = models.StringField(blank=True) postcode = models.StringField(blank=True) network = models.StringField(blank=True) timeZone = models.StringField(blank=True) utcOffset = models.StringField(blank=True) latitude = models.FloatField(blank=True) longitude = models.FloatField(blank=True) tor = models.BooleanField(blank=True) vpn = models.BooleanField(blank=True) proxy = models.BooleanField(blank=True) def live_method(self, data): user_agent_string = data['userAgent'] geo_data = data['geoData'] print('received agent data for player%d'%self.participant.id_in_session) self.data_received = data['page'] self.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.machine = 'Macintosh' elif 'Windows' in user_agent_string: self.machine = 'Windows' elif 'X11' in user_agent_string: self.machine = 'UNIX' elif 'Linux' in user_agent_string: self.machine = 'Linux' else: self.machine = 'Other' # This part checks for the browser if 'Chrome' in user_agent_string: self.browser = 'Chrome' elif 'Edge' in user_agent_string: self.browser = 'Edge' elif 'Firefox' in user_agent_string: self.browser = 'Firefox' elif 'Safari' in user_agent_string and 'Chrome' not in user_agent_string and 'Edge' not in user_agent_string: self.browser = 'Safari' elif 'MSIE' in user_agent_string: self.browser = 'InternetExplorer' elif 'Opera' in user_agent_string: self.browser = 'Opera' else: self.browser = 'Other' self.ip = geo_data['ip'] self.language = geo_data['localityLanguageRequested'] self.region = geo_data['location']['isoPrincipalSubdivision'] self.city = geo_data['location']['city'] self.locality = geo_data['location']['localityName'] self.postcode = geo_data['location']['postcode'] self.latitude = geo_data['location']['latitude'] self.longitude = geo_data['location']['longitude'] self.timeZone = geo_data['location']['timeZone']['effectiveTimeZoneShort'] self.utcOffset = geo_data['location']['timeZone']['utcOffset'] self.network = geo_data['network']['organisation'] self.tor = geo_data['hazardReport']['isKnownAsTorServer'] self.vpn = geo_data['hazardReport']['isKnownAsVpn'] self.proxy = geo_data['hazardReport']['isKnownAsProxy']