59 lines
2.2 KiB
Python
59 lines
2.2 KiB
Python
from sqlalchemy import Column, String, DateTime, Boolean, Text, Date
|
|
from datetime import datetime
|
|
from backend.database import Base
|
|
|
|
|
|
class Emitter(Base):
|
|
__tablename__ = "emitters"
|
|
|
|
id = Column(String, primary_key=True, index=True)
|
|
unit_type = Column(String, nullable=False)
|
|
last_seen = Column(DateTime, default=datetime.utcnow)
|
|
last_file = Column(String, nullable=False)
|
|
status = Column(String, nullable=False)
|
|
notes = Column(String, nullable=True)
|
|
|
|
|
|
class RosterUnit(Base):
|
|
"""
|
|
Roster table: represents our *intended assignment* of a unit.
|
|
This is editable from the GUI.
|
|
|
|
Supports multiple device types (seismograph, modem) with type-specific fields.
|
|
"""
|
|
__tablename__ = "roster"
|
|
|
|
# Core fields (all device types)
|
|
id = Column(String, primary_key=True, index=True)
|
|
unit_type = Column(String, default="series3") # Backward compatibility
|
|
device_type = Column(String, default="seismograph") # "seismograph" | "modem"
|
|
deployed = Column(Boolean, default=True)
|
|
retired = Column(Boolean, default=False)
|
|
note = Column(String, nullable=True)
|
|
project_id = Column(String, nullable=True)
|
|
location = Column(String, nullable=True) # Legacy field - use address/coordinates instead
|
|
address = Column(String, nullable=True) # Human-readable address
|
|
coordinates = Column(String, nullable=True) # Lat,Lon format: "34.0522,-118.2437"
|
|
last_updated = Column(DateTime, default=datetime.utcnow)
|
|
|
|
# Seismograph-specific fields (nullable for modems)
|
|
last_calibrated = Column(Date, nullable=True)
|
|
next_calibration_due = Column(Date, nullable=True)
|
|
deployed_with_modem_id = Column(String, nullable=True) # FK to another RosterUnit
|
|
|
|
# Modem-specific fields (nullable for seismographs)
|
|
ip_address = Column(String, nullable=True)
|
|
phone_number = Column(String, nullable=True)
|
|
hardware_model = Column(String, nullable=True)
|
|
|
|
|
|
class IgnoredUnit(Base):
|
|
"""
|
|
Ignored units: units that report but should be filtered out from unknown emitters.
|
|
Used to suppress noise from old projects.
|
|
"""
|
|
__tablename__ = "ignored_units"
|
|
|
|
id = Column(String, primary_key=True, index=True)
|
|
reason = Column(String, nullable=True)
|
|
ignored_at = Column(DateTime, default=datetime.utcnow) |