feat: 工参小区按制式拆成 CellData_4G、CellData_5G;即席查询补上页面必带参数

两张表列名沿用平台工参表,已有快照由迁移 0008 原样搬过去。即席查询的 result 补 tableParams、columnname,计数补 indexcount=0,缺这些服务端会返回 stat 0。
This commit is contained in:
2026-11-11 02:30:21 +08:00
parent dcd0a87cc3
commit 33d132d7b6
8 changed files with 304 additions and 76 deletions
+28 -13
View File
@@ -25,7 +25,7 @@ from app.collect.gongcan import (
snapshot_task_name,
target_center,
)
from app.models import Base, GongcanCell, GongcanSnapshot
from app.models import Base, CellData4G, CellData5G, GongcanSnapshot
from app.nqi.client import NqiError
from app.nqi.opencode import CsvTable, OpenCode
@@ -37,12 +37,20 @@ def cell(cgi, site, tech="4G", lat=22.0, lon=113.0, name="A", network_type="LTE"
return {"tech": tech, "cgi": cgi, "cell_name": name, "site_name": site, "latitude": lat, "longitude": lon, "network_type": network_type}
def with_target(*others):
return [cell("t1", "T"), cell("n1", "N", tech="5G")] + [cell(f"x{i}", name) for i, name in enumerate(others)]
def lte(cgi, site, lat=22.0):
return {"cgi": cgi, "cell_name": f"{site}-A", "station_name": site, "latitude": lat, "longitude": 113.0, "network_type": "LTE"}
def nr(ncgi, site, lat=22.0):
return {"ncgi": ncgi, "nrcell_name": f"{site}-N", "station_name": site, "latitude": lat, "longitude": 113.0, "network_type": "NR"}
def with_target():
return {"4G": [lte("t1", "T")], "5G": [nr("n1", "N")]}
def without_target():
return [cell("n1", "N", tech="5G"), cell("o1", "O")]
return {"4G": [lte("o1", "O")], "5G": [nr("n1", "N")]}
class Clock:
@@ -70,7 +78,7 @@ class Platform:
def make_store(platform, stored=None, clock=None):
db = create_engine("sqlite://")
Base.metadata.create_all(db, tables=[GongcanSnapshot.__table__, GongcanCell.__table__])
Base.metadata.create_all(db, tables=[GongcanSnapshot.__table__, CellData4G.__table__, CellData5G.__table__])
clock = clock or Clock()
for day, cells in (stored or {}).items():
snapshot_id = claim_snapshot(db, CITY, day, clock())
@@ -111,13 +119,15 @@ def test_build_cells_merges_coordinates_by_cgi():
{"cgi": "c2", "longitude": "0", "latitude": "0"},
]
cells = build_cells(attrs, coords, "4G")
assert [(item["cgi"], item["cell_name"], item["site_name"], item["latitude"], item["longitude"]) for item in cells] == [
assert [(item["cgi"], item["cell_name"], item["station_name"], item["latitude"], item["longitude"]) for item in cells] == [
("c1", "A", "S1", 22.5, 113.1),
("c2", "B", "S2", None, None),
]
assert cells[0]["node_id"] == "1" and cells[0]["tech"] == "4G" and cells[1]["network_type"] == ""
nr = build_cells([{"ncgi": "", "cgi": "n1", "nrcell_name": "N", "gnodeb_id": "9"}], [{"ncgi": "n1", "longitude": "113", "latitude": "22"}], "5G")
assert nr == [{**nr[0], "cgi": "n1", "cell_name": "N", "node_id": "9", "latitude": 22.0, "longitude": 113.0}]
assert cells[0]["enodeb_id"] == "1" and cells[1]["network_type"] == ""
assert set(cells[0]) == {"cgi", "latitude", "longitude"} | set(gongcan.ATTRIBUTES["4G"])
rows = build_cells([{"ncgi": "", "cgi": "n1", "nrcell_name": "N", "gnodeb_id": "9"}], [{"ncgi": "n1", "longitude": "113", "latitude": "22"}], "5G")
assert rows == [{**rows[0], "ncgi": "n1", "nrcell_name": "N", "gnodeb_id": "9", "latitude": 22.0, "longitude": 113.0}]
assert "cgi" not in rows[0] and "enodeb_id" not in rows[0]
def test_key_overlap():
@@ -167,19 +177,20 @@ def test_snapshot_takes_attributes_from_adhoc_and_coordinates_from_opencode(monk
oc = SnapshotOpenCode(PLATFORM_ROWS)
cells, source = asyncio.run(fetch_snapshot(None, oc, CITY, date(2026, 11, 1)))
assert source == "adhoc" and oc.phases == ["xy"] and oc.cleaned == [snapshot_task_name(CITY, date(2026, 11, 1))]
assert [(item["tech"], item["site_name"], item["latitude"]) for item in cells] == [("4G", "即席站", 22.0), ("5G", "即席站", 22.0)]
assert [(row["cgi"], row["station_name"], row["latitude"]) for row in cells["4G"]] == [("c1", "即席站", 22.0)]
assert [(row["ncgi"], row["station_name"], row["latitude"]) for row in cells["5G"]] == [("n1", "即席站", 22.0)]
def test_snapshot_falls_back_to_opencode_attributes(monkeypatch):
adhoc_returns(monkeypatch, NqiError("即席查询没有返回行数"))
oc = SnapshotOpenCode(PLATFORM_ROWS)
cells, source = asyncio.run(fetch_snapshot(None, oc, CITY, date(2026, 11, 1)))
assert source == "opencode" and oc.phases == ["attr"] and cells[0]["site_name"] == "OC站"
assert source == "opencode" and oc.phases == ["attr"] and cells["4G"][0]["station_name"] == "OC站"
adhoc_returns(monkeypatch, {"4G": [{"cgi": "other"}], "5G": [{"ncgi": "n1"}]})
mismatch = SnapshotOpenCode(PLATFORM_ROWS)
cells, source = asyncio.run(fetch_snapshot(None, mismatch, CITY, date(2026, 11, 1)))
assert source == "opencode" and mismatch.phases == ["xy", "attr"] and cells[0]["cgi"] == "c1"
assert source == "opencode" and mismatch.phases == ["xy", "attr"] and cells["4G"][0]["cgi"] == "c1"
def test_snapshot_rejects_empty_city(monkeypatch):
@@ -194,10 +205,14 @@ def test_store_answers_presence_queries():
assert store.ready_dates(CITY, date(2026, 10, 1), date(2026, 11, 1)) == [date(2026, 10, 1)]
assert store.dates_with_target(CITY, SITE, date(2026, 1, 1), date(2027, 1, 1)) == [date(2026, 10, 1)]
assert store.has_target(CITY, date(2026, 10, 1), Target(cgis=("zz", "t1")))
assert store.has_target(CITY, date(2026, 11, 1), Target(cgis=("n1",)))
assert store.has_target(CITY, date(2026, 11, 1), Target(site="N"))
assert not store.has_target(CITY, date(2026, 11, 1), Target(cgis=("t1",)))
assert not store.has_target("广州", date(2026, 10, 1), SITE)
loaded = store.cells(CITY, date(2026, 10, 1))
assert {item["cgi"] for item in loaded} == {"t1", "n1"} and loaded[0]["area"] == ""
assert sorted((item["tech"], item["cgi"], item["cell_name"], item["site_name"]) for item in loaded) == [("4G", "t1", "T-A", "T"), ("5G", "n1", "N-N", "N")]
assert loaded[0]["area"] == "" and loaded[0]["node_id"] == ""
assert store.cells(CITY, date(2026, 9, 1)) == []
def test_ensure_loads_once_even_when_tasks_race():