61 lines
2.6 KiB
Python
61 lines
2.6 KiB
Python
"""Stored compute-center locations."""
|
|
|
|
from sqlalchemy import Boolean, Column, DateTime, Float, Integer, JSON, String, Text, UniqueConstraint
|
|
from sqlalchemy.sql import func
|
|
|
|
from app.core.time import to_iso8601_utc
|
|
from app.db.session import Base
|
|
|
|
|
|
class ComputeCenterLocationRecord(Base):
|
|
"""Current known location for a compute-center record."""
|
|
|
|
__tablename__ = "compute_center_locations"
|
|
__table_args__ = (
|
|
UniqueConstraint("source", "source_id", name="uq_compute_center_location_source_id"),
|
|
)
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
source = Column(String(100), nullable=False, index=True)
|
|
source_id = Column(String(255), nullable=False, index=True)
|
|
name = Column(String(500), nullable=True)
|
|
operator = Column(String(255), nullable=True)
|
|
site = Column(String(255), nullable=True)
|
|
city = Column(String(255), nullable=True)
|
|
country = Column(String(255), nullable=True)
|
|
latitude = Column(Float, nullable=True)
|
|
longitude = Column(Float, nullable=True)
|
|
precision = Column(String(30), nullable=False, default="city")
|
|
confidence = Column(Float, nullable=True)
|
|
location_source = Column(String(80), nullable=False, default="stored_compute_center_location", index=True)
|
|
source_url = Column(String(500), nullable=True)
|
|
source_note = Column(Text, nullable=True)
|
|
raw_payload = Column(JSON, nullable=False, default=dict)
|
|
needs_confirmation = Column(Boolean, nullable=False, default=False, index=True)
|
|
verification_status = Column(String(30), nullable=False, default="verified", index=True)
|
|
verified_at = Column(DateTime(timezone=True), 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())
|
|
|
|
def to_location_dict(self) -> dict:
|
|
return {
|
|
"source": self.source,
|
|
"source_id": self.source_id,
|
|
"name": self.name,
|
|
"operator": self.operator,
|
|
"site": self.site,
|
|
"city": self.city,
|
|
"country": self.country,
|
|
"latitude": self.latitude,
|
|
"longitude": self.longitude,
|
|
"precision": self.precision,
|
|
"confidence": self.confidence,
|
|
"location_source": self.location_source,
|
|
"source_url": self.source_url,
|
|
"source_note": self.source_note,
|
|
"raw_payload": self.raw_payload or {},
|
|
"needs_confirmation": self.needs_confirmation,
|
|
"verification_status": self.verification_status,
|
|
"verified_at": to_iso8601_utc(self.verified_at),
|
|
}
|