def is_published(self, obj): task = get_active_video_turk_task(obj.id) if task == None: return False if task.hit_id == '': return False return True
def publish_to_turk(modeladmin, request, videos): for video in videos: video_task = get_active_video_turk_task(video.id) if video_task != None: raise Exception('video {} already has an active FullVideoTask'.format(id)) video_task = FullVideoTask(video = video) video_task.publish()
def videoAnnotations(request, video_id): try: video = Video.objects.get(id=video_id) except Video.DoesNotExist: raise Http404('No video with id "{}". Possible fixes: \n1) Download an up to date DB, see README. \n2) Add this video to the DB via /admin'.format(video_id)) userId = request.user.id videoAnnotations_currentUser = VideoAnnotation.objects.filter(videoId=video_id, userId=userId) videoAnnotations_otherUsers = VideoAnnotation.objects.filter(videoId=video_id).exclude(userId=userId) mturk_data = mturk.utils.authenticate_hit(request) if 'error' in mturk_data: return HttpResponseForbidden(mturk_data['error']) if not (mturk_data['authenticated'] or request.user.is_authenticated()): return redirect('/login/?next=' + request.path) start_time = float(request.GET['s']) if 's' in request.GET else None end_time = float(request.GET['e']) if 'e' in request.GET else None turk_task = get_active_video_turk_task(video.id) if turk_task != None: if turk_task.metrics != '': metricsDictr = ast.literal_eval(turk_task.metrics) else: metricsDictr = {} # Data for Javascript full_video_task_data = { 'id': turk_task.id, 'storedMetrics': metricsDictr, 'bonus': float(turk_task.bonus), 'bonusMessage': turk_task.message, 'rejectionMessage': settings.MTURK_REJECTION_MESSAGE, 'emailSubject': settings.MTURK_EMAIL_SUBJECT, 'emailMessage': settings.MTURK_EMAIL_MESSAGE, 'isComplete': turk_task.worker_id != '' } # Data for python templating if turk_task.last_email_sent_date != None: mturk_data['last_email_sent_date'] = turk_task.last_email_sent_date.strftime("%Y-%m-%d %H:%M") else: full_video_task_data = None mturk_data['status'] = get_mturk_status(video, turk_task) mturk_data['has_current_full_video_task'] = full_video_task_data != None label_data = [] video_data = json.dumps({ 'id': video.id, 'location': video.url, 'path': video.host, 'is_image_sequence': True if video.image_list else False, 'start_time': start_time, 'end_time' : end_time, 'turk_task' : full_video_task_data }) help_content = '' if settings.HELP_URL and settings.HELP_USE_MARKDOWN: help_content = urllib.request.urlopen(settings.HELP_URL).read().decode('utf-8') help_content = markdown.markdown(help_content) title = 'Annotations for video '+str(video.id) videoAnnotations_data_currentUser = [] videoAnnotations_data_otherUsers = [] for videoAnnotation in videoAnnotations_currentUser: videoAnnotationStr = '/video/'+str(video.id)+'/'+str(videoAnnotation.id) videoAnnotations_data_currentUser.append({'url':videoAnnotationStr, 'id':videoAnnotation.id, 'videoId':video.id}) for videoAnnotation in videoAnnotations_otherUsers: videoAnnotationStr = '/video/'+str(video.id)+'/'+str(videoAnnotation.id) videoAnnotations_data_otherUsers.append({'url':videoAnnotationStr, 'id':videoAnnotation.id, 'videoId':video.id}) response = render(request, 'video_annotations.html', context={ 'title': title, 'video_data': video_data, 'videoAnnotations_data_currentUser': videoAnnotations_data_currentUser, 'videoAnnotations_data_otherUsers': videoAnnotations_data_otherUsers, 'image_list': list(map(urllib.parse.quote, json.loads(video.image_list))) if video.image_list else 0, 'image_list_path': urllib.parse.quote(video.host, safe='/:'), 'help_url': settings.HELP_URL, 'help_embed': settings.HELP_EMBED, 'mturk_data': mturk_data, 'iframe_mode': mturk_data['authenticated'], 'survey': False, 'help_content': help_content }) if not mturk_data['authenticated']: response['X-Frame-Options'] = 'SAMEORIGIN' return response
def video(request, video_id, annotation_id): #import pdb #pdb.set_trace() try: video = Video.objects.get(id=video_id) labels = Label.objects.all() except Video.DoesNotExist: raise Http404('No video with id "{}". Possible fixes: \n1) Download an up to date DB, see README. \n2) Add this video to the DB via /admin'.format(video_id)) videoAnnotation = VideoAnnotation.objects.get(id=annotation_id) mturk_data = mturk.utils.authenticate_hit(request) if 'error' in mturk_data: return HttpResponseForbidden(mturk_data['error']) if not (mturk_data['authenticated'] or request.user.is_authenticated()): return redirect('/login/?next=' + request.path) start_time = float(request.GET['s']) if 's' in request.GET else None end_time = float(request.GET['e']) if 'e' in request.GET else None turk_task = get_active_video_turk_task(video.id) if turk_task != None: if turk_task.metrics != '': metricsDictr = ast.literal_eval(turk_task.metrics) else: metricsDictr = {} # Data for Javascript full_video_task_data = { 'id': turk_task.id, 'storedMetrics': metricsDictr, 'bonus': float(turk_task.bonus), 'bonusMessage': turk_task.message, 'rejectionMessage': settings.MTURK_REJECTION_MESSAGE, 'emailSubject': settings.MTURK_EMAIL_SUBJECT, 'emailMessage': settings.MTURK_EMAIL_MESSAGE, 'isComplete': turk_task.worker_id != '' } # Data for python templating if turk_task.last_email_sent_date != None: mturk_data['last_email_sent_date'] = turk_task.last_email_sent_date.strftime("%Y-%m-%d %H:%M") else: full_video_task_data = None mturk_data['status'] = get_mturk_status(video, turk_task) mturk_data['has_current_full_video_task'] = full_video_task_data != None label_data = [] link_data = [] video_data = json.dumps({ 'id': video.id, 'annotation_id':annotation_id, 'location':video.url, 'path':video.host, 'is_image_sequence': True if video.image_list else False, 'annotated': videoAnnotation.annotation != '', 'verified':video.verified, 'rejected':video.rejected, 'start_time':start_time, 'end_time':end_time, 'turk_task':full_video_task_data, 'description':videoAnnotation.description }) if videoAnnotation.annotation != '': annotation_data = json.loads(videoAnnotation.annotation) for a in annotation_data: label_data.append({'name': a['type'], 'color': a['color'][1:]}) for k in a['links']: link1 = (a['type'], k['name'], a['color'], k['color']) link2 = (k['name'], a['type'], k['color'], a['color']) if link1 in link_data or link2 in link_data: continue link_data.append(link1) link_data = list(map(lambda x: (x[0], x[1]), link_data)) help_content = '' if settings.HELP_URL and settings.HELP_USE_MARKDOWN: help_content = urllib.request.urlopen(settings.HELP_URL).read().decode('utf-8') help_content = markdown.markdown(help_content) response = render(request, 'video.html', context={ 'label_data': label_data, 'link_data': link_data, 'video_data': video_data, 'image_list': list(map(urllib.parse.quote, json.loads(video.image_list))) if video.image_list else 0, 'image_list_path': urllib.parse.quote(video.host, safe='/:'), 'help_url': settings.HELP_URL, 'help_embed': settings.HELP_EMBED, 'mturk_data': mturk_data, 'iframe_mode': mturk_data['authenticated'], 'survey': False, 'help_content': help_content }) if not mturk_data['authenticated']: response['X-Frame-Options'] = 'SAMEORIGIN' return response
def video(request, video_id): try: video = Video.objects.get(id=video_id) labels = Label.objects.all() except Video.DoesNotExist: raise Http404('No video with id "{}". Possible fixes: \n1) Download an up to date DB, see README. \n2) Add this video to the DB via /admin'.format(video_id)) mturk_data = mturk.utils.authenticate_hit(request) if 'error' in mturk_data: return HttpResponseForbidden(mturk_data['error']) if not (mturk_data['authenticated'] or request.user.is_authenticated()): return redirect('/login/?next=' + request.path) start_time = float(request.GET['s']) if 's' in request.GET else None end_time = float(request.GET['e']) if 'e' in request.GET else None turk_task = get_active_video_turk_task(video.id) if turk_task != None: if turk_task.metrics != '': metricsDictr = ast.literal_eval(turk_task.metrics) else: metricsDictr = {} # Data for Javascript full_video_task_data = { 'id': turk_task.id, 'storedMetrics': metricsDictr, 'bonus': float(turk_task.bonus), 'bonusMessage': turk_task.message, 'rejectionMessage': settings.MTURK_REJECTION_MESSAGE, 'emailSubject': settings.MTURK_EMAIL_SUBJECT, 'emailMessage': settings.MTURK_EMAIL_MESSAGE, 'isComplete': turk_task.worker_id != '' } # Data for python templating if turk_task.last_email_sent_date != None: mturk_data['last_email_sent_date'] = turk_task.last_email_sent_date.strftime("%Y-%m-%d %H:%M") else: full_video_task_data = None mturk_data['status'] = get_mturk_status(video, turk_task) mturk_data['has_current_full_video_task'] = full_video_task_data != None video_data = json.dumps({ 'id': video.id, 'location': video.url, 'path': video.host, 'is_image_sequence': True if video.image_list else False, 'annotated': video.annotation != '', 'verified': video.verified, 'rejected': video.rejected, 'start_time': start_time, 'end_time' : end_time, 'turk_task' : full_video_task_data }) label_data = [] video_labels = video.labels.all() if len(video_labels): for v_label in video_labels: label_data.append({'name': v_label.name, 'color': v_label.color}) else: for l in labels: label_data.append({'name': l.name, 'color': l.color}) help_content = '' if settings.HELP_URL and settings.HELP_USE_MARKDOWN: help_content = urllib.request.urlopen(settings.HELP_URL).read().decode('utf-8') help_content = markdown.markdown(help_content) response = render(request, 'video.html', context={ 'label_data': label_data, 'video_data': video_data, 'image_list': list(map(urllib.parse.quote, json.loads(video.image_list))) if video.image_list else 0, 'image_list_path': urllib.parse.quote(video.host, safe='/:'), 'help_url': settings.HELP_URL, 'help_embed': settings.HELP_EMBED, 'mturk_data': mturk_data, 'iframe_mode': mturk_data['authenticated'], 'survey': False, 'help_content': help_content }) if not mturk_data['authenticated']: response['X-Frame-Options'] = 'SAMEORIGIN' return response