feat: 5G 指标和 4G、5G 的 MR 改从即席查询取实际数据,评估不再用模拟指标
- 5G 流量、RRC、利用率、扇区取 5G 小区容量周表,接通率和掉线率取 5GSA_CU 的周粒度,MR 取 5GMRO 的周粒度 - 4G 的 MR 采样、覆盖率、竞对和三个是否取 MR 月表:停闭前用拆除日上一个月,停闭后用当月 - 周边站的 MR 弱覆盖填弱于 -110dBm 的比例(100 减平台的占比),和模板阈值一致 - 多粒度的表在请求里带上选中的时间粒度和地理维度 - 判断公式逐项检查停闭后有没有数值,缺了显示「/」;4G 的 MR 月数据没出时汇总行的 MR 一项不判断 - 扇区成员把 5G 小区也算进来
This commit is contained in:
@@ -75,8 +75,8 @@ def test_select_rows_inserts_the_list_before_city_and_batches(monkeypatch):
|
||||
async def session(client):
|
||||
return None
|
||||
|
||||
async def fetch(client, head, chosen, where):
|
||||
seen.append(([column["columnname"] for column in chosen], where))
|
||||
async def fetch(client, head, chosen, where, **dimensions):
|
||||
seen.append(([column["columnname"] for column in chosen], where, dimensions))
|
||||
return [{"cgi": "ok"}]
|
||||
|
||||
monkeypatch.setattr(adhoc, "_columns", fake_columns)
|
||||
@@ -93,5 +93,42 @@ def test_select_rows_inserts_the_list_before_city_and_batches(monkeypatch):
|
||||
("city", "in", "江门"),
|
||||
]
|
||||
assert seen[1][1][-2]["val"] == "460-00-1-3"
|
||||
assert seen[0][2] == {"time_dimension": None, "geo_dimension": None}
|
||||
assert asyncio.run(adhoc.select_rows(None, table, start, end, "江门", "cgi", [])) == []
|
||||
assert len(seen) == 2
|
||||
|
||||
|
||||
def test_tables_with_several_granularities_send_the_selected_one(monkeypatch):
|
||||
# 5GSA_CU 性能报表一张表有小时、天、周、月四种粒度,同一个字段登记了不止一次。
|
||||
table = "appdbv3.a_common_pm_sacu"
|
||||
config = {**HEAD, "tablename": table, "supporteddimension": "0,2,1,3", "supportedtimedimension": "0,1,2,3,4", "time_field": "starttime"}
|
||||
table_columns = [
|
||||
{**config, "columnname": "starttime"},
|
||||
{**config, "columnname": "ncgi"},
|
||||
{**config, "columnname": "kpi_rate", "fieldtype": "天粒度"},
|
||||
{**config, "columnname": "kpi_rate", "fieldtype": "周、月粒度"},
|
||||
]
|
||||
assert [column["fieldtype"] for column in adhoc._pick(table_columns, ("kpi_rate", "ncgi"))] == [HEAD["fieldtype"], "天粒度"]
|
||||
picked = json.loads(adhoc._result_json(config, table_columns[:2], time_dimension="2", geo_dimension="0"))
|
||||
assert picked["tableParams"] == {"supporteddimension": "0", "supportedtimedimension": "2"}
|
||||
assert json.loads(adhoc._result_json(config, table_columns[:2]))["tableParams"] == {"supporteddimension": "0,2,1,3", "supportedtimedimension": "0,1,2,3,4"}
|
||||
sent = []
|
||||
|
||||
async def fake_columns(client, name):
|
||||
return table_columns
|
||||
|
||||
async def session(client):
|
||||
return None
|
||||
|
||||
async def fake_post(client, url, form):
|
||||
sent.append((url.rsplit("/", 1)[-1], form))
|
||||
return {"count": 0, "indexcount": "0"}
|
||||
|
||||
monkeypatch.setattr(adhoc, "_columns", fake_columns)
|
||||
monkeypatch.setattr(adhoc, "ensure_session", session)
|
||||
monkeypatch.setattr(adhoc, "_post_json", fake_post)
|
||||
week = (datetime(2026, 11, 2), datetime(2026, 11, 8, 23, 59, 59))
|
||||
assert asyncio.run(adhoc.select_rows(None, table, *week, "江门", "ncgi", ["460-00-1-1"], ("starttime", "ncgi", "kpi_rate"), time_dimension="2", geo_dimension="0")) == []
|
||||
result = json.loads(sent[0][1]["result"])
|
||||
assert sent[0][0] == "getTableCount" and result["tableParams"] == {"supporteddimension": "0", "supportedtimedimension": "2"}
|
||||
assert [item["feild"] for item in result["result"]] == ["starttime", "ncgi", "kpi_rate"]
|
||||
|
||||
+109
-47
@@ -11,7 +11,8 @@ 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, PlatformMetrics
|
||||
from app.evaluate.compute import month_ready, mr_months
|
||||
from app.evaluate.sources import LTE_MR, LTE_WEEK, NR_KPI, NR_MR, NR_WEEK, MockGongcan, MockMetrics, Period, PlatformMetrics, PlatformTables, weak_share
|
||||
|
||||
TODAY = date(2026, 11, 11)
|
||||
|
||||
@@ -94,55 +95,97 @@ def test_frequency_rules_and_windows():
|
||||
# 平台数据约三天同步好:11-02 这一周周日是 11-08,到 11-11 才能查。
|
||||
assert windows(date(2026, 11, 4), TODAY)[1] == (date(2026, 11, 2), date(2026, 11, 8))
|
||||
assert windows(date(2026, 11, 4), date(2026, 11, 10))[1] is None
|
||||
# 4G 的 MR 只有月数据:停闭前用上一个月,停闭后用当月;月底过后第 3 天才有。
|
||||
assert mr_months(date(2026, 10, 15)) == (date(2026, 9, 1), date(2026, 10, 1))
|
||||
assert mr_months(date(2026, 1, 10)) == (date(2025, 12, 1), date(2026, 1, 1))
|
||||
assert not month_ready(date(2026, 10, 1), date(2026, 11, 2)) and month_ready(date(2026, 10, 1), date(2026, 11, 3))
|
||||
|
||||
|
||||
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"}]}
|
||||
LTE_ROW = {
|
||||
"starttime": "2026-10-05 00:00:00", "cgi": "460-00-1-1", "cell_name": "礼睦F-ZLH-1", "station_name": "礼睦",
|
||||
"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,
|
||||
}
|
||||
PLATFORM_ROWS = {
|
||||
# 周表里同一小区偶尔有完全相同的两行;别的周的行不该被用上。
|
||||
LTE_WEEK.name: [LTE_ROW, dict(LTE_ROW), {**LTE_ROW, "starttime": "2026-09-28 00:00:00", "upoctudl_avg": 1.0}],
|
||||
LTE_MR.name: [{
|
||||
"starttime": "2026-09-01 00:00:00", "cgi": "460-00-1-1", "mro_all_rsrp_count": 9880971, "mro_yd_rsrp_gt_f110": 9605340,
|
||||
"mro_yd_rsrp_rate": 97.21049, "mro_yd_rsrp_rate_untime": 97.41865, "mro_yd_rsrp_rate_tetime": 96.71725,
|
||||
"is_lowrsrp": False, "is_lowrsrp_un": True, "is_lowrsrp_te": False,
|
||||
}],
|
||||
NR_WEEK.name: [{
|
||||
"starttime": "2026-10-05 00:00:00", "ncgi": "460-00-9-1", "nrcell_name": "礼睦D-ZRH-1", "station_name": "礼睦",
|
||||
"sectors_name": "礼睦-扇区0", "freq": "2.6GHz", "band_width": "100MHZ", "pdcp_upoctudl": 306.66953,
|
||||
"bh_rrc_connmean": 53.49278, "bh_rrc_connmax": 75, "is_highload": True, "bh_cellprbrate": 18.4876,
|
||||
}],
|
||||
NR_KPI.name: [{"starttime": "2026-10-05 00:00:00", "ncgi": "460-00-9-1", "kpi_wirelesssuccconnrate": 99.9765, "kpi_wirelessdroprate_celllevel": 0.00113}],
|
||||
NR_MR.name: [{"starttime": "2026-10-05 00:00:00", "ncgi": "460-00-9-1", "nr_rsrp_count": 2878061, "nr_rsrp_gt_f110": 2871285, "nr_rsrp_rate": 99.76456}],
|
||||
}
|
||||
|
||||
|
||||
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"
|
||||
class FakeTables(PlatformTables):
|
||||
"""不连平台,按表名回放即席查询的行,并记下发出的查询。"""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__("local", "tester", "江门")
|
||||
self.queries = []
|
||||
|
||||
def _run(self, queries):
|
||||
self.queries += [(table.title, field, tuple(values), start, end) for table, field, values, start, end in queries]
|
||||
return [[row for row in PLATFORM_ROWS[table.name] if row.get(field) in values] for table, field, values, _start, _end in queries]
|
||||
|
||||
|
||||
def test_platform_metrics_read_every_value_from_adhoc_tables():
|
||||
tables = FakeTables()
|
||||
metrics = PlatformMetrics(tables)
|
||||
cells = [{"cgi": "460-00-1-1", "tech": "4G"}, {"cgi": "460-00-9-1", "tech": "5G"}, {"cgi": "460-00-2-2", "tech": "4G"}]
|
||||
period = Period(date(2026, 10, 5), date(2026, 10, 11), date(2026, 9, 1))
|
||||
window = metrics.window(cells, period)
|
||||
assert set(window) == {"460-00-1-1", "460-00-9-1"}
|
||||
assert window["460-00-1-1"] == {
|
||||
"traffic_gb": 21.1019, "rrc_max": 25.28571, "high_load": 0, "mr_weak_pct": pytest.approx(2.78951),
|
||||
"access_rate": 99.92656, "drop_rate": 0.02945, "util_peak": 31.7206,
|
||||
}
|
||||
assert window["460-00-9-1"] == {
|
||||
"traffic_gb": 306.66953, "rrc_max": 53.49278, "high_load": 1, "mr_weak_pct": pytest.approx(0.23544),
|
||||
"access_rate": 99.9765, "drop_rate": 0.00113, "util_peak": 18.4876,
|
||||
}
|
||||
assert [(title, field, start, end) for title, field, _values, start, end in tables.queries] == [
|
||||
("4G 小区周表", "cgi", date(2026, 10, 5), date(2026, 10, 11)),
|
||||
("4G MR 月表", "cgi", date(2026, 9, 1), date(2026, 9, 30)),
|
||||
("5G 容量周表", "ncgi", date(2026, 10, 5), date(2026, 10, 11)),
|
||||
("5G MRO 表", "ncgi", date(2026, 10, 5), date(2026, 10, 11)),
|
||||
("5G SA_CU 性能表", "ncgi", date(2026, 10, 5), date(2026, 10, 11)),
|
||||
]
|
||||
assert (NR_KPI.time_dimension, NR_KPI.geo_dimension, NR_MR.time_dimension, LTE_MR.time_dimension) == ("2", "0", "2", None)
|
||||
|
||||
profile = metrics.profile(cells, period)
|
||||
assert len(tables.queries) == 5 # 同一批小区、同一段时间不再查
|
||||
lte, nr = profile["460-00-1-1"], profile["460-00-9-1"]
|
||||
assert (lte["sector_name"], lte["freq"], lte["freq_band"], lte["equiv"], lte["high_perception"]) == ("礼睦-扇区0", "F1", "F频段", 1.0, "是")
|
||||
assert (lte["mr_total"], lte["mr_good_cnt"], lte["mr_cover_pct"], lte["unicom_cov"], lte["telecom_cov"]) == (9880971, 9605340, 97.21049, 97.41865, 96.71725)
|
||||
assert (lte["weak_cell"], lte["worse_unicom"], lte["worse_telecom"]) == ("否", "是", "否")
|
||||
assert (nr["sector_name"], nr["freq"], nr["freq_band"], nr["bandwidth"], nr["equiv"]) == ("礼睦-扇区0", "", "2.6GHz", 100.0, None)
|
||||
assert (nr["traffic_gb"], nr["rrc_max"], nr["rrc_max_abs"], nr["util_peak"], nr["high_load_expand"]) == (306.66953, 53.49278, 75, 18.4876, "是")
|
||||
assert (nr["mr_total"], nr["mr_cover_pct"], nr["unicom_cov"], nr["weak_cell"], nr["high_traffic_warn"]) == (2878061, 99.76456, None, None, None)
|
||||
assert profile["460-00-2-2"]["sector_name"] == "" and profile["460-00-2-2"]["mr_total"] is None and profile["460-00-2-2"]["weak_cell"] is None
|
||||
|
||||
members = metrics.sector_members({"礼睦-扇区0"}, period, [])["礼睦-扇区0"]
|
||||
assert [(item["tech"], item["cgi"], item["cell_name"], item["site_name"]) for item in members] == [
|
||||
("4G", "460-00-1-1", "礼睦F-ZLH-1", "礼睦"),
|
||||
("5G", "460-00-9-1", "礼睦D-ZRH-1", "礼睦"),
|
||||
]
|
||||
assert [query[1] for query in tables.queries[5:]] == ["sectors_name", "sectors_name"]
|
||||
|
||||
# 4G 的 MR 月数据还没出:不查月表,MR 留空,别的照常。
|
||||
early = PlatformMetrics(FakeTables())
|
||||
no_month = early.window(cells[:1], Period(date(2026, 10, 5), date(2026, 10, 11)))
|
||||
assert no_month["460-00-1-1"]["mr_weak_pct"] is None and no_month["460-00-1-1"]["traffic_gb"] == 21.1019
|
||||
assert [query[0] for query in early.tables.queries] == ["4G 小区周表"]
|
||||
assert weak_share(None) is None and weak_share("83.9838") == pytest.approx(16.0162)
|
||||
|
||||
|
||||
def demand(cgi: str, name: str, order: str = "频段清退", when: date = date(2026, 10, 15)) -> DemandRow:
|
||||
@@ -174,6 +217,7 @@ def low_site(when: date) -> SiteGroup:
|
||||
def test_evaluate_site_waits_for_weeks_the_platform_has_not_synced():
|
||||
done = evaluate_site(low_site(date(2026, 10, 15)), "江门", TODAY, MockGongcan(), MockMetrics())
|
||||
assert done["windows"]["after"] == ["2026-10-12", "2026-10-18"] and not any("同步好" in note for note in done["notes"])
|
||||
assert done["mrMonths"] == {"before": "2026-09", "after": "2026-10"} and not any("月数据" in note for note in done["notes"])
|
||||
assert len(done["section1"]) == 1 and done["section1"][0]["站点类型"] == "室分" and done["section1"][0]["扇区名称"]
|
||||
assert done["sectors"] and done["sectors"][0]["base"] >= 1
|
||||
|
||||
@@ -183,6 +227,16 @@ def test_evaluate_site_waits_for_weeks_the_platform_has_not_synced():
|
||||
assert any("2026-11-09 至 2026-11-15" in note and "2026-11-18" in note for note in this_week["notes"])
|
||||
assert this_week["sectors"] and all(item["before"] and item["after"] == {} for item in this_week["item2"])
|
||||
|
||||
# 拆除日在上周:前后两周的周数据都有了,但 4G 的 MR 要用 11 月的月数据,12-03 才有。
|
||||
last_week = evaluate_site(low_site(date(2026, 11, 4)), "江门", TODAY, MockGongcan(), MockMetrics())
|
||||
assert last_week["windows"]["after"] == ["2026-11-02", "2026-11-08"] and last_week["mrMonths"] == {"before": "2026-10", "after": None}
|
||||
assert any("停闭后的 4G MR 用 2026-11 的月数据" in note and "2026-12-03" in note for note in last_week["notes"])
|
||||
lte_rows = [item for item in last_week["item2"] if item["tech"] == "4G"]
|
||||
assert last_week["mrPending"] is True and not done["mrPending"]
|
||||
assert all(item["before"]["mr_weak_pct"] is not None and item["after"]["mr_weak_pct"] is None and item["after"]["traffic_gb"] is not None for item in lte_rows)
|
||||
assert all(item["after"]["mr_weak_pct"] is not None for item in last_week["item2"] if item["tech"] == "5G")
|
||||
assert all(sector["cover_b"] is not None and sector["cover_a"] is None for sector in last_week["sectors"])
|
||||
|
||||
# 拆除日还远:上一周的数据也没有,不去查,结果里说明哪天之后再评估。
|
||||
later = evaluate_site(low_site(date(2026, 12, 20)), "江门", TODAY, MockGongcan(), MockMetrics())
|
||||
assert later["beforeDay"] == "2026-11-02" and later["afterDay"] is None
|
||||
@@ -218,7 +272,7 @@ def item(cgi: str, site: str, locatable: bool = True) -> Item1:
|
||||
def test_write_pinduan_groups_neighbors_per_site():
|
||||
content = write_pinduan(
|
||||
[item("460-00-1-1", "站A"), item("460-00-2-1", "站B", locatable=False)],
|
||||
[NeighborGroup("站A", neighbor_cells("周边一", 3)), NeighborGroup("站B", neighbor_cells("周边二", 2, with_after=False))],
|
||||
[NeighborGroup("站A", neighbor_cells("周边一", 3)), NeighborGroup("站B", neighbor_cells("周边二", 2, with_after=False), mr_pending=True)],
|
||||
)
|
||||
sheet = load_workbook(io.BytesIO(content)).worksheets[0]
|
||||
assert sheet["E3"].value == "460-00-1-1" and sheet["D3"].value == "460-00-1" and sheet["J3"].number_format == "yyyy-mm-dd"
|
||||
@@ -235,10 +289,18 @@ def test_write_pinduan_groups_neighbors_per_site():
|
||||
assert f"W{first}:W{summary_a}" in merges and f"X{first}:X{summary_a}" in merges
|
||||
assert sheet.cell(first, 24).value == "站A"
|
||||
assert "不通过" in sheet.cell(first, 23).value and "拆除后再评估" in sheet.cell(first, 23).value
|
||||
# 每一项只在自己的停闭后数值存在时才比阈值,缺了显示「/」。
|
||||
assert sheet.cell(first, 19).value == f'=IF(ISNUMBER(L{first}),IF(L{first}>10,"N",IF(AND(ISNUMBER(E{first}),(L{first}-E{first})>5),"N","Y")),"/")'
|
||||
assert sheet.cell(first, 20).value == f'=IF(ISNUMBER(M{first}),IF(M{first}<97,"N",IF(AND(ISNUMBER(F{first}),(F{first}-M{first})>1),"N","Y")),"/")'
|
||||
assert sheet.cell(first, 21).value == f'=IF(ISNUMBER(N{first}),IF(N{first}<0.3,"Y","N"),"/")'
|
||||
assert sheet.cell(summary_a, 22).value == f'=IF(ISNUMBER(O{summary_a}),IF(O{summary_a}<0.3,"Y","N"),"/")'
|
||||
second = summary_a + 1
|
||||
assert sheet.cell(second, 1).value == "周边二-1" and sheet.cell(second, 9).value is None
|
||||
assert sheet.cell(second, 2).fill.start_color.rgb.endswith("F2F6FC")
|
||||
assert sheet.cell(second + 2, 1).value == "汇总"
|
||||
# 4G 停闭后的 MR 月数据没出时,汇总行的 MR 弱覆盖直接写「/」,别的项照常用公式。
|
||||
assert sheet.cell(second + 2, 19).value == "/" and sheet.cell(summary_a, 19).value.startswith("=IF(ISNUMBER(L")
|
||||
assert sheet.cell(second + 2, 20).value.startswith("=IF(ISNUMBER(M")
|
||||
assert sheet.cell(second + 3, 1).value.startswith("CGI评估对象")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user