每个逻辑站点一个排队任务,与采集共用并行数量;工参按拆除前后规则取本系统快照,指标暂用模拟数据;全部站点结束后写频段清退、低效拆除两份结果表。去掉原来的通用导出任务。
225 lines
11 KiB
Python
225 lines
11 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("cgi", "snapshot_id", name="uq_celldata_4g_cgi"),
|
|
Index("ix_celldata_4g_enodeb", "enodeb_id", "snapshot_id"),
|
|
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("ncgi", "snapshot_id", name="uq_celldata_5g_ncgi"),
|
|
Index("ix_celldata_5g_gnodeb", "gnodeb_id", "snapshot_id"),
|
|
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 EvalJob(Base):
|
|
"""一次提交:单个站点/小区,或一份清单。结果按退网工单类型写成频段清退、低效拆除两份表。"""
|
|
|
|
__tablename__ = "eval_job"
|
|
|
|
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)
|
|
owner_name: Mapped[str] = mapped_column(String(128), default="")
|
|
mode: Mapped[str] = mapped_column(String(8))
|
|
title: Mapped[str] = mapped_column(String(255), default="")
|
|
city: Mapped[str] = mapped_column(String(32), default="")
|
|
source_name: Mapped[str] = mapped_column(String(255), default="")
|
|
status: Mapped[str] = mapped_column(String(16), default="queued", index=True)
|
|
total: Mapped[int] = mapped_column(Integer, default=0)
|
|
finished: Mapped[int] = mapped_column(Integer, default=0)
|
|
failed: Mapped[int] = mapped_column(Integer, default=0)
|
|
results: Mapped[list] = mapped_column(JSON, default=list)
|
|
warnings: Mapped[list] = mapped_column(JSON, default=list)
|
|
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)
|
|
|
|
|
|
class EvalTask(Base):
|
|
"""提交里的一个逻辑站点,独立取工参、算周边站、取指标。"""
|
|
|
|
__tablename__ = "eval_task"
|
|
__table_args__ = (Index("ix_eval_task_job_seq", "job_id", "seq"),)
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
job_id: Mapped[int] = mapped_column(ForeignKey("eval_job.id", ondelete="CASCADE"))
|
|
seq: Mapped[int] = mapped_column(Integer, default=0)
|
|
site_key: Mapped[str] = mapped_column(String(255), default="")
|
|
kind: Mapped[str] = mapped_column(String(16), default="pinduan")
|
|
order_type: Mapped[str] = mapped_column(String(64), default="")
|
|
removal_date: Mapped[date | None] = mapped_column(Date, nullable=True)
|
|
target: Mapped[dict] = mapped_column(JSON, default=dict)
|
|
rows: Mapped[list] = mapped_column(JSON, default=list)
|
|
status: Mapped[str] = mapped_column(String(16), default="queued", index=True)
|
|
stage: Mapped[str] = mapped_column(String(64), default="")
|
|
before_date: Mapped[date | None] = mapped_column(Date, nullable=True)
|
|
after_date: Mapped[date | None] = mapped_column(Date, nullable=True)
|
|
after_present: Mapped[bool | None] = mapped_column(Boolean, nullable=True)
|
|
payload: Mapped[dict] = mapped_column(JSON, default=dict)
|
|
error: Mapped[str] = mapped_column(Text, default="")
|
|
started_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
|
|
finished_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
|
|
|
|
|
|
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)
|