コード例 #1
0
 def get_context_data(self, **kwargs):
     context = super(VisualSearchDetail, self).get_context_data(**kwargs)
     qp = DVAPQLProcess(query=context['object'],media_dir=settings.MEDIA_ROOT)
     qp.collect()
     context['results'] = qp.context.items()
     context['url'] = '{}queries/{}.png'.format(settings.MEDIA_URL, self.object.pk, self.object.pk)
     return context
コード例 #2
0
def search(request):
    if request.method == 'POST':
        qp = DVAPQLProcess()
        qp.create_from_request(request)
        qp.launch()
        qp.wait()
        qp.collect()
        return JsonResponse(data={'task_id': "",
                                  'primary_key': qp.query.pk,
                                  'results': qp.context,
                                  'url': '{}queries/{}.png'.format(settings.MEDIA_URL, qp.query.pk)
                                  })
コード例 #3
0
def import_s3(request):
    if request.method == 'POST':
        keys = request.POST.get('key')
        region = request.POST.get('region')
        bucket = request.POST.get('bucket')
        process_spec = {
            'process_type': DVAPQL.PROCESS,
        }
        user = request.user if request.user.is_authenticated else None
        tasks = []
        for key in keys.strip().split('\n'):
            if key.strip():
                video = Video()
                if user:
                    video.uploader = user
                video.name = "pending S3 import {} s3://{}/{}".format(region, bucket, key)
                video.save()
                tasks.append({'video_id':video.pk,'operation':'import_video_from_s3','arguments':{'key':key.strip(),'bucket':bucket,'region':region}})
        process_spec['tasks'] = tasks
        p = DVAPQLProcess()
        p.create_from_json(process_spec,user)
        p.launch()
    else:
        raise NotImplementedError
    return redirect('video_list')
コード例 #4
0
def indexes(request):
    context = {
        'visual_index_list': settings.VISUAL_INDEXES.items(),
        'index_entries': IndexEntries.objects.all(),
        "videos": Video.objects.all().filter(),
        "region_types": Region.REGION_TYPES
    }
    if request.method == 'POST':
        filters = {
            'region_type__in': request.POST.getlist('region_type__in', []),
            'w__gte': int(request.POST.get('w__gte')),
            'h__gte': int(request.POST.get('h__gte'))
         }
        for optional_key in ['metadata_text__contains', 'object_name__contains', 'object_name']:
            if request.POST.get(optional_key, None):
                filters[optional_key] = request.POST.get(optional_key)
        for optional_key in ['h__lte', 'w__lte']:
            if request.POST.get(optional_key, None):
                filters[optional_key] = int(request.POST.get(optional_key))
        args = {'filters':filters,'index':request.POST.get('visual_index_name')}
        p = DVAPQLProcess()
        spec = {
            'process_type':DVAPQL.PROCESS,
            'tasks':[
                {
                    'operation':'perform_indexing',
                    'arguments':args,
                    'video_id':request.POST.get('video_id')
                }
            ]
        }
        user = request.user if request.user.is_authenticated else None
        p.create_from_json(spec,user)
        p.launch()
    return render(request, 'indexes.html', context)
コード例 #5
0
def export_video(request):
    if request.method == 'POST':
        pk = request.POST.get('video_id')
        video = Video.objects.get(pk=pk)
        export_method = request.POST.get('export_method')
        if video:
            if export_method == 's3':
                key = request.POST.get('key')
                bucket = request.POST.get('bucket')
                region = request.POST.get('region','us-east-1')
                process_spec = {'process_type':DVAPQL.PROCESS,
                          'tasks':[
                              {
                                  'video_id':video.pk,
                                  'operation':'backup_video_to_s3',
                                  'arguments': {'key':key,'bucket':bucket,'region':region}
                              },
                          ]}
            else:
                process_spec = {'process_type':DVAPQL.PROCESS,
                          'tasks':[
                              {
                                  'video_id':video.pk,
                                  'operation':'export_video',
                              },
                          ]
                          }
            p = DVAPQLProcess()
            p.create_from_json(process_spec)
            p.launch()
        return redirect('video_list')
    else:
        raise NotImplementedError
コード例 #6
0
def retry_task(request):
    pk = request.POST.get('pk')
    event = TEvent.objects.get(pk=int(pk))
    spec = {
        'process_type':DVAPQL.PROCESS,
        'tasks':[
            {
                'operation':event.operation,
                'arguments':event.arguments
            }
        ]
    }
    p = DVAPQLProcess()
    p.create_from_json(spec)
    p.launch()
    return redirect('/processes/')
コード例 #7
0
def push(request, video_id):
    video = Video.objects.get(pk=video_id)
    if request.method == 'POST':
        push_type = request.POST.get('push_type')
        server = VDNServer.objects.get(pk=request.POST.get('server_pk'))
        token = request.POST.get('token_{}'.format(server.pk))
        server.last_token = token
        server.save()
        server_url = server.url
        if not server_url.endswith('/'):
            server_url += '/'
        headers = {'Authorization': 'Token {}'.format(server.last_token)}
        if push_type == 'annotation':
            new_vdn_dataset = create_child_vdn_dataset(video, server, headers)
            for key in request.POST:
                if key.startswith('annotation_') and request.POST[key]:
                    annotation = Region.objects.get(pk=int(key.split('annotation_')[1]))
                    data = {
                        'label': annotation.label,
                        'metadata_text': annotation.metadata_text,
                        'x': annotation.x,
                        'y': annotation.y,
                        'w': annotation.w,
                        'h': annotation.h,
                        'full_frame': annotation.full_frame,
                        'parent_frame_index': annotation.parent_frame_index,
                        'dataset_id': int(new_vdn_dataset.url.split('/')[-2]),
                    }
                    r = requests.post("{}/api/annotations/".format(server_url), data=data, headers=headers)
                    if r.status_code == 201:
                        annotation.vdn_dataset = new_vdn_dataset
                        annotation.save()
                    else:
                        raise ValueError
        elif push_type == 'dataset':
            key = request.POST.get('key')
            region = request.POST.get('region')
            bucket = request.POST.get('bucket')
            name = request.POST.get('name')
            description = request.POST.get('description')
            vdn = create_root_vdn_dataset(region, bucket, key, server, headers, name, description)
            video.vdn_dataset = vdn
            spec = {
                'process_type':DVAPQL.PROCESS,
                'tasks':[
                    {
                        'operation':'push_video_to_vdn_s3',
                        'arumgents': {'key':key,
                                      'bucket':bucket,
                                      'region':region}
                     }
                ]
            }
            p = DVAPQLProcess()
            p.create_from_json(spec,request.user)
            p.launch()
        else:
            raise NotImplementedError

    servers = VDNServer.objects.all()
    context = {'video': video, 'servers': servers}
    if video.vdn_dataset:
        context['annotations'] = Region.objects.all().filter(video=video, vdn_dataset__isnull=True,
                                                             region_type=Region.ANNOTATION)
    else:
        context['annotations'] = Region.objects.all().filter(video=video, region_type=Region.ANNOTATION)
    return render(request, 'push.html', context)