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
+45 -9
View File
@@ -16,6 +16,7 @@ PAGE = f"{ADHOC}/adhocquery"
ENTRY = f"{ADHOC}/index"
PAGE_SIZE = 200
MAX_PAGES = 2000
IN_BATCH = 500
TIME_MODES = {"prev_month", "prev_week", "prev_day", "prev_weeks", "prev_months", "prev_days"}
@@ -144,15 +145,50 @@ async def export_table(
raise NqiError("这张表没有可导出的字段")
title = str(columns[0].get("tablename_cn") or tablename)
where = _where(columns[0], start, end, city, timed=_has_time_column(columns))
return title, columns, await _fetch_all(client, columns[0], columns, where)
async def select_rows(
client: NqiClient,
tablename: str,
start: datetime,
end: datetime,
city: str,
field: str,
values: list[str],
wanted: tuple[str, ...] = (),
) -> list[dict]:
"""按 field 的取值清单查 [start, end] 的行,和页面一样把清单逗号拼进 in 条件,每批 IN_BATCH 个。wanted 给出时只取这些列。"""
await ensure_session(client)
columns = await _columns(client, tablename)
if not columns:
raise NqiError("这张表没有可查的字段")
head = columns[0]
chosen = [column for column in columns if column.get("columnname") in wanted] if wanted else columns
names = [value for value in dict.fromkeys(str(item).strip() for item in values) if value and "," not in value]
timed = _has_time_column(columns)
rows: list[dict] = []
for offset in range(0, len(names), IN_BATCH):
where = _where(head, start, end, city, timed=timed)
at = len(where) - (1 if city.strip() else 0)
where.insert(
at,
{"datatype": "character", "feild": field, "feildName": "", "symbol": "in", "val": ",".join(names[offset : offset + IN_BATCH]), "whereCon": "and", "query": True},
)
rows.extend(await _fetch_all(client, head, chosen, where))
return rows
async def _fetch_all(client: NqiClient, head: dict, columns: list[dict], where: list[dict]) -> list[dict]:
common = {
"geographicdimension": columns[0].get("geographicdimension") or "",
"timedimension": columns[0].get("timedimension") or "",
"enodebField": columns[0].get("enodeb_field") or "",
"cgiField": columns[0].get("cgi_field") or "",
"timeField": columns[0].get("time_field") or "starttime",
"cellField": columns[0].get("cell_field") or "",
"cityField": columns[0].get("city_field") or "city",
"result": _result_json(columns[0], columns),
"geographicdimension": head.get("geographicdimension") or "",
"timedimension": head.get("timedimension") or "",
"enodebField": head.get("enodeb_field") or "",
"cgiField": head.get("cgi_field") or "",
"timeField": head.get("time_field") or "starttime",
"cellField": head.get("cell_field") or "",
"cityField": head.get("city_field") or "city",
"result": _result_json(head, columns),
"where": json.dumps(where, ensure_ascii=False),
}
total, index_count = await _count(client, common)
@@ -186,7 +222,7 @@ async def export_table(
if len(batch) < PAGE_SIZE:
break
start_at += PAGE_SIZE
return title, columns, rows
return rows
async def _count(client: NqiClient, common: dict) -> tuple[int, str]: