fix: 拆除后工参改用拆除日下一周的周一

停闭后一周的指标周三就有、下一周周一的工参周四才取,中间这一天周边站先按拆除前工参算,并在结果说明里写明。
This commit is contained in:
2026-11-12 14:57:19 +08:00
parent 62b72bb130
commit 9225d7e45b
7 changed files with 32 additions and 23 deletions
+4 -4
View File
@@ -411,8 +411,8 @@ def before_monday(removal: date, today: date) -> date:
def after_monday(removal: date, today: date) -> date | None:
"""拆除后工参:拆除日当周的周一。那一天还取不到时没有拆除后工参。"""
day = monday_of(removal)
"""拆除后工参:拆除日下一周的周一。那一天还取不到时没有拆除后工参。"""
day = monday_of(removal) + timedelta(days=7)
return day if day <= latest_monday(today) else None
@@ -435,9 +435,9 @@ async def pick_before(store: GongcanStore, city: str, target: Target, removal: d
async def pick_after(store: GongcanStore, city: str, target: Target, removal: date, today: date) -> AfterPick | None:
"""拆除后用的工参日期:拆除日当周的周一。
"""拆除后用的工参日期:拆除日下一周的周一。
这一天通常还在拆除日之前,目标仍在工参里是正常的,只做标记。还取不到这一天时返回 None。
拆掉的小区有时还留在工参里,这是正常的,只做标记。还取不到这一天时返回 None。
"""
day = after_monday(removal, today)
if day is None:
+5 -1
View File
@@ -131,7 +131,7 @@ def evaluate_site(
wanted_after = after_monday(group.removal, today)
if after is None and wanted_after is not None:
notes.append(f"{wanted_after} 的工参没取到,周边站按拆除前工参算")
# 拆除后工参是拆除当周周一的,待拆小区通常还在里面;算周边站和取指标时去掉它们。
# 拆掉的小区有时还留在拆除后工参里;算周边站和取指标时去掉它们。
own = {cell["cgi"] for cell in targets} | set(group.cgis)
pool = [cell for cell in (gongcan.cells(city, after.day) if after is not None and after.day != before_day else before_cells) if cell["cgi"] not in own]
center = target_center(targets)
@@ -158,6 +158,10 @@ def evaluate_site(
for label, period, month in (("停闭前", before_period, before_month), ("停闭后", after_period, after_month)):
if period is not None and period.month is None:
notes.append(f"{label}的 4G MR 用 {month:%Y-%m} 的月数据,平台要到 {ready_day(month_span(month)[1])} 才有,4G 小区的 MR 暂时空着")
if after is None and wanted_after is None and after_window is not None:
# 停闭后一周的指标周三就有,下一周周一的工参要到周四才取,中间差一天。
later = monday_of(group.removal) + timedelta(days=7)
notes.append(f"拆除后工参用 {later} 的,要到 {ready_day(later)} 才取,周边站先按拆除前工参算")
by_site: dict[str, list[dict]] = {}
for cell in pool:
name = cell.get("cell_name") or ""
+1 -1
View File
@@ -1,6 +1,6 @@
"""评估取数。
工参:本系统的工参快照(CellData_4G/5G),每周一一份。拆除前用拆除日上一周的周一,拆除后用拆除日当周的周一;
工参:本系统的工参快照(CellData_4G/5G),每周一一份。拆除前用拆除日上一周的周一,拆除后用拆除日下一周的周一;
库里还没有的周一用提交人的大数据平台凭证经 OpenCode 补取,本系统账号没有凭证时借号池里的账号。
指标从即席查询按小区清单取,一次取一周(周一到周日):
4G 流量、质量、扇区、频段取「[管理视图]重要场景-小区周粒度」,4G 的 MR 取「MR报表_小区粒度_月」(只有月数据);
+5 -2
View File
@@ -198,8 +198,8 @@ def test_evaluate_site_finds_neighbors_and_sectors_with_mock_sources():
group = groups[0]
stages: list[str] = []
payload = evaluate_site(group, "江门", TODAY, MockGongcan(), MockMetrics(), stage=stages.append)
# 拆除前工参是拆除日上一周的周一,拆除后工参是拆除日当周的周一。
assert payload["beforeDay"] == "2026-10-05" and payload["afterDay"] == "2026-10-12" and payload["afterPresent"] is True
# 拆除前工参是拆除日上一周的周一,拆除后工参是拆除日下一周的周一。
assert payload["beforeDay"] == "2026-10-05" and payload["afterDay"] == "2026-10-19" and payload["afterPresent"] is True
assert len(payload["neighbors"]) == 3 and payload["locatable"]
assert all(item["site"] != "模拟待拆站点" for item in payload["item2"])
assert not {"460-00-5001-1", "460-00-5001-2"} & {item["cgi"] for item in payload["item2"]}
@@ -231,6 +231,9 @@ def test_evaluate_site_waits_for_weeks_the_platform_has_not_synced():
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"])
# 停闭后一周的指标今天(周三)有了,下一周周一 11-09 的工参明天才取。
assert last_week["afterDay"] is None and "拆除后工参用 2026-11-09 的,要到 2026-11-12 才取,周边站先按拆除前工参算" in last_week["notes"]
assert not any("拆除后工参用" in note for note in done["notes"] + this_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)
+12 -11
View File
@@ -259,7 +259,7 @@ def test_next_to_fill_takes_one_at_a_time_and_backs_off_after_a_failure():
assert platform.fetched == [date(2026, 11, 2), date(2026, 10, 26)]
# 拆除日 2026-10-15 是周四:上一周的周一是 10-05,当周的周一是 10-12。
# 拆除日 2026-10-15 是周四:上一周的周一是 10-05,下一周的周一是 10-19。
REMOVAL = date(2026, 10, 15)
TODAY = date(2026, 11, 12)
@@ -303,21 +303,22 @@ def test_before_uses_latest_available_monday_for_a_future_removal():
assert platform.fetched == []
def test_after_is_the_monday_of_the_removal_week_and_target_may_still_be_there():
platform = Platform({date(2026, 10, 12): with_target()})
store = make_store(platform, {date(2026, 10, 19): without_target()})
assert asyncio.run(pick_after(store, CITY, SITE, REMOVAL, TODAY)) == AfterPick(date(2026, 10, 12), True)
assert asyncio.run(pick_after(store, CITY, SITE, date(2026, 10, 19), TODAY)) == AfterPick(date(2026, 10, 19), False)
assert platform.fetched == [date(2026, 10, 12)]
def test_after_is_the_monday_after_the_removal_week_and_target_may_still_be_there():
platform = Platform({date(2026, 10, 19): with_target()})
store = make_store(platform, {date(2026, 10, 12): with_target(), date(2026, 10, 26): without_target()})
assert asyncio.run(pick_after(store, CITY, SITE, REMOVAL, TODAY)) == AfterPick(date(2026, 10, 19), True)
# 拆除日正好是周一,也用下一周的周一。
assert asyncio.run(pick_after(store, CITY, SITE, date(2026, 10, 19), TODAY)) == AfterPick(date(2026, 10, 26), False)
assert platform.fetched == [date(2026, 10, 19)]
def test_after_is_empty_until_that_monday_can_be_fetched():
store = make_store(Platform({}))
# 11-09 这个周一 11-12 起可取;11-16 的还不行。
assert asyncio.run(pick_after(store, CITY, SITE, date(2026, 11, 10), date(2026, 11, 11))) is None
assert asyncio.run(pick_after(store, CITY, SITE, date(2026, 11, 17), TODAY)) is None
# 拆除日 11-03 的下一周周一是 11-09,11-12 起可取;拆除日 11-10 的是 11-16,还不行。
assert asyncio.run(pick_after(store, CITY, SITE, date(2026, 11, 3), date(2026, 11, 11))) is None
assert asyncio.run(pick_after(store, CITY, SITE, date(2026, 11, 10), TODAY)) is None
with pytest.raises(GongcanError, match="平台没有这一天"):
asyncio.run(pick_after(store, CITY, SITE, date(2026, 11, 10), TODAY))
asyncio.run(pick_after(store, CITY, SITE, date(2026, 11, 3), TODAY))
def test_target_needs_cgis_or_site():
+1 -1
View File
@@ -43,7 +43,7 @@
页面显示的阶段:确定拆除前工参 → 确定拆除后工参 → 定位待拆站点 → 查询停闭前后指标 →(低效拆除)查询扇区指标 → 完成。
1. **工参日期**:每周一一份。拆除前用拆除日上一周的周一,拆除后用拆除日当周的周一,细则见 [评估工参的数据来源](gongcan-source.md)。
1. **工参日期**:每周一一份。拆除前用拆除日上一周的周一,拆除后用拆除日下一周的周一,细则见 [评估工参的数据来源](gongcan-source.md)。
拆除前取不到时这个站点失败;拆除后那一份还取不到时没有拆除后工参。
2. **定位**:在拆除前工参里找目标小区(按小区)或站点名(按站点)。清单没写小区名的从工参补上;部分 CGI 不在工参里只记说明。
3. **周边站**:离待拆小区中心最近的 3 个物理站,用拆除后工参(没有就用拆除前的)。排除待拆小区和待拆站本身、室分(小区名含 `W-`)、NB-IoT、
+4 -3
View File
@@ -100,14 +100,15 @@
**拆除后**(取不到不算失败):
1. 拆除日当周的周一。这一天现在还取不到时没有拆除后工参。
2. 这一天通常还在拆除日之前,待拆小区仍在工参里是正常的,只记 `target_present`,页面不提示。
1. 拆除日下一周的周一(拆除日正好是周一也一样)。这一天现在还取不到时没有拆除后工参,周边站先按拆除前工参算。
停闭后一周的指标周三就有,下一周周一的工参周四才取,中间这一天结果说明里会写明。
2. 拆掉的小区有时还留在工参里,这是正常的,只记 `target_present`,页面不提示。
算周边站和取指标时会把待拆小区去掉。
3. 平台取不到这一份时,周边站改用拆除前工参,结果说明里写明。
用到的周一库里没有时,评估任务自己去平台取这一份并入库。
例:拆除日 2026-10-15(周四),拆除前用 10-05,拆除后用 10-12。
例:拆除日 2026-10-15(周四),拆除前用 10-05,拆除后用 10-19。
## OpenCode 接口