project.py 1.2 KB

123456789101112131415161718192021222324252627282930
  1. """Project model."""
  2. import json
  3. from datetime import datetime
  4. from sqlalchemy import Column, Integer, String, Text, DateTime
  5. from ..database import Base
  6. class Project(Base):
  7. """A simulation project containing multiple plans and results."""
  8. __tablename__ = "projects"
  9. id = Column(Integer, primary_key=True, index=True)
  10. name = Column(String(200), nullable=False, index=True)
  11. description = Column(Text, default="")
  12. topology = Column(String(20), default="SSSR") # SSSR / DRSS / SDSR
  13. model_path = Column(String(500), default="")
  14. status = Column(String(20), default="draft") # draft / active / completed / archived
  15. boundary_conditions = Column(Text, default="{}") # JSON: dimensions, targets, constraints
  16. created_at = Column(DateTime, default=datetime.utcnow)
  17. updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
  18. def get_boundary_conditions(self) -> dict:
  19. try:
  20. return json.loads(self.boundary_conditions) if self.boundary_conditions else {}
  21. except (json.JSONDecodeError, TypeError):
  22. return {}
  23. def set_boundary_conditions(self, data: dict) -> None:
  24. self.boundary_conditions = json.dumps(data, ensure_ascii=False)