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
+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"]: