- backend/schemas.py: TemplateUpdate 添加 classes/rules 字段 - backend/models.py: Template 添加 description 列 - backend/routers/templates.py: create/update 打包/解包 mapping_rules.classes (已有) - backend/main.py: seed 腹腔镜胆囊切除术35分类模板 - src/lib/api.ts: updateTemplate 改 PATCH,补齐 color/z_index,_mapTemplate 对齐 TS 接口 - src/store/useStore.ts: 新增 activeTemplateId/setActiveTemplateId - src/components/TemplateRegistry.tsx: 随机颜色(HSL轮盘)、HTML5拖拽排序、批量JSON导入、一键载入腹腔镜模板、handleSave 补齐必填字段 - src/components/OntologyInspector.tsx: 完全重写,从store读取模板,支持模板切换和自定义分类 - src/components/VideoWorkspace.tsx: 进入时自动加载模板列表 - src/components/ProjectLibrary.tsx: 修复状态字符串 TS 严格类型报错 - 工程分析/: 更新实现方案与经验记录 Timestamp: 20260430_222830
124 lines
4.2 KiB
Python
124 lines
4.2 KiB
Python
"""SQLAlchemy ORM models."""
|
|
|
|
from sqlalchemy import (
|
|
Column,
|
|
Integer,
|
|
String,
|
|
Text,
|
|
DateTime,
|
|
ForeignKey,
|
|
JSON,
|
|
Float,
|
|
)
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
|
|
from database import Base
|
|
|
|
|
|
class Project(Base):
|
|
"""Project model representing a segmentation project."""
|
|
|
|
__tablename__ = "projects"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
name = Column(String(255), nullable=False)
|
|
description = Column(Text, nullable=True)
|
|
video_path = Column(String(512), nullable=True)
|
|
thumbnail_url = Column(String(512), nullable=True)
|
|
status = Column(String(50), default="Ready", nullable=False)
|
|
source_type = Column(String(20), default="video", nullable=False) # video | dicom
|
|
original_fps = Column(Float, nullable=True)
|
|
parse_fps = Column(Float, default=30.0, nullable=False)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at = Column(
|
|
DateTime(timezone=True), server_default=func.now(), onupdate=func.now()
|
|
)
|
|
|
|
frames = relationship("Frame", back_populates="project", cascade="all, delete-orphan")
|
|
annotations = relationship(
|
|
"Annotation", back_populates="project", cascade="all, delete-orphan"
|
|
)
|
|
|
|
|
|
class Frame(Base):
|
|
"""Frame model representing an extracted video frame."""
|
|
|
|
__tablename__ = "frames"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
project_id = Column(Integer, ForeignKey("projects.id", ondelete="CASCADE"), nullable=False)
|
|
frame_index = Column(Integer, nullable=False)
|
|
image_url = Column(String(512), nullable=False)
|
|
width = Column(Integer, nullable=True)
|
|
height = Column(Integer, nullable=True)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
project = relationship("Project", back_populates="frames")
|
|
annotations = relationship(
|
|
"Annotation", back_populates="frame", cascade="all, delete-orphan"
|
|
)
|
|
|
|
|
|
class Template(Base):
|
|
"""Template (Ontology) model for segmentation classes."""
|
|
|
|
__tablename__ = "templates"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
name = Column(String(255), nullable=False)
|
|
description = Column(Text, nullable=True)
|
|
color = Column(String(50), nullable=False)
|
|
z_index = Column(Integer, default=0, nullable=False)
|
|
mapping_rules = Column(JSON, nullable=True)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
annotations = relationship(
|
|
"Annotation", back_populates="template", cascade="all, delete-orphan"
|
|
)
|
|
|
|
|
|
class Annotation(Base):
|
|
"""Annotation model for segmentation masks and prompts."""
|
|
|
|
__tablename__ = "annotations"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
project_id = Column(
|
|
Integer, ForeignKey("projects.id", ondelete="CASCADE"), nullable=False
|
|
)
|
|
frame_id = Column(
|
|
Integer, ForeignKey("frames.id", ondelete="CASCADE"), nullable=True
|
|
)
|
|
template_id = Column(
|
|
Integer, ForeignKey("templates.id", ondelete="SET NULL"), nullable=True
|
|
)
|
|
mask_data = Column(JSON, nullable=True)
|
|
points = Column(JSON, nullable=True)
|
|
bbox = Column(JSON, nullable=True)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at = Column(
|
|
DateTime(timezone=True), server_default=func.now(), onupdate=func.now()
|
|
)
|
|
|
|
project = relationship("Project", back_populates="annotations")
|
|
frame = relationship("Frame", back_populates="annotations")
|
|
template = relationship("Template", back_populates="annotations")
|
|
masks = relationship("Mask", back_populates="annotation", cascade="all, delete-orphan")
|
|
|
|
|
|
class Mask(Base):
|
|
"""Mask model for exported/derived mask files."""
|
|
|
|
__tablename__ = "masks"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
annotation_id = Column(
|
|
Integer, ForeignKey("annotations.id", ondelete="CASCADE"), nullable=False
|
|
)
|
|
mask_url = Column(String(512), nullable=False)
|
|
format = Column(String(50), default="png", nullable=False) # png / rle / json
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
annotation = relationship("Annotation", back_populates="masks")
|