feat: 评估按拆除日的前一周和当周取 4G 周表,MR 和 5G 仍用模拟数据

This commit is contained in:
2026-11-12 11:39:36 +08:00
parent a1f4e78b19
commit 452b01498f
12 changed files with 442 additions and 112 deletions
+40 -1
View File
@@ -1,6 +1,6 @@
import asyncio
import json
from datetime import date
from datetime import date, datetime
import pytest
@@ -56,3 +56,42 @@ def test_count_sends_indexcount_and_rejects_error_payload(monkeypatch):
for _ in range(2):
with pytest.raises(NqiError):
asyncio.run(adhoc._count(None, {"where": "[]"}))
def test_select_rows_inserts_the_list_before_city_and_batches(monkeypatch):
monkeypatch.setattr(adhoc, "IN_BATCH", 2)
table = "appdbv3.a_overview_ispm_lte_cell_w"
table_columns = [
{**HEAD, "tablename": table, "columnname": "starttime", "time_field": "starttime", "city_field": "city"},
{**HEAD, "tablename": table, "columnname": "cgi"},
{**HEAD, "tablename": table, "columnname": "upoctudl_avg"},
]
seen = []
async def fake_columns(client, name):
assert name == table
return table_columns
async def session(client):
return None
async def fetch(client, head, chosen, where):
seen.append(([column["columnname"] for column in chosen], where))
return [{"cgi": "ok"}]
monkeypatch.setattr(adhoc, "_columns", fake_columns)
monkeypatch.setattr(adhoc, "ensure_session", session)
monkeypatch.setattr(adhoc, "_fetch_all", fetch)
start, end = datetime(2026, 10, 5), datetime(2026, 10, 11, 23, 59, 59)
rows = asyncio.run(adhoc.select_rows(None, table, start, end, "江门", "cgi", ["460-00-1-1", "460-00-1-1", "bad,cgi", "460-00-1-2", "460-00-1-3"], ("cgi", "upoctudl_avg")))
assert rows == [{"cgi": "ok"}, {"cgi": "ok"}]
assert [item[0] for item in seen] == [["cgi", "upoctudl_avg"], ["cgi", "upoctudl_avg"]]
assert [(item["feild"], item["symbol"], item["val"]) for item in seen[0][1]] == [
("starttime", ">=", "2026-10-05 00:00:00"),
("starttime", "<", "2026-10-11 23:59:59"),
("cgi", "in", "460-00-1-1,460-00-1-2"),
("city", "in", "江门"),
]
assert seen[1][1][-2]["val"] == "460-00-1-3"
assert asyncio.run(adhoc.select_rows(None, table, start, end, "江门", "cgi", [])) == []
assert len(seen) == 2
+54 -5
View File
@@ -11,7 +11,7 @@ from app.collect.gongcan import GongcanMissing
from app.evaluate.compute import EvalFailure, equiv_carriers, evaluate_site, norm_freq, windows
from app.evaluate.demand import DemandError, DemandRow, SiteGroup, group_rows, parse_demand, template_workbook
from app.evaluate.report import Item1, NeighborGroup, write_dixiao, write_pinduan
from app.evaluate.sources import MockGongcan, MockMetrics
from app.evaluate.sources import MockGongcan, MockMetrics, PlatformMetrics
TODAY = date(2026, 11, 11)
@@ -88,11 +88,60 @@ def test_frequency_rules_and_windows():
assert equiv_carriers("E1", "3D-MIMO", 20) == 2.5
assert equiv_carriers("", "", 20) is None
before, after = windows(date(2026, 10, 15), TODAY)
assert before == (date(2026, 9, 15), date(2026, 10, 14))
assert after == (date(2026, 10, 16), date(2026, 11, 10))
assert before == (date(2026, 10, 5), date(2026, 10, 11))
assert after == (date(2026, 10, 12), date(2026, 10, 18))
assert windows(date(2026, 11, 10), TODAY)[1] is None
class _WeekStub:
def __init__(self, row: dict):
self.row = row
def by_cgi(self, cgis, start, end):
return {cgi: self.row for cgi in cgis if cgi == self.row["cgi"]}
def by_sector(self, sectors, start, end):
return {"礼睦-扇区0": [{"cgi": "460-00-1-9", "cell_name": "礼睦-9", "site_name": "礼睦", "tech": "4G"}]}
def test_platform_metrics_keeps_weekly_lte_and_mocks_mr_and_nr():
metrics = PlatformMetrics(
_WeekStub(
{
"cgi": "460-00-1-1",
"upoctudl_avg": "21.1019",
"bh_effectiveconnmax": "25.28571",
"bh_connmax": "49.71429",
"bh_peak_use_rate": "31.7206",
"radio_succ_rate": "99.92656",
"radio_drop_rate_cell": "0.02945",
"is_highflow": False,
"is_highload": "false",
"is_highflow_perceive": True,
"sectors_name": "礼睦-扇区0",
"freq_name": "F1",
"freq": "F频段",
"bandwidth": "20",
"equivalent_20m_carrier": "1.0",
}
),
MockMetrics(),
)
cells = [{"cgi": "460-00-1-1", "tech": "4G", "site_name": "礼睦"}, {"cgi": "460-00-9-1", "tech": "5G", "site_name": "礼睦"}]
week = (date(2026, 10, 5), date(2026, 10, 11))
window = metrics.window(cells, *week)
assert window["460-00-1-1"]["traffic_gb"] == pytest.approx(21.1019)
assert window["460-00-1-1"]["high_load"] == 0 and window["460-00-1-1"]["mr_weak_pct"] is not None
assert "460-00-2-2" not in metrics.window([{"cgi": "460-00-2-2", "tech": "4G"}], *week)
assert window["460-00-9-1"]["traffic_gb"] is not None
profile = metrics.profile(cells, *week)
assert profile["460-00-1-1"]["sector_name"] == "礼睦-扇区0"
assert profile["460-00-1-1"]["high_perception"] == "是" and profile["460-00-1-1"]["equiv"] == 1.0
assert profile["460-00-1-1"]["mr_cover_pct"] is not None
assert profile["460-00-9-1"]["freq"] == "N41"
assert metrics.sector_members({"礼睦-扇区0"}, *week, [])["礼睦-扇区0"][0]["cgi"] == "460-00-1-9"
def demand(cgi: str, name: str, order: str = "频段清退", when: date = date(2026, 10, 15)) -> DemandRow:
return DemandRow(line=2, cgi=cgi, order_type=order, need_date=when, cell_name=name, county="台山市", applicant="张三", retire_reason="搬迁")
@@ -113,7 +162,7 @@ def test_evaluate_site_finds_neighbors_and_sectors_with_mock_sources():
low = SiteGroup(key="低效站", kind="dixiao", order_type="低效拆除", removal=date(2026, 12, 20), rows=[demand("460-00-6001-1", "低效站E-ZLW-1", "低效拆除", date(2026, 12, 20))])
result = evaluate_site(low, "江门", TODAY, MockGongcan(), MockMetrics())
assert result["afterDay"] is None and "拆除日期还没过,没有停闭后的指标" in result["notes"]
assert result["afterDay"] is None and "拆除当周还没结束,没有停闭后的指标" in result["notes"]
assert len(result["section1"]) == 1 and result["section1"][0]["站点类型"] == "室分"
assert result["sectors"] and result["sectors"][0]["base"] >= 1
assert all(item["after"] == {} for item in result["item2"])
@@ -255,7 +304,7 @@ def test_eval_api_end_to_end(client: TestClient):
detail = wait_job(client, user, created["id"])
assert detail["job"]["status"] == "done", detail
assert [result["kind"] for result in detail["job"]["results"]] == ["pinduan", "dixiao"]
assert detail["job"]["warnings"][0].startswith("流量和质量指标暂为模拟数据")
assert detail["job"]["warnings"][0].startswith("模拟数据:")
assert [task["status"] for task in detail["tasks"]] == ["done", "done"]
assert detail["tasks"][0]["beforeDate"] == "2026-09-01" and len(detail["tasks"][0]["neighbors"]) == 3
for result in detail["job"]["results"]: