コード例 #1
0
ファイル: views.py プロジェクト: Tommos0/grand-challenge.org
    def form_valid(self, form):
        uploaded_file = form.cleaned_data["chunked_upload"][0]

        with uploaded_file.open() as f:
            form.instance.labels = process_csv_file(f)

        return super().form_valid(form)
コード例 #2
0
ファイル: views.py プロジェクト: comic/comic-django
    def form_valid(self, form):
        uploaded_file = form.cleaned_data["chunked_upload"][0]

        with uploaded_file.open() as f:
            form.instance.labels = process_csv_file(f)

        return super().form_valid(form)
コード例 #3
0
    def _copy_output_files(self, *, container, base_dir: Path):
        output_files = {
            base_dir / Path(f)
            for f in container.exec_run(f"find {base_dir} -type f")
            .output.decode()
            .splitlines()
        }

        if not output_files:
            raise ValueError("Output directory is empty")

        job = SubmissionToAnnotationSetJob.objects.get(pk=self._job_id)
        annotationset = AnnotationSet.objects.create(
            creator=job.submission.creator,
            base=job.base,
            submission=job.submission,
            kind=AnnotationSet.PREDICTION,
        )

        if self.__was_unzipped:
            with TemporaryDirectory() as tmpdir:
                input_files = set()

                for file in output_files:
                    tmpfile = Path(
                        safe_join(tmpdir, file.relative_to(base_dir))
                    )
                    tmpfile.parent.mkdir(parents=True, exist_ok=True)

                    with open(tmpfile, "wb") as outfile:
                        infile = get_file(container=container, src=file)
                        buffer = True
                        while buffer:
                            buffer = infile.read(1024)
                            outfile.write(buffer)

                    input_files.add(tmpfile)

                importer_result = import_images(files=input_files,)

            annotationset.images.add(*importer_result.new_images)

        else:
            if not len(output_files) == 1:
                raise RuntimeError("This submission has too many files.")

            f = get_file(container=container, src=output_files.pop())
            annotationset.labels = process_csv_file(f)
            annotationset.save()
コード例 #4
0
ファイル: models.py プロジェクト: comic/comic-django
    def _copy_output_files(self, *, container, base_dir: Path):
        output_files = [
            base_dir / Path(f)
            for f in container.exec_run(f"find {base_dir} -type f")
            .output.decode()
            .splitlines()
        ]

        if not output_files:
            raise ValueError("Output directory is empty")

        # TODO: This thing should not interact with the database
        job = SubmissionToAnnotationSetJob.objects.get(pk=self._job_id)
        annotationset = AnnotationSet.objects.create(
            creator=job.submission.creator,
            base=job.base,
            submission=job.submission,
            kind=AnnotationSet.PREDICTION,
        )

        if self.__was_unzipped:

            # Create the upload session but do not save it until we have the
            # files
            upload_session = RawImageUploadSession(annotationset=annotationset)

            images = []

            for file in output_files:
                new_uuid = uuid.uuid4()

                django_file = File(get_file(container=container, src=file))

                staged_file = StagedFile(
                    csrf="staging_conversion_csrf",
                    client_id=self._job_id,
                    client_filename=file.name,
                    file_id=new_uuid,
                    timeout=timezone.now() + timedelta(hours=24),
                    start_byte=0,
                    end_byte=django_file.size - 1,
                    total_size=django_file.size,
                )
                staged_file.file.save(f"{uuid.uuid4()}", django_file)
                staged_file.save()

                staged_ajax_file = StagedAjaxFile(new_uuid)

                images.append(
                    RawImageFile(
                        upload_session=upload_session,
                        filename=staged_ajax_file.name,
                        staged_file_id=staged_ajax_file.uuid,
                    )
                )

            upload_session.save(skip_processing=True)
            RawImageFile.objects.bulk_create(images)
            upload_session.process_images()

        else:
            assert len(output_files) == 1

            f = get_file(container=container, src=output_files[0])
            annotationset.labels = process_csv_file(f)
            annotationset.save()
コード例 #5
0
    def _copy_output_files(self, *, container, base_dir: Path):
        output_files = [
            base_dir / Path(f)
            for f in container.exec_run(f"find {base_dir} -type f")
            .output.decode()
            .splitlines()
        ]

        if not output_files:
            raise ValueError("Output directory is empty")

        # TODO: This thing should not interact with the database
        job = SubmissionToAnnotationSetJob.objects.get(pk=self._job_id)
        annotationset = AnnotationSet.objects.create(
            creator=job.submission.creator,
            base=job.base,
            submission=job.submission,
            kind=AnnotationSet.PREDICTION,
        )

        if self.__was_unzipped:

            # Create the upload session but do not save it until we have the
            # files
            upload_session = RawImageUploadSession(annotationset=annotationset)

            images = []

            for file in output_files:
                new_uuid = uuid.uuid4()

                django_file = File(get_file(container=container, src=file))

                staged_file = StagedFile(
                    csrf="staging_conversion_csrf",
                    client_id=self._job_id,
                    client_filename=file.name,
                    file_id=new_uuid,
                    timeout=timezone.now() + timedelta(hours=24),
                    start_byte=0,
                    end_byte=django_file.size - 1,
                    total_size=django_file.size,
                )
                staged_file.file.save(f"{uuid.uuid4()}", django_file)
                staged_file.save()

                staged_ajax_file = StagedAjaxFile(new_uuid)

                images.append(
                    RawImageFile(
                        upload_session=upload_session,
                        filename=staged_ajax_file.name,
                        staged_file_id=staged_ajax_file.uuid,
                    )
                )

            upload_session.save(skip_processing=True)
            RawImageFile.objects.bulk_create(images)
            upload_session.process_images()

        else:
            assert len(output_files) == 1

            f = get_file(container=container, src=output_files[0])
            annotationset.labels = process_csv_file(f)
            annotationset.save()