def make_data(self, user_id): try: return self._user_finished(user_id) except mturk_vision.UserNotFinishedException: pass row = self.get_row(user_id) if not row: return {'submitUrl': 'data:,Done%20annotating'} question = quote(self.read_row_column(row, 'question')) out = {"dataId": self.urlsafe_uuid(), "question": quote(question)} data = {'image': row, 'userId': user_id, 'startTime': time.time(), 'question': question} try: latitude = quote(self.read_row_column(row, 'latitude')) longitude = quote(self.read_row_column(row, 'longitude')) out['latitude'] = data['latitude'] = latitude out['longitude'] = data['longitude'] = longitude except ValueError: pass self.response_db.hmset(self.prefix + out['dataId'], data) image = self.path_to_key_db.get(self.prefix + self.row_column_encode(row, 'image')) if image: out['image'] = image return out
def make_data(self, user_id): try: return self._user_finished(user_id) except mturk_vision.UserNotFinishedException: pass row = self.get_row(user_id) if not row: return {'submitUrl': 'data:,Done%20annotating'} class_name = self.class_override if self.class_override else self.read_row_column(row, 'class') class_name = quote(class_name) out = {"images": [], "dataId": self.urlsafe_uuid(), "className": '<h3>Class: %s</h3>' % class_name} h = '' if class_name in self.class_descriptions: h = '<pre>Description: '+ self.class_descriptions[class_name] + '</pre>' if class_name in self.class_thumbnails: h += '<h3>Class Examples</h3>' for x in self.class_thumbnails[class_name]: h += '<img src="%s" height="75px" width="75px">' % x if h: out['help'] = h self.response_db.hmset(self.prefix + out['dataId'], {'image': row, 'userId': user_id, 'startTime': time.time(), 'class': class_name}) out['images'].append({"src": 'image/%s' % self.path_to_key_db.get(self.prefix + self.row_column_encode(row, 'image')), "width": 250}) return out
def __init__(self, *args, **kw): super(AMTImageClassManager, self).__init__(*args, **kw) self.class_descriptions = json.loads(kw.get('class_descriptions', '{}')) self.class_descriptions = {x: quote(y) for x, y in self.class_descriptions.items()} self.class_thumbnails = json.loads(kw.get('class_thumbnails', '{}')) self.class_thumbnails = {x: map(quote, y) for x, y in self.class_thumbnails.items()} self.required_columns = set(['image', 'class'])
def __init__(self, *args, **kw): super(AMTImageClassManager, self).__init__(*args, **kw) self.class_descriptions = json.loads(kw.get('class_descriptions', '{}')) self.class_descriptions = dict((x, quote(y)) for x, y in self.class_descriptions.items()) self.class_thumbnails = json.loads(kw.get('class_thumbnails', '{}')) self.class_thumbnails = dict((x, map(quote, y)) for x, y in self.class_thumbnails.items()) self.class_override = kw.get('class') if self.class_override: self.required_columns = set(['image']) else: self.required_columns = set(['image', 'class'])
def make_data(self, user_id): try: return self._user_finished(user_id) except mturk_vision.UserNotFinishedException: pass row = self.get_row(user_id) if not row: return {'submitUrl': 'data:,Done%20annotating'} question = quote(self.read_row_column(row, 'question')) out = {"images": [], "dataId": self.urlsafe_uuid(), "question": '<h3>%s</h3>' % question} self.response_db.hmset(self.prefix + out['dataId'], {'image': row, 'userId': user_id, 'startTime': time.time(), 'question': question}) out['images'].append({"src": 'image/%s' % self.path_to_key_db.get(self.prefix + self.row_column_encode(row, 'image')), "width": 250}) return out
def __init__(self, mode, num_tasks, index_path, config_path, task_key, users_db, response_db, state_db, key_to_path_db, path_to_key_db, data_source, secret=None, **kw): self.prefix = task_key + ':' self.mode = mode self.num_tasks = num_tasks self.users_db = users_db self.response_db = response_db self.state_db = state_db self.key_to_path_db = key_to_path_db self.path_to_key_db = path_to_key_db self.dbs = [self.users_db, self.response_db, self.state_db, self.key_to_path_db, self.path_to_key_db] self.index_path = index_path self.config_path = config_path self.data_source = data_source self._make_secret(secret) self.data_source_lock = gevent.coros.RLock() # Used to protect the data_source from simultaneous access self.lock_expire = 60 self.random_prefix = 4 if 'instructions' in kw: self.instructions = '<pre>%s</pre>' % quote(kw['instructions'])
def __init__(self, query, *args, **kw): super(AMTImageQueryBatchManager, self).__init__(*args, **kw) self.images_per_batch = 64 self.query = '<h2>%s</h2>' % quote(query)