-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql_models.py
More file actions
53 lines (40 loc) · 2.14 KB
/
sql_models.py
File metadata and controls
53 lines (40 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from sqlalchemy import Column, Integer, String, Float, DateTime, Text, ForeignKey
from sqlalchemy.orm import relationship
from database import Base
import datetime
class AnalysisResult(Base):
__tablename__ = "results"
id = Column(Integer, primary_key=True, index=True)
file_id = Column(String, unique=True, index=True)
filename = Column(String)
analysis_time = Column(DateTime, default=datetime.datetime.utcnow)
avg_occupancy_rate = Column(Float)
max_occupied_chairs = Column(Integer)
total_interactions = Column(Integer)
class MultiCameraSetup(Base):
"""Stores multi-camera configuration setups."""
__tablename__ = "multi_camera_setups"
id = Column(Integer, primary_key=True, index=True)
name = Column(String, unique=True, index=True)
created_at = Column(DateTime, default=datetime.datetime.utcnow)
updated_at = Column(DateTime, default=datetime.datetime.utcnow, onupdate=datetime.datetime.utcnow)
# Relationship to cameras
cameras = relationship("CameraConfig", back_populates="setup", cascade="all, delete-orphan")
class CameraConfig(Base):
"""Stores individual camera configuration within a multi-camera setup."""
__tablename__ = "camera_configs"
id = Column(Integer, primary_key=True, index=True)
setup_id = Column(Integer, ForeignKey("multi_camera_setups.id", ondelete="CASCADE"))
camera_id = Column(Integer) # User-defined camera identifier
priority = Column(Integer, default=1)
video_path = Column(String, nullable=True) # Path to video file or RTSP URL
zones_json = Column(Text, nullable=True) # Store zones as JSON string
# Relationship back to setup
setup = relationship("MultiCameraSetup", back_populates="cameras")
class OverlapRegion(Base):
"""Stores overlap regions between cameras."""
__tablename__ = "overlap_regions"
id = Column(Integer, primary_key=True, index=True)
setup_id = Column(Integer, ForeignKey("multi_camera_setups.id", ondelete="CASCADE"))
region_json = Column(Text) # Store region coords as JSON: {"x1": ..., "y1": ..., "x2": ..., "y2": ...}
camera_ids_json = Column(Text) # Store as JSON array: [1, 2]