mirror of
https://github.com/leaders-of-digital-9-task/backend.git
synced 2024-11-10 20:16:37 +03:00
fixed celery
This commit is contained in:
parent
1e19f7edd0
commit
8b88e97489
|
@ -1,5 +0,0 @@
|
|||
__version__ = "0.1.0"
|
||||
__version_info__ = tuple(
|
||||
int(num) if num.isdigit() else num
|
||||
for num in __version__.replace("-", ".", 1).split(".")
|
||||
)
|
|
@ -5,7 +5,7 @@ from pathlib import Path
|
|||
|
||||
import environ
|
||||
|
||||
ROOT_DIR = Path(__file__).resolve(strict=True).parent.parent.parent
|
||||
ROOT_DIR = Path(__file__).resolve(strict=True).parent.parent.parent.parent
|
||||
# image_markuper/
|
||||
APPS_DIR = ROOT_DIR / "image_markuper"
|
||||
env = environ.Env()
|
||||
|
@ -71,11 +71,7 @@ THIRD_PARTY_APPS = [
|
|||
"drf_spectacular",
|
||||
]
|
||||
|
||||
LOCAL_APPS = [
|
||||
"image_markuper.users",
|
||||
"image_markuper.dicom"
|
||||
# Your stuff: custom apps go here
|
||||
]
|
||||
LOCAL_APPS = ["users", "dicom"]
|
||||
# https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
|
||||
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
|
||||
|
|
@ -180,7 +180,7 @@ class ProjectSerializer(serializers.ModelSerializer):
|
|||
|
||||
class Meta:
|
||||
model = Project
|
||||
fields = ["files", "slug", "created"]
|
||||
fields = ["files", "slug", "created", "stl"]
|
||||
|
||||
|
||||
class PatologyGenerateSerializer(serializers.Serializer):
|
||||
|
|
|
@ -9,6 +9,7 @@ User = get_user_model()
|
|||
class Project(models.Model):
|
||||
user = models.ForeignKey(User, related_name="projects", on_delete=models.CASCADE)
|
||||
slug = models.SlugField(max_length=10)
|
||||
stl = models.FileField(blank=True)
|
||||
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ def process_files(
|
|||
if content_type == "DICOM medical imaging data":
|
||||
Dicom.objects.create(file=file, project=project, user=user)
|
||||
elif "Zip" in content_type:
|
||||
dit_path = f"tmp/{generate_charset(10)}"
|
||||
dit_path = f"/tmp/{generate_charset(10)}"
|
||||
os.mkdir(dit_path)
|
||||
with zipfile.ZipFile(file.temporary_file_path(), "r") as zip_ref:
|
||||
zip_ref.extractall(dit_path)
|
||||
|
@ -96,7 +96,7 @@ def generate_3d_point_cloud(project_slug: str):
|
|||
return point_clouds
|
||||
|
||||
|
||||
def generate_3d_model(project: Project, thr=800) -> str:
|
||||
def generate_3d_model(project: Project, thr=800):
|
||||
image = []
|
||||
for file in project.files.all():
|
||||
image.append(pydicom.dcmread(file.file.path).pixel_array)
|
||||
|
@ -111,4 +111,9 @@ def generate_3d_model(project: Project, thr=800) -> str:
|
|||
|
||||
pth = f"/tmp/{generate_charset(4)}.stl"
|
||||
solid.save(pth)
|
||||
return pth
|
||||
path = Path(pth)
|
||||
with path.open(mode="rb") as f:
|
||||
project.stl = File(f, name=pth.split("/")[-1])
|
||||
project.save()
|
||||
|
||||
os.remove(pth)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from dicom.models import Dicom, Project
|
||||
from dicom.tasks import process_project
|
||||
from django.db.models.signals import post_save
|
||||
from django.dispatch import receiver
|
||||
from utils.generators import generate_charset
|
||||
|
@ -12,6 +13,7 @@ def create_project(sender, instance: Project, created, **kwargs):
|
|||
slug = generate_charset(5)
|
||||
instance.slug = slug
|
||||
instance.save()
|
||||
process_project.apply_async(kwargs={"slug": slug})
|
||||
|
||||
|
||||
@receiver(post_save, sender=Dicom)
|
||||
|
|
|
@ -4,6 +4,7 @@ from dicom.services import generate_3d_model
|
|||
|
||||
|
||||
@shared_task()
|
||||
def process_dicom(pk: int):
|
||||
generate_3d_model(Project.objects.get(pk=pk))
|
||||
return pk
|
||||
def process_project(slug: str):
|
||||
print(slug)
|
||||
generate_3d_model(Project.objects.get(slug=slug))
|
||||
return slug
|
||||
|
|
Loading…
Reference in New Issue
Block a user