Пример #1
0
def original_info(request, project_id, original_id):
    username = request.user
    user_id = AccountManager.get_id_by_username(username)
    original_manager = OriginalManager()
    if request.method == 'GET':
        if not Permission.hasPermission(user_id, 'get_original', project_id):
            raise PermissionDenied
        contents = original_manager.get_original(project_id, original_id)

        return HttpResponse(content=json.dumps(contents),
                            status=200,
                            content_type='application/json')
    elif request.method == 'PUT':
        if not Permission.hasPermission(user_id, 'modify_original',
                                        project_id):
            raise PermissionDenied
        # TODO: status validation
        status = request.data.get('status')
        if status == 'analyzed':
            dataset_candidates = request.data.get('dataset_candidates')
            original_manager.update_status(original_id, status,
                                           dataset_candidates)
        else:
            original_manager.update_status(original_id, status)
        return HttpResponse(status=204)
    else:
        user_id = AccountManager.get_id_by_username(username)
        original_manager.delete_rosbag(project_id, user_id, original_id)
        return HttpResponse(status=204)
Пример #2
0
def annotation(request, project_id, annotation_id):
    username = request.user
    user_id = AccountManager.get_id_by_username(username)
    annotation_manager = AnnotationManager()
    if request.method == 'GET':
        if not Permission.hasPermission(user_id, 'get_annotationwork',
                                        project_id):
            raise PermissionDenied
        contents = annotation_manager.get_annotation(annotation_id)
        return HttpResponse(content=json.dumps(contents),
                            status=200,
                            content_type='application/json')

    elif request.method == 'POST':
        file_path = request.data.get('file_path')
        file_name = request.data.get('file_name')
        annotation_manager.set_archive(annotation_id, file_path, file_name)
        return HttpResponse(status=201)

    else:
        if not Permission.hasPermission(user_id, 'delete_annotationwork',
                                        project_id):
            raise PermissionDenied
        annotation_manager.delete_annotation(annotation_id)
        return HttpResponse(status=204)
Пример #3
0
def annotations(request, project_id):
    username = request.user
    user_id = AccountManager.get_id_by_username(username)
    annotation_manager = AnnotationManager()
    if request.method == 'GET':
        if not Permission.hasPermission(user_id, 'list_annotationwork', project_id):
            raise PermissionDenied
        per_page = int(request.GET.get(key="per_page", default=PER_PAGE))
        page = int(request.GET.get(key="page", default=1))
        sort_key = request.GET.get(key="sort_key", default=SORT_KEY)
        reverse_flag = request.GET.get(key="reverse_flag", default="false")
        is_reverse = (reverse_flag == "true")
        search_keyword = request.GET.get(key="search", default="")

        contents = annotation_manager.list_annotations(project_id, sort_key, is_reverse, per_page, page, search_keyword)

        return HttpResponse(content=json.dumps(contents), status=200, content_type='application/json')
    else:
        if not Permission.hasPermission(user_id, 'create_annotationwork', project_id):
            raise PermissionDenied

        name = request.data.get('name')
        dataset_id = request.data.get('dataset_id')

        annotation_id = annotation_manager.create_annotation(user_id, project_id, name, dataset_id)

        contents = annotation_manager.get_annotation(annotation_id)
        return HttpResponse(status=201, content=contents, content_type='application/json')
Пример #4
0
def frame(request, project_id, annotation_id, frame):
    username = request.user
    user_id = AccountManager.get_id_by_username(username)
    annotation_manager = AnnotationManager()
    if request.method == 'GET':
        if not Permission.hasPermission(user_id, 'get_label', project_id):
            raise PermissionDenied
        try_lock = (request.GET.get(key='try_lock') == 'true')
        labels = annotation_manager.get_frame_labels(project_id, user_id,
                                                     try_lock, annotation_id,
                                                     frame)
        return HttpResponse(content=json.dumps(labels),
                            status=200,
                            content_type='application/json')

    else:
        if not Permission.hasPermission(user_id, 'create_label', project_id):
            raise PermissionDenied
        created = request.data.get('created', "")
        edited = request.data.get('edited', "")
        deleted = request.data.get('deleted', "")
        annotation_manager.set_frame_label(user_id, project_id, annotation_id,
                                           frame, created, edited, deleted)
        return HttpResponse(status=201,
                            content=json.dumps({}),
                            content_type='application/json')
Пример #5
0
def index(request, project_id):
    username = request.user
    user_id = AccountManager.get_id_by_username(username)
    original_manager = OriginalManager()
    if request.method == 'POST':
        if not Permission.hasPermission(user_id, 'create_original',
                                        project_id):
            raise PermissionDenied
        name = request.data['name']
        file_type = request.data['file_type']
        size = request.data['size']
        storage_id = int(request.data['storage_id'])
        contents = original_manager.register_original(int(project_id), user_id,
                                                      name, file_type, size,
                                                      storage_id)
        return HttpResponse(content=json.dumps(contents),
                            status=201,
                            content_type='application/json')
    else:
        if not Permission.hasPermission(user_id, 'list_original', project_id):
            raise PermissionDenied
        per_page = int(request.GET.get(key="per_page", default=PER_PAGE))
        page = int(request.GET.get(key="page", default=1))
        sort_key = request.GET.get(key="sort_key", default=SORT_KEY)
        reverse_flag = request.GET.get(key="reverse_flag", default="false")
        is_reverse = (reverse_flag == "true")
        search_keyword = request.GET.get(key="search", default="")
        status = request.GET.get(key="status", default="")
        contents = original_manager.get_originals(project_id, sort_key,
                                                  is_reverse, per_page, page,
                                                  search_keyword, status)
        return HttpResponse(content=json.dumps(contents),
                            status=200,
                            content_type='application/json')
Пример #6
0
def annotation(request, project_id, annotation_id):
    username = request.user
    user_id = AccountManager.get_id_by_username(username)
    annotation_manager = AnnotationManager()
    if request.method == 'GET':
        if not Permission.hasPermission(user_id, 'get_annotationwork',
                                        project_id):
            raise PermissionDenied
        contents = annotation_manager.get_annotation(annotation_id)
        return HttpResponse(content=json.dumps(contents),
                            status=200,
                            content_type='application/json')

    elif request.method == 'POST':
        file_path = request.data.get('file_path')
        file_name = request.data.get('file_name')
        annotation_manager.set_archive(annotation_id, file_path, file_name)
        return HttpResponse(status=201,
                            content=json.dumps({}),
                            content_type='application/json')

    else:
        if not Permission.hasPermission(user_id, 'delete_annotationwork',
                                        project_id):
            raise PermissionDenied
        dataset_id = annotation_manager.get_annotation(
            annotation_id)['dataset_id']
        original_id = DatasetManager().get_dataset(user_id,
                                                   dataset_id)['original_id']
        storage_id = OriginalManager().get_original(project_id,
                                                    original_id)['storage_id']
        storage = StorageSerializer().get_storage(project_id, storage_id)
        annotation_manager.delete_annotation(annotation_id, storage)
        return HttpResponse(status=204)
Пример #7
0
def get_frame(request, project_id, dataset_id, candidate_id, frame):
    username = request.user
    user_id = AccountManager.get_id_by_username(username)
    if not Permission.hasPermission(user_id, 'get_annotationwork', project_id):
        raise PermissionDenied

    dataset = DatasetManager().get_dataset(user_id, dataset_id)
    original = OriginalManager().get_original(project_id,
                                              dataset['original_id'])
    storage = StorageSerializer().get_storage(project_id,
                                              original['storage_id'])

    if storage['storage_type'] == 'LOCAL_NFS':
        image_link = request.build_absolute_uri(request.path) + 'image/'
    elif storage['storage_type'] == 'AWS_S3':
        ext = __get_extension(candidate_id)
        key = (dataset['file_path'] + candidate_id + '_' +
               str(frame).zfill(6) + ext)
        image_link = AwsS3Client().get_s3_down_url(
            storage['storage_config']['bucket'], key)
    else:
        raise UnknownStorageTypeError

    frame = DatasetFrameManager.get_dataset_frame(project_id, dataset_id,
                                                  frame,
                                                  storage['storage_type'])

    content = {'image_link': image_link, 'frame': frame['frame']}
    return HttpResponse(status=200,
                        content=json.dumps(content),
                        content_type='application/json')
Пример #8
0
 def retrieve(self, request, project_id, dataset_id, frame_id):
     username = request.user
     user_id = AccountManager.get_id_by_username(username)
     if not Permission.hasPermission(user_id, 'get_dataset', project_id):
         raise PermissionDenied
     frame = DatasetFrameManager.get_dataset_frame(project_id, dataset_id, frame_id, 'AZURE')
     return HttpResponse(content=json.dumps(frame), status=200, content_type='application/json')
Пример #9
0
def download_local_nfs_image(request, project_id, dataset_id, candidate_id,
                             frame):
    username = request.user
    user_id = AccountManager.get_id_by_username(username)
    if not Permission.hasPermission(user_id, 'get_annotationwork', project_id):
        raise PermissionDenied
    dataset_manager = DatasetManager()
    dataset_dir = dataset_manager.get_dataset_file_path(user_id, dataset_id)

    original_manager = OriginalManager()
    candidate = original_manager.get_dataset_candidate(candidate_id)
    analyzed_info = json.loads(candidate['analyzed_info'])
    msg_type = analyzed_info['msg_type']
    if msg_type == 'sensor_msgs/Image':
        extension = '.jpg'
    elif msg_type == 'sensor_msgs/PointCloud2':
        extension = '.pcd'

    file_path = dataset_dir + candidate_id + '_' + str(frame).zfill(
        6) + extension
    image = open(file_path, "rb").read()

    if msg_type == 'sensor_msgs/Image':
        return HttpResponse(image, content_type="image/jpeg")
    return HttpResponse(image, content_type="application/octet-stream")
Пример #10
0
 def permissions(self, request, project_id):
     print('permissions')
     username = request.user
     user_id = AccountManager.get_id_by_username(username)
     permissions = Permission.getPermissions(user_id, project_id)
     return HttpResponse(
         content=json.dumps({'permissions': permissions}),
         status=200, content_type='application/json')
Пример #11
0
 def retrieve(self, request, project_id):
     username = request.user
     user_id = AccountManager.get_id_by_username(username)
     project_manager = ProjectManager()
     if not Permission.hasPermission(user_id, 'get_project', project_id):
         raise PermissionDenied
     contents = project_manager.get_project(project_id, user_id)
     return HttpResponse(content=json.dumps(contents), status=200, content_type='application/json')
Пример #12
0
 def destroy(self, request, project_id, dataset_id):
     username = request.user
     dataset_manager = DatasetManager()
     user_id = AccountManager.get_id_by_username(username)
     if not Permission.hasPermission(user_id, 'delete_dataset', project_id):
         raise PermissionDenied
     dataset_manager.delete_dataset(user_id, dataset_id)
     return HttpResponse(status=204)
Пример #13
0
 def destroy(self, request, project_id):
     username = request.user
     user_id = AccountManager.get_id_by_username(username)
     project_manager = ProjectManager()
     if not Permission.hasPermission(user_id, 'delete_project', project_id):
         raise PermissionDenied
     project_manager.delete_project(project_id, user_id)
     return HttpResponse(status=204)
Пример #14
0
 def retrieve(self, request, project_id, group_id):
     username = request.user
     user_id = AccountManager.get_id_by_username(username)
     if not Permission.hasPermission(user_id, 'get_group', project_id):
         raise PermissionDenied
     content = GroupSerializer.get_group(project_id, user_id, group_id)
     return HttpResponse(content=json.dumps(content),
                         status=200,
                         content_type='application/json')
Пример #15
0
 def destroy(self, request, project_id, member_id):
     username = request.user
     user_id = AccountManager.get_id_by_username(username)
     if not Permission.hasPermission(user_id, 'delete_member', project_id):
         raise PermissionDenied
     # FIXME: Validate group_id
     MemberSerializer.destroy(project_id, member_id,
                              int(request.data.get('group_id', None)))
     return HttpResponse(status=204)
Пример #16
0
def download_local_nfs_archive(request, project_id, annotation_id):
    username = request.user
    user_id = AccountManager.get_id_by_username(username)
    if not Permission.hasPermission(user_id, 'get_label', project_id):
        raise PermissionDenied
    annotation_manager = AnnotationManager()
    archive_path = annotation_manager.get_archive_path(annotation_id)
    archive = open(archive_path, "rb").read()
    return HttpResponse(archive, content_type="application/octet-stream")
Пример #17
0
 def klassset(self, request, project_id):
     klassset_manager = KlasssetManager()
     username = request.user
     user_id = AccountManager.get_id_by_username(username)
     if not Permission.hasPermission(user_id, 'create_klassset', project_id):
         raise PermissionDenied
     new_klassset = json.loads(request.body.decode())
     klassset_manager.set_klassset(
         project_id, user_id, new_klassset['klasses'])
     return HttpResponse(status=201, content=json.dumps({}), content_type='application/json')
Пример #18
0
def download_link(request, project_id, dataset_id, candidate_id, frame):
    username = request.user
    user_id = AccountManager.get_id_by_username(username)
    if not Permission.hasPermission(user_id, 'get_annotationwork', project_id):
        raise PermissionDenied
    # TODO ckeck storage type
    content = request.build_absolute_uri(request.path) + 'image/'
    return HttpResponse(status=200,
                        content=json.dumps(content),
                        content_type='text/plain')
Пример #19
0
    def list(self, request, project_id):
        username = request.user
        user_id = AccountManager.get_id_by_username(username)
        if not Permission.hasPermission(user_id, 'list_member', project_id):
            raise PermissionDenied

        content = MemberSerializer.list(project_id)
        return HttpResponse(content=json.dumps(content),
                            status=200,
                            content_type='application/json')
Пример #20
0
 def destroy(self, request, project_id, dataset_id):
     username = request.user
     dataset_manager = DatasetManager()
     user_id = AccountManager.get_id_by_username(username)
     if not Permission.hasPermission(user_id, 'delete_dataset', project_id):
         raise PermissionDenied
     original_id = DatasetManager().get_dataset(user_id,
                                                dataset_id)['original_id']
     storage_id = OriginalManager().get_original(project_id,
                                                 original_id)['storage_id']
     storage = StorageSerializer().get_storage(project_id, storage_id)
     dataset_manager.delete_dataset(user_id, dataset_id, storage)
     return HttpResponse(status=204)
Пример #21
0
def download_local_nfs_image(request, project_id, dataset_id, candidate_id,
                             frame):
    username = request.user
    user_id = AccountManager.get_id_by_username(username)
    if not Permission.hasPermission(user_id, 'get_annotationwork', project_id):
        raise PermissionDenied

    dataset_dir = DatasetManager().get_dataset_file_path(user_id, dataset_id)
    ext = __get_extension(candidate_id)
    file_path = dataset_dir + candidate_id + '_' + str(frame).zfill(6) + ext
    image = open(file_path, "rb").read()

    if ext == '.pcd':
        return HttpResponse(image, content_type="application/octet-stream")
    return HttpResponse(image, content_type="image/jpeg")
Пример #22
0
    def list(self, request, project_id):
        username = request.user
        user_id = AccountManager.get_id_by_username(username)
        if not Permission.hasPermission(user_id, 'list_job', project_id):
            raise PermissionDenied
        per_page = int(request.GET.get(key="per_page", default=PER_PAGE))
        page = int(request.GET.get(key="page", default=1))
        sort_key = request.GET.get(key="sort_key", default=SORT_KEY)
        reverse_flag = request.GET.get(key="reverse_flag", default="false")
        is_reverse = (reverse_flag == "true")
        search_keyword = request.GET.get(key="search", default="")

        contents = JobSerializer.list_jobs(project_id, sort_key, is_reverse,
                                           per_page, page, search_keyword)
        return HttpResponse(content=json.dumps(contents),
                            status=200,
                            content_type='application/json')
Пример #23
0
    def get_projects(self, user_id, sort_key=SORT_KEY, is_reverse=False, per_page=PER_PAGE, page=1, search_keyword=""):
        validation_check(per_page, page)
        begin = per_page * (page - 1)

        project_ids = self.__user_projects(user_id)
        try:
            if is_reverse is False:
                projects = Projects.objects.order_by(sort_key).filter(
                    Q(id__in=project_ids),
                    Q(name__contains=search_keyword) | Q(description__contains=search_keyword))[begin:begin + per_page]
            else:
                projects = Projects.objects.order_by(sort_key).reverse().filter(
                    Q(id__in=project_ids),
                    Q(name__contains=search_keyword) | Q(description__contains=search_keyword))[begin:begin + per_page]
        except FieldError:
            projects = Projects.objects.order_by("id").filter(
                Q(id__in=project_ids),
                Q(name__contains=search_keyword) | Q(description__contains=search_keyword))[begin:begin + per_page]

        records = []
        for project in projects:
            record = {}
            record['id'] = project.id
            record['name'] = project.name
            record['description'] = project.description
            record['label_type'] = project.label_type
            record['created_at'] = str(project.created_at)
            record['can_delete'] = Permission.hasPermission(user_id, 'delete_project', project.id)
            records.append(record)
            try:
                klassset_manager = KlasssetManager()
                klassset = klassset_manager.get_klassset(project.id)
                record['klassset_name'] = klassset.name
                record['klassset_id'] = klassset.id
            except Exception:
                record['klassset_name'] = ''
                record['klassset_id'] = 0
        contents = {}
        contents['count'] = self.project_total_count(user_id)
        contents['records'] = records
        contents['sort_key'] = sort_key
        contents['per_page'] = per_page
        contents['page'] = page
        return contents
Пример #24
0
def file_upload(request, project_id):
    username = request.user
    user_id = AccountManager.get_id_by_username(username)
    if not Permission.hasPermission(user_id, 'create_original', project_id):
        raise PermissionDenied
    try:
        file = request.FILES['file']
        original_manager = OriginalManager()
        data = original_manager.save_file(project_id, file)
        response = JSONResponse(data, mimetype=response_mimetype(request))
        response['Content-Disposition'] = 'inline; filename=files.json'
        return response

    except Exception:  # FIXME
        ServiceLog.error(traceback.format_exc())
        data = json.dumps({'status': 'NG'})
        return HttpResponse(content=data,
                            status=400,
                            content_type='application/json')
Пример #25
0
    def create(self, request, project_id):
        username = request.user
        user_id = AccountManager.get_id_by_username(username)
        dataset_manager = DatasetManager()
        if not Permission.hasPermission(user_id, 'create_dataset', project_id):
            raise PermissionDenied
        name = request.data.get('name')
        file_path = request.data.get('file_path')
        frame_count = int(request.data.get('frame_count'))
        original_id = request.data.get('original_id', None)
        candidates = request.data.get('candidates')
        dataset_id = dataset_manager.create_dataset(name, file_path,
                                                    frame_count, original_id,
                                                    project_id, candidates)

        contents = dataset_manager.get_dataset(user_id, dataset_id)
        return HttpResponse(status=201,
                            content=contents,
                            content_type='application/json')
Пример #26
0
    def create(self, request, project_id):
        username = request.user
        user_id = AccountManager.get_id_by_username(username)
        if not Permission.hasPermission(user_id, 'create_calibration',
                                        project_id):
            raise PermissionDenied
        file = request.FILES['file']
        if int(request.META['CONTENT_LENGTH']) > 2048:
            raise ValidationError()
        file_path = '/tmp/' + file.name

        # write
        with open(file_path, 'ab') as destination:
            for chunk in file.chunks():
                destination.write(chunk)

        # validation
        try:
            camera_extrinsic_mat, camera_mat, dist_coeff = parse_calib(
                file_path)
        except Exception:
            raise ValidationError()
        serializer = CalibrationSerializer(
            data={
                'project':
                int(project_id),
                'name':
                file.name,
                'content':
                json.dumps({
                    'camera_extrinsic_mat': camera_extrinsic_mat,
                    'camera_mat': camera_mat,
                    'dist_coeff': dist_coeff
                }),
            })
        if not serializer.is_valid():
            raise ValidationError()
        serializer.save()
        contents = {}
        os.remove(file_path)
        response = JSONResponse(contents, mimetype=response_mimetype(request))
        response['Content-Disposition'] = 'inline; filename=files.json'
        return response
Пример #27
0
    def create(self, request, project_id):
        username = request.user
        user_id = AccountManager.get_id_by_username(username)
        if not Permission.hasPermission(user_id, 'create_member', project_id):
            raise PermissionDenied

        member_username = request.data.get('username')
        member_user_id = AccountManager.get_id_by_username(member_username)
        # FIXME: Validate group_id
        serializer = MemberSerializer(
            data={
                'project': int(project_id),
                'user': int(member_user_id),
                'group': int(request.data.get('group_id', None)),
            })
        if not serializer.is_valid():
            raise ValidationError
        serializer.save()
        return HttpResponse(content=json.dumps(serializer.data),
                            status=200,
                            content_type='application/json')
Пример #28
0
    def create(self, request, project_id):
        username = request.user
        user_id = AccountManager.get_id_by_username(username)
        if not Permission.hasPermission(user_id, 'create_storage', project_id):
            raise PermissionDenied

        serializer = StorageSerializer(
            data={
                'storage_type':
                request.data.get('storage_type', None),
                'storage_config':
                json.dumps(request.data.get('storage_config', None)),
                'project':
                project_id
            })
        if not serializer.is_valid():
            raise ValidationError
        content = serializer.save()
        return HttpResponse(status=201,
                            content=content,
                            content_type='application/json')
Пример #29
0
    def create(self, request, project_id):
        username = request.user
        user_id = AccountManager.get_id_by_username(username)
        if not Permission.hasPermission(user_id, 'create_job', project_id):
            raise PermissionDenied

        job_type = request.data['job_type']
        if job_type == 'ANALYZER':
            if not Permission.hasPermission(user_id, 'get_original',
                                            project_id):
                raise PermissionDenied
            job_config = request.data['job_config']
            original_id = int(job_config['original_id'])
            JobSerializer.analyze(user_id, project_id, original_id)
        elif job_type == 'EXTRACTOR':
            if not Permission.hasPermission(user_id, 'get_original',
                                            project_id):
                raise PermissionDenied
            if not Permission.hasPermission(user_id, 'create_dataset',
                                            project_id):
                raise PermissionDenied
            job_config = request.data['job_config']
            original_id = int(job_config['original_id'])
            candidates = job_config['candidates']
            name = job_config['name']
            JobSerializer.extract(user_id, project_id, original_id, candidates,
                                  name)
        elif job_type == 'ARCHIVER':
            if not Permission.hasPermission(user_id, 'get_original',
                                            project_id):
                raise PermissionDenied
            if not Permission.hasPermission(user_id, 'get_label', project_id):
                raise PermissionDenied
            job_config = request.data['job_config']
            original_id = int(job_config['original_id'])
            dataset_id = int(job_config['dataset_id'])
            annotation_id = int(job_config['annotation_id'])
            is_include_image = bool(job_config['include_image'])
            JobSerializer.archive(user_id, int(project_id), dataset_id,
                                  original_id, annotation_id, is_include_image)
        else:
            raise ValidationError

        return HttpResponse(status=201,
                            content=json.dumps({}),
                            content_type='application/json')