两张表列名沿用平台工参表,已有快照由迁移 0008 原样搬过去。即席查询的 result 补 tableParams、columnname,计数补 indexcount=0,缺这些服务端会返回 stat 0。
173 lines
8.2 KiB
Python
173 lines
8.2 KiB
Python
from __future__ import annotations
|
|
|
|
from datetime import date, datetime, timezone
|
|
|
|
from sqlalchemy import JSON, BigInteger, Boolean, Date, DateTime, Float, ForeignKey, Index, Integer, String, Text, UniqueConstraint
|
|
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
|
|
|
|
|
|
def utcnow() -> datetime:
|
|
return datetime.now(timezone.utc)
|
|
|
|
|
|
class Base(DeclarativeBase):
|
|
pass
|
|
|
|
|
|
class AppSetting(Base):
|
|
__tablename__ = "app_setting"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
login_mode: Mapped[str] = mapped_column(String(16), default="local")
|
|
credential_refresh_seconds: Mapped[int] = mapped_column(Integer, default=300)
|
|
worker_concurrency: Mapped[int] = mapped_column(Integer, default=4)
|
|
db_host: Mapped[str] = mapped_column(String(255), default="")
|
|
db_port: Mapped[int] = mapped_column(Integer, default=5432)
|
|
db_name: Mapped[str] = mapped_column(String(128), default="")
|
|
db_user: Mapped[str] = mapped_column(String(128), default="")
|
|
db_password: Mapped[str] = mapped_column(Text, default="")
|
|
jwt_secret: Mapped[str] = mapped_column(String(128), default="")
|
|
|
|
|
|
class User(Base):
|
|
__tablename__ = "app_user"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
username: Mapped[str] = mapped_column(String(64), unique=True, index=True)
|
|
password_hash: Mapped[str] = mapped_column(String(200))
|
|
role: Mapped[str] = mapped_column(String(16), default="user")
|
|
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=utcnow)
|
|
|
|
|
|
class NqiAccount(Base):
|
|
__tablename__ = "nqi_account"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
login_id: Mapped[str] = mapped_column(String(64), unique=True, index=True)
|
|
user_name: Mapped[str] = mapped_column(String(128), default="")
|
|
city_name: Mapped[str] = mapped_column(String(64), default="")
|
|
org_name: Mapped[str] = mapped_column(String(128), default="")
|
|
cookies: Mapped[list] = mapped_column(JSON, default=list)
|
|
role: Mapped[str] = mapped_column(String(16), default="user")
|
|
session_open: Mapped[bool] = mapped_column(Boolean, default=True)
|
|
credential_valid: Mapped[bool] = mapped_column(Boolean, default=True)
|
|
active_tasks: Mapped[int] = mapped_column(Integer, default=0)
|
|
task_runs: Mapped[int] = mapped_column(Integer, default=0)
|
|
last_task_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=utcnow)
|
|
saved_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=utcnow)
|
|
|
|
|
|
class CellData(Base):
|
|
__tablename__ = "CellData"
|
|
__table_args__ = (UniqueConstraint("cell_key", "observed_at", "source", name="uq_cell_time_source"),)
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
cell_key: Mapped[str] = mapped_column(String(128), index=True)
|
|
observed_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), index=True)
|
|
source: Mapped[str] = mapped_column(String(16))
|
|
metrics: Mapped[dict] = mapped_column(JSON, default=dict)
|
|
|
|
|
|
class CollectionSource(Base):
|
|
__tablename__ = "collection_source"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
name: Mapped[str] = mapped_column(String(128))
|
|
kind: Mapped[str] = mapped_column(String(16))
|
|
period_days: Mapped[int] = mapped_column(Integer, default=1)
|
|
config: Mapped[dict] = mapped_column(JSON, default=dict)
|
|
enabled: Mapped[bool] = mapped_column(Boolean, default=True)
|
|
next_run_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
|
|
last_error: Mapped[str] = mapped_column(Text, default="")
|
|
|
|
|
|
class GongcanSnapshot(Base):
|
|
"""某地市某一天的全量 4G/5G 小区工参。status 兼作取数锁:loading 时别的任务等它。"""
|
|
|
|
__tablename__ = "gongcan_snapshot"
|
|
__table_args__ = (UniqueConstraint("city", "snapshot_date", name="uq_gongcan_city_date"),)
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
city: Mapped[str] = mapped_column(String(32))
|
|
snapshot_date: Mapped[date] = mapped_column(Date)
|
|
status: Mapped[str] = mapped_column(String(16), default="loading")
|
|
attr_source: Mapped[str] = mapped_column(String(16), default="")
|
|
lte_cells: Mapped[int] = mapped_column(Integer, default=0)
|
|
nr_cells: Mapped[int] = mapped_column(Integer, default=0)
|
|
located_cells: Mapped[int] = mapped_column(Integer, default=0)
|
|
error: Mapped[str] = mapped_column(Text, default="")
|
|
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=utcnow)
|
|
updated_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=utcnow)
|
|
|
|
|
|
class CellData4G(Base):
|
|
"""4G 小区工参快照,列名沿用平台 4G 工参表。"""
|
|
|
|
__tablename__ = "CellData_4G"
|
|
__table_args__ = (
|
|
UniqueConstraint("snapshot_id", "cgi", name="uq_celldata_4g_cgi"),
|
|
Index("ix_celldata_4g_station", "snapshot_id", "station_name"),
|
|
)
|
|
|
|
id: Mapped[int] = mapped_column(BigInteger().with_variant(Integer, "sqlite"), primary_key=True)
|
|
snapshot_id: Mapped[int] = mapped_column(ForeignKey("gongcan_snapshot.id", ondelete="CASCADE"))
|
|
cgi: Mapped[str] = mapped_column(String(64))
|
|
cell_name: Mapped[str] = mapped_column(Text, default="")
|
|
station_name: Mapped[str] = mapped_column(Text, default="")
|
|
latitude: Mapped[float | None] = mapped_column(Float, nullable=True)
|
|
longitude: Mapped[float | None] = mapped_column(Float, nullable=True)
|
|
enodeb_id: Mapped[str] = mapped_column(Text, default="")
|
|
enodeb_name: Mapped[str] = mapped_column(Text, default="")
|
|
network_type: Mapped[str] = mapped_column(Text, default="")
|
|
area: Mapped[str] = mapped_column(Text, default="")
|
|
town: Mapped[str] = mapped_column(Text, default="")
|
|
state: Mapped[str] = mapped_column(Text, default="")
|
|
cover_type: Mapped[str] = mapped_column(Text, default="")
|
|
frequency_band: Mapped[str] = mapped_column(Text, default="")
|
|
vendor: Mapped[str] = mapped_column(Text, default="")
|
|
azimuth: Mapped[str] = mapped_column(Text, default="")
|
|
|
|
|
|
class CellData5G(Base):
|
|
"""5G 小区工参快照,列名沿用平台 5G 工参表。"""
|
|
|
|
__tablename__ = "CellData_5G"
|
|
__table_args__ = (
|
|
UniqueConstraint("snapshot_id", "ncgi", name="uq_celldata_5g_ncgi"),
|
|
Index("ix_celldata_5g_station", "snapshot_id", "station_name"),
|
|
)
|
|
|
|
id: Mapped[int] = mapped_column(BigInteger().with_variant(Integer, "sqlite"), primary_key=True)
|
|
snapshot_id: Mapped[int] = mapped_column(ForeignKey("gongcan_snapshot.id", ondelete="CASCADE"))
|
|
ncgi: Mapped[str] = mapped_column(String(64))
|
|
nrcell_name: Mapped[str] = mapped_column(Text, default="")
|
|
station_name: Mapped[str] = mapped_column(Text, default="")
|
|
latitude: Mapped[float | None] = mapped_column(Float, nullable=True)
|
|
longitude: Mapped[float | None] = mapped_column(Float, nullable=True)
|
|
gnodeb_id: Mapped[str] = mapped_column(Text, default="")
|
|
gnodeb_name: Mapped[str] = mapped_column(Text, default="")
|
|
network_type: Mapped[str] = mapped_column(Text, default="")
|
|
area: Mapped[str] = mapped_column(Text, default="")
|
|
town: Mapped[str] = mapped_column(Text, default="")
|
|
state: Mapped[str] = mapped_column(Text, default="")
|
|
cover_type: Mapped[str] = mapped_column(Text, default="")
|
|
frequency_band: Mapped[str] = mapped_column(Text, default="")
|
|
vendor: Mapped[str] = mapped_column(Text, default="")
|
|
azimuth: Mapped[str] = mapped_column(Text, default="")
|
|
|
|
|
|
class ExportTask(Base):
|
|
__tablename__ = "export_task"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
owner_kind: Mapped[str] = mapped_column(String(16))
|
|
owner_id: Mapped[str] = mapped_column(String(64), index=True)
|
|
status: Mapped[str] = mapped_column(String(16), default="queued", index=True)
|
|
file_format: Mapped[str] = mapped_column(String(8))
|
|
params: Mapped[dict] = mapped_column(JSON, default=dict)
|
|
result_name: Mapped[str] = mapped_column(String(255), default="")
|
|
error: Mapped[str] = mapped_column(Text, default="")
|
|
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=utcnow)
|
|
finished_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
|