diff --git a/README.md b/README.md
index d14eeb5..374555e 100644
--- a/README.md
+++ b/README.md
@@ -27,11 +27,8 @@ zip 内包含:
```text
GIS.qgz
BuildingInfo.gpkg
-信号.tif
用户量.tif
-信号差用户量.tif
-弱覆盖占比.tif
-移动优竟对弱用户分布图.tif
+目标栅格竟对RSRP.tif
楼宇指标.csv
栅格指标.csv
```
@@ -42,14 +39,11 @@ BuildingInfo.gpkg
output/所有网格汇总.zip
├── GIS.qgz
├── BuildingInfo.gpkg
-├── 信号.tif
├── 用户量.tif
-├── 信号差用户量.tif
-├── 弱覆盖占比.tif
-└── 移动优竟对弱用户分布图.tif
+└── 目标栅格竟对RSRP.tif
```
-汇总包不包含 CSV。程序会先合并本次参与处理的全部市场网格边界,再从原始 Grid 一次扫描生成五张全域 TIF;网格之间没有数据的区域保持透明。`BuildingInfo.gpkg` 为完整源文件副本,保留全部样式和支撑表;`GIS.qgz` 使用全网 BuildingInfo 范围作为初始画布。`用户量.tif`、`信号差用户量.tif` 和 `移动优竟对弱用户分布图.tif` 的动态阈值按全域有效像元重新计算,不是简单拼接各市场图片。设置 `LIMIT` 时,TIF 汇总范围与本次受限处理的市场保持一致。
+汇总包不包含 CSV。程序会先合并本次参与处理的全部市场网格边界,再从原始 Grid 一次扫描生成两张全域 TIF;网格之间没有数据的区域保持透明。`BuildingInfo.gpkg` 为完整源文件副本,保留全部样式和支撑表;`GIS.qgz` 使用全网 BuildingInfo 范围作为初始画布。`用户量.tif` 的动态四分位阈值按全域有效像元重新计算;`目标栅格竟对RSRP.tif` 使用固定八档 RSRP 图例。设置 `LIMIT` 时,TIF 汇总范围与本次受限处理的市场保持一致。
## 裁切规则
@@ -61,7 +55,7 @@ output/所有网格汇总.zip
来源:`source/MapPark/GIS.qgz`
-说明:以该文件为模板生成到每个结果包。模板已包含五张专题 TIF 图层;“移动优竟对弱用户分布图”作为当前核心目标图层默认勾选,其他专题栅格默认关闭,避免透明区域露出下层颜色而混淆目标区域。程序会读取 QGZ 内的项目 XML,把 BuildingInfo 图层范围更新为当前市场实际楼宇范围,并将 QGIS 主画布设置为该范围四周增加 5% 留白。打开项目后会直接定位到当前市场区域。
+说明:以该文件为模板生成到每个结果包。模板包含“用户量”和“目标栅格竟对RSRP”两张专题 TIF;目标 RSRP 图默认勾选,用户量图默认关闭。程序会读取 QGZ 内的项目 XML,把 BuildingInfo 图层范围更新为当前市场实际楼宇范围,并将 QGIS 主画布设置为该范围四周增加 5% 留白。打开项目后会直接定位到当前市场区域。
QGZ 内的样式数据库、其他图层配置和项目结构保持不变;如果当前市场没有 BuildingInfo 要素,画布范围会回退到市场网格范围。
@@ -79,25 +73,6 @@ QGZ 内的样式数据库、其他图层配置和项目结构保持不变;如
| `floor` | 楼层 |
| `height` | 建筑高度 |
-### 信号.tif
-
-来源字段:`grid.gpkg` 的 `ssb_rsrp_dl`
-
-说明:RSRP 连续红黄绿热力图。值越大表示信号越好,颜色越偏绿;值越小表示信号越差,颜色越偏红。程序先对 RSRP 数值做空间平滑,再按固定物理锚点连续插值,无数据区域透明。
-
-当前 RSRP 连续颜色锚点:
-
-| RSRP 范围或锚点 | 颜色 | 含义 |
-| --- | --- | --- |
-| `<= -105` | 纯红 `RGB(255, 0, 0)` | 信号较差端点 |
-| `-105 ~ -95` | 红色连续过渡到黄色 | 信号由较差逐步改善 |
-| `-95` | 黄色 `RGB(255, 255, 0)` | 中间锚点 |
-| `-95 ~ -80` | 黄色连续过渡到绿色 | 信号由一般逐步改善 |
-| `>= -80` | 纯绿 `RGB(0, 176, 80)` | 信号良好端点 |
-| 无数据 | 透明 | 不显示底色 |
-
-透明度:有效像元 alpha 为 `191`,约 75% 不透明度。
-
### 用户量.tif
来源字段:`grid.gpkg` 的 `mro_total_dl`
@@ -118,64 +93,30 @@ QGZ 内的样式数据库、其他图层配置和项目结构保持不变;如
相同数值的像元始终归入同一颜色档位,不会为了强制凑满 25% 而按空间位置拆分,因此实际各档像元占比可能因重复值而偏离严格四等分。
-### 信号差用户量.tif
+### 目标栅格竟对RSRP.tif
-来源字段:`grid.gpkg` 的 `rsrp_lt_neg105_dl`
+来源:`source/grid.gpkg`
-说明:信号差用户量连续热力图,数值越大表示弱覆盖采样点越多,颜色越偏红。程序先平滑数值,再按当前市场内有效像元的动态百分位连续映射颜色,不再使用三等分色块。
+仅同时满足以下严格条件的 Grid 参与渲染:
-连续颜色锚点:
+- `rsrp_lt_neg105_yd / mro_total_yd × 100% < 20%`
+- `mro_total_dl > 1000`
+- `rsrp_lt_neg105_dl / mro_total_dl × 100% > 20%`
-| 市场内动态锚点 | 颜色 | 含义 |
+总采样量无效、弱覆盖采样量为空或为负、竟对 RSRP 无效时保持透明;任一比例恰好等于 `20%` 时不纳入。目标图直接使用 Grid 的原始 `ssb_rsrp_dl` 分八档着色,不做空间平滑,因此有效像元只会出现以下八种颜色:
+
+| 竟对 RSRP 范围 | RGB | 颜色 |
| --- | --- | --- |
-| 最高值 | 纯红 `RGB(255, 0, 0)` | 信号差用户量最高 |
-| 第 75 百分位 | 黄色 `RGB(255, 255, 0)` | 黄色动态锚点 |
-| 最低值 | 纯绿 `RGB(0, 176, 80)` | 信号差用户量最低 |
-| 无数据 | 透明 | 不显示底色 |
+| `< -110` | `253, 0, 5` | 红 |
+| `[-110, -104)` | `255, 138, 0` | 橙 |
+| `[-104, -98)` | `254, 253, 2` | 黄 |
+| `[-98, -92)` | `214, 251, 199` | 浅绿 |
+| `[-92, -86)` | `42, 231, 41` | 亮绿 |
+| `[-86, -80)` | `34, 174, 51` | 深绿 |
+| `[-80, -74)` | `0, 149, 231` | 蓝 |
+| `[-74, 0]` | `58, 14, 247` | 紫 |
-绿色到黄色、黄色到红色之间均为连续渐变。黄色设置在第 75 百分位,使红色热点主要集中于最高值约 25% 的区域。每个市场的数据范围不同,运行后可在 `output/summary.json` 的 `weak_cover_heatmap_results.color_anchor_values` 查看实际绿、黄、红数值锚点。
-
-相同数值始终映射为相同颜色;最低值和大量 `0` 值保持绿色,不会为了凑比例而按空间位置拆色。若当前范围内所有有效值完全相同,则统一显示黄色,表示没有可用于区分内部高低的相对差异。
-
-### 弱覆盖占比.tif
-
-计算公式:`rsrp_lt_neg105_dl / mro_total_dl × 100%`
-
-说明:先计算每个 Grid 的弱覆盖采样点占总采样点比例,再进行空间平滑,并在绿、蓝、黄、红四个固定锚点之间逐像元连续插值。总采样点为空或小于等于 `0`、弱覆盖采样点为空或小于 `0` 时作为无数据处理。
-
-| 弱覆盖占比锚点或区间 | 颜色 | 含义 |
-| --- | --- | --- |
-| `<= 0%` | 绿色 `RGB(0, 176, 80)` | 绿色端点 |
-| `0% ~ 5%` | 绿色连续过渡到蓝色 | 弱覆盖占比逐渐升高 |
-| `5%` | 蓝色 `RGB(0, 112, 255)` | 蓝色锚点 |
-| `5% ~ 10%` | 蓝色连续过渡到黄色 | 弱覆盖占比继续升高 |
-| `10%` | 黄色 `RGB(255, 255, 0)` | 黄色锚点 |
-| `10% ~ 20%` | 黄色连续过渡到红色 | 弱覆盖占比进入高值区 |
-| `>= 20%` | 红色 `RGB(255, 0, 0)` | 红色端点 |
-| 无有效总采样点 | 透明 | 不显示底色 |
-
-`10% ~ 20%` 区间内占比越大越接近红色;达到 `20%` 后统一保持纯红色,不再继续加深。因此该图层表达的是“弱覆盖占比越高,颜色越偏红”,而不是弱覆盖采样点的绝对数量。
-
-### 移动优竟对弱用户分布图.tif
-
-准入字段:`grid.gpkg` 的 `ssb_rsrp_yd`
-
-机会分值公式:`mro_total_dl + max(rsrp_lt_neg105_dl, 0)`
-
-说明:用于定位移动网络可以承接的竟对潜在用户。仅当 `ssb_rsrp_yd > -95` 且 `mro_total_dl > 0` 时参与渲染;移动信号未达到门槛、移动信号无效或没有竟对总采样量的 Grid 保持透明。竟对弱覆盖采样量为 `0` 时仍按总采样量显示,因此“移动好、竟对好”的潜在用户区域不会被漏掉。
-
-机会分值中,竟对总采样量计一次,竟对弱覆盖采样量再额外加一次。也就是说,竟对覆盖正常的用户仍进入基础机会规模,竟对弱覆盖用户因转化优先级更高而获得额外权重。
-
-| 动态位置 | 颜色 | 含义 |
-| --- | --- | --- |
-| 最高值 | 纯红 `RGB(255, 0, 0)` | 综合机会分值最高 |
-| 第 75 百分位 | 黄色 `RGB(255, 255, 0)` | 黄色动态锚点 |
-| 最低正值 | 纯绿 `RGB(0, 176, 80)` | 综合机会分值最低 |
-| 移动未达标或无竟对用户 | 透明 | 不具备当前挖掘条件 |
-
-颜色在绿、黄、红三个锚点之间连续变化,默认使用独立平滑半径 `5`,在突出机会聚集趋势的同时保留较清晰的位置边界。单市场结果按当前市场内符合条件的像元建立动态色带;`所有网格汇总.zip` 按全部参与市场的符合条件像元重新建立全域色带,因此全网汇总图可用于跨市场统一比较。若当前范围内所有机会分值完全相同,则统一显示黄色,表示存在目标用户但没有内部高低差异。
-
-`mro_total_dl` 和 `rsrp_lt_neg105_dl` 都是采样量,不是去重后的真实用户数。图层的业务读法是:“有颜色表示移动信号达标且存在竟对用户;颜色越红,竟对用户规模与弱覆盖机会的综合优先级越高。”
+`ssb_rsrp_dl > 0` 或空值透明。有效像元 alpha 为 `191`,约 75% 不透明度。
## CSV 指标表
@@ -250,26 +191,17 @@ CSV 中的 `移动信号` 和 `竟对信号` 使用同一套文字等级:
| `PROJECT_EXTENT_PADDING_RATIO` | `0.05` | QGIS 初始画布在 BuildingInfo 范围四周的留白比例 |
| `SCALE` | `5.0` | 分辨率倍数,越大输出越清晰,文件也越大 |
| `CLIP_MODE` | `intersects` | Grid 热力图裁切模式 |
-| `HEATMAP_BAD_RSRP` | `-105.0` | RSRP 红色端 |
-| `HEATMAP_MID_RSRP` | `-95.0` | RSRP 黄色锚点 |
-| `HEATMAP_GOOD_RSRP` | `-80.0` | RSRP 纯绿色端点 |
-| `WEAK_COVER_YELLOW_PERCENTILE` | `0.75` | 信号差用户量黄色锚点百分位,红色主要聚焦最高值约 25% |
-| `WEAK_COVER_RATIO_GREEN_ANCHOR` | `0.0` | 弱覆盖占比绿色端点,单位 `%` |
-| `WEAK_COVER_RATIO_BLUE_ANCHOR` | `5.0` | 弱覆盖占比蓝色锚点,单位 `%` |
-| `WEAK_COVER_RATIO_YELLOW_ANCHOR` | `10.0` | 弱覆盖占比黄色锚点,单位 `%` |
-| `WEAK_COVER_RATIO_RED_ANCHOR` | `20.0` | 弱覆盖占比红色端点,单位 `%` |
-| `MOBILE_RSRP_FIELD` | `ssb_rsrp_yd` | 潜在用户图准入门槛使用的移动 RSRP 字段 |
-| `MOBILE_ADVANTAGE_GOOD_RSRP_THRESHOLD` | `-95.0` | 移动信号门槛;仅严格大于该值且竟对总采样量为正的 Grid 参与目标图 |
-| `MOBILE_ADVANTAGE_SCORE_FORMULA` | `mro_total_dl + max(rsrp_lt_neg105_dl, 0)` | 竟对总采样量加弱覆盖采样量的综合机会分值 |
-| `MOBILE_ADVANTAGE_YELLOW_PERCENTILE` | `0.75` | 目标图黄色锚点百分位 |
-| `MOBILE_ADVANTAGE_SMOOTH_RADIUS` | `5` | 目标图独立平滑半径;可改为 `10` 或其他非负整数试验效果 |
+| `TARGET_MOBILE_WEAK_RATIO_MAX` | `20.0` | 移动弱覆盖比例严格上限 |
+| `TARGET_COMPETITOR_TOTAL_MIN` | `1000.0` | 竟对采样点总数严格下限 |
+| `TARGET_COMPETITOR_WEAK_RATIO_MIN` | `20.0` | 竟对弱覆盖比例严格下限 |
+| `TARGET_RSRP_BREAKS` | `-110` 至 `-74` | 八档 RSRP 的七个分界点 |
| `HEATMAP_ALPHA` | `191` | 热力图有效像元透明度,约 75% 不透明 |
## 性能优化
当前处理流程已做以下加速:
-- 同一市场的 Grid 数据只执行一次 RTree 查询和几何相交判断,同时缓存像元窗口并写出 `栅格指标.csv`;五张 TIF 顺序复用栅格矩阵内存。
+- 同一市场的 Grid 数据只执行一次 RTree 查询和几何相交判断,同时缓存像元窗口并写出 `栅格指标.csv`;用户量和目标 RSRP 两张 TIF 复用同一批 Grid 数据。
- Grid、Building 和 BuildingInfo 使用 Shapely 批量解析 WKB、判断几何相交并提取边界,减少大量 Python 逐要素调用。
- 市场边界使用 Prepared Geometry 加速同一边界与大量 Grid 候选的重复拓扑判断;汇总任务会先修复边界副本的无效拓扑,再执行全域合并。
- 热力图平滑使用 NumPy 滑动窗口矩阵乘法,一次处理完整像元矩阵,不再逐行执行卷积。
diff --git a/aidocs/project_context.md b/aidocs/project_context.md
index 58421c1..c0fc3b0 100644
--- a/aidocs/project_context.md
+++ b/aidocs/project_context.md
@@ -127,3 +127,11 @@
- `source/MapPark/GIS.qgz` 已将原目标图原位重命名为“移动优竟对弱用户分布图”,数据源同步改为新 TIF 文件名;该目标图继续作为唯一默认勾选的专题栅格,其他四张专题栅格默认关闭。
- 标准库单元测试增至 22 项并全部通过,新增边界覆盖:移动值等于 `-95` 时排除、总采样量无效时排除、弱覆盖为空/为零/为负时仍按总采样量纳入、弱覆盖为正时正确增加机会分值。
- 单市场 `1-城区蓬江` 端到端验证通过:符合新准入条件的 Grid 为 90,171 个,其中 34,031 个弱覆盖量为零但已按总采样量显示,56,140 个获得弱覆盖加分;14,202 个因移动信号不达标被排除,4,729 个因无有效总采样量被排除。抽样核验中,“移动好、竟对好”和“移动好、竟对弱”的像元 alpha 均为 `191`,“移动差”的像元 alpha 为 `0`;QGIS 图层名称、数据源和默认可见性均正确。
+
+## 2026-07-22
+- 用户确认废弃 `信号.tif`、`信号差用户量.tif`、`弱覆盖占比.tif` 和 `移动优竟对弱用户分布图.tif`,成果包只保留原有 `用户量.tif` 和新增 `目标栅格竟对RSRP.tif`;本轮暂不生成目标 Grid GPKG。
+- 目标 Grid 必须同时满足三个严格条件:`rsrp_lt_neg105_yd / mro_total_yd < 20%`、`mro_total_dl > 1000`、`rsrp_lt_neg105_dl / mro_total_dl > 20%`。比例恰好为 `20%` 时不纳入;分母无效、空值或负采样量也不纳入。
+- 新目标 TIF 直接按原始 `ssb_rsrp_dl` 分八档,不做空间平滑:`< -110` 红、`[-110,-104)` 橙、`[-104,-98)` 黄、`[-98,-92)` 浅绿、`[-92,-86)` 亮绿、`[-86,-80)` 深绿、`[-80,-74)` 蓝、`[-74,0]` 紫;空值或大于 `0` 透明。
+- `source/MapPark/GIS.qgz` 已删除四张废弃栅格图层,只保留“用户量”和“目标栅格竟对RSRP”;目标图默认勾选,用户量默认关闭。单市场包保留 GIS、BuildingInfo、两张 TIF 和两个 CSV;全网汇总包保留 GIS、BuildingInfo 和两张 TIF。
+- `summary.json` 现在记录三项筛选公式、严格阈值、目标 Grid 数量、各排除原因、八档颜色和像元数量;全局新增 `target_rsrp_legend.csv`。
+- 单市场 `1-城区蓬江` 端到端验证通过:109,102 个相交 Grid 中 511 个符合目标条件,目标图有效像元 17,130 个,实际出现 5 个 RSRP 色档,透明通道仅包含 `0/191`;zip 成员和 QGIS 两图层可见性均正确。标准库回归测试为 18 项并全部通过。
diff --git a/aidocs/technical_presentation.md b/aidocs/technical_presentation.md
index 7ba4b5e..82fb432 100644
--- a/aidocs/technical_presentation.md
+++ b/aidocs/technical_presentation.md
@@ -106,60 +106,15 @@ flowchart LR
- 根据市场边界生成透明底图画布。
- 将指标数据映射到空间像元矩阵。
-- 对指标值进行聚合、分级和平滑处理。
+- 按业务规则筛选、聚合和分级。
- 写入地理配准信息。
- 输出带透明度的专题图层。
-其中,信号质量、弱覆盖用户量、弱覆盖占比和移动优竟对弱用户分布专题图采用连续热力表达,而不是将像元机械切成几种色块。颜色在空间上形成连续过渡,可以更自然地表现信号质量、弱覆盖规模、弱覆盖比例和潜在用户机会聚集趋势。
-
-所有专题 TIF 均采用 RGBA 透明图层:有效像元透明度约为 75%,无数据区域完全透明,可直接叠加卫星影像、建筑图层和其他 GIS 底图。空间平滑只作用于有效数据区域,不会为无采集区域虚构指标值。
+当前成果只保留用户量和目标栅格竟对 RSRP 两张专题 TIF。两张图均采用 RGBA 透明图层:有效像元透明度约为 75%,无数据区域完全透明,可直接叠加卫星影像、建筑图层和其他 GIS 底图。
这种方式使网络指标既具备空间表达能力,又能保持较好的视觉呈现效果。
-### 6. RSRP 连续信号质量模型
-
-信号质量图采用红、黄、绿连续渐变表达,直接对应业务认知。颜色锚点沿用网络质量阈值,同时在锚点之间进行连续插值:信号越差越接近红色,信号越好越接近绿色。
-
-| RSRP 范围或锚点 | 颜色 | 业务含义 |
-| --- | --- | --- |
-| `<= -105` | 纯红 | 信号较差端点 |
-| `-105 ~ -95` | 红色连续过渡到黄色 | 信号逐步改善 |
-| `-95` | 黄色锚点 | 中间质量锚点 |
-| `-95 ~ -80` | 黄色连续过渡到绿色 | 信号继续改善 |
-| `>= -80` | 纯绿 | 信号良好端点 |
-
-该表达方式具备三个优点:
-
-- 颜色含义直观,适合汇报展示。
-- 阈值锚点清晰,便于跨市场对比。
-- 与指标表中的文字等级保持一致。
-
-红黄绿连续体系也更符合管理视角下的风险识别习惯,可以在保持阈值解释能力的同时,减少色块边界带来的视觉割裂。
-
-### 7. 弱覆盖用户量连续分位模型
-
-弱覆盖用户量图采用市场内动态百分位和连续颜色表达。系统先对弱覆盖用户量进行空间平滑,再依据当前市场的数据分布建立绿、黄、红三个颜色锚点。
-
-当前颜色锚点规则为:
-
-| 市场内动态位置 | 颜色 | 含义 |
-| --- | --- | --- |
-| 最高值 | 纯红 | 弱覆盖用户量最高 |
-| 第 75 百分位 | 黄色 | 连续渐变中间锚点 |
-| 最低值 | 纯绿 | 弱覆盖用户量最低 |
-
-颜色在三个锚点之间连续变化,红色主要聚焦最高值约 25% 的热点区域;相同数值保持同色,不按像元位置强制拆分。
-
-当当前处理范围内所有有效值完全相同时,图层统一显示黄色,表示存在弱覆盖用户采样,但没有可用于区分内部高低的相对差异。
-
-其优势在于:
-
-- 能适配不同市场之间的规模差异。
-- 能突出每个市场内部相对严重的问题区域,同时保留热点内部的细腻变化。
-- 避免固定阈值在小市场或大市场中失真。
-- 与信号质量图保持红黄绿一致表达。
-
-### 8. 用户量动态四分位模型
+### 6. 用户量动态四分位模型
用户量图保留四分位表达方式,用于体现用户分布梯度。
@@ -172,49 +127,30 @@ flowchart LR
用户量图主要用于识别用户聚集区域,为网络优化、资源投放和问题优先级判断提供参考。
-### 9. 弱覆盖占比连续色带模型
+### 7. 目标栅格竟对 RSRP 模型
-弱覆盖占比图用于刻画弱覆盖采样点在总采样点中的比例,计算口径为:
+目标图从 Grid 图层中筛选“移动弱覆盖比例较低、竟对采样规模较大且竟对弱覆盖比例较高”的位置。三个条件必须同时满足:
-> 弱覆盖占比 = 弱覆盖采样点(rsrp_lt_neg105_dl)/ 总采样点(mro_total_dl)× 100%
+- `rsrp_lt_neg105_yd / mro_total_yd < 20%`
+- `mro_total_dl > 1000`
+- `rsrp_lt_neg105_dl / mro_total_dl > 20%`
-系统先按空间栅格计算占比,再进行有效区域内的平滑处理,并在固定业务锚点之间连续插值。颜色由低风险端的绿色逐步过渡到蓝色、黄色和红色。
+两个比例都使用严格比较,恰好为 `20%` 的 Grid 不纳入;分母无效、采样量为空或为负时也不纳入。筛选后的 Grid 按原始 `ssb_rsrp_dl` 直接分八档显示,不做平滑:
-| 弱覆盖占比锚点或区间 | 颜色 | 业务含义 |
+| 竟对 RSRP 范围 | RGB | 业务含义 |
| --- | --- | --- |
-| `<= 0%` | 纯绿 | 绿色低值端点 |
-| `0% ~ 5%` | 绿色连续过渡到蓝色 | 弱覆盖占比逐渐升高 |
-| `5%` | 纯蓝 | 蓝色锚点 |
-| `5% ~ 10%` | 蓝色连续过渡到黄色 | 弱覆盖占比继续升高 |
-| `10%` | 纯黄 | 黄色锚点 |
-| `10% ~ 20%` | 黄色连续过渡到红色 | 数值越大越接近红色 |
-| `>= 20%` | 纯红 | 红色高值端点,达到后不再继续加深 |
-| 无有效总采样点 | 透明 | 不参与渲染 |
+| `< -110` | `253, 0, 5` | 极弱,红色 |
+| `[-110, -104)` | `255, 138, 0` | 很弱,橙色 |
+| `[-104, -98)` | `254, 253, 2` | 偏弱,黄色 |
+| `[-98, -92)` | `214, 251, 199` | 浅绿色 |
+| `[-92, -86)` | `42, 231, 41` | 亮绿色 |
+| `[-86, -80)` | `34, 174, 51` | 深绿色 |
+| `[-80, -74)` | `0, 149, 231` | 蓝色 |
+| `[-74, 0]` | `58, 14, 247` | 紫色 |
-该图采用固定锚点,便于不同市场之间进行同口径横向比较。需要特别说明的是:`10% ~ 20%` 区间内数值越大越红;达到 `20%` 后统一使用纯红色,因此 `20%`、`30%` 和更高占比在图例上均属于同一红色高风险端。
+未通过筛选、`ssb_rsrp_dl` 为空或大于 `0` 的位置保持透明。该模型保留 Grid 边界和原始 RSRP 档位,便于在 QGIS 中精确定位目标栅格。
-### 10. 移动优竟对弱用户机会分布模型
-
-移动优竟对弱用户分布图用于直接识别“移动网络具备承接能力、且存在竟对潜在用户”的目标 Grid。模型不再把竟对弱覆盖作为强制准入条件:移动信号好、竟对覆盖也好的用户区域同样显示,避免漏掉可以持续挖掘的潜在用户;竟对弱覆盖用户则获得额外机会权重。
-
-模型采用“移动准入门槛 + 综合机会分值”的业务规则:
-
-- 移动信号门槛:`ssb_rsrp_yd > -95`。
-- 用户准入条件:竟对总采样量 `mro_total_dl > 0`。
-- 机会分值:`mro_total_dl + max(rsrp_lt_neg105_dl, 0)`。
-- 竟对弱覆盖采样量为 `0` 时仍按总采样量显示;每个弱覆盖采样再额外计一次权重。
-- 移动信号未达到门槛、移动信号无效或没有竟对总采样量时保持透明。
-
-| 动态位置 | 颜色 | 业务含义 |
-| --- | --- | --- |
-| 最高值 | 纯红 | 竟对用户规模与弱覆盖机会的综合优先级最高 |
-| 第 75 百分位 | 黄色 | 重点机会区域的动态锚点 |
-| 最低正值 | 纯绿 | 存在可挖掘竟对用户,但综合机会分值较低 |
-| 移动未达标或无竟对用户 | 透明 | 当前不具备挖掘条件 |
-
-目标图使用独立平滑半径 `5`,在表达机会聚集趋势的同时保留较清晰的空间定位。市场级图按本市场数据分布建立色带,用于发现市场内部热点;全网汇总图按全域数据重新建立统一色带,用于跨市场比较。若当前范围内所有机会分值完全相同,则统一显示黄色,表示存在目标用户但没有内部高低差异。总采样量和弱覆盖采样量都不是去重后的真实用户数。
-
-### 11. GeoPackage 图层结构与样式保留
+### 8. GeoPackage 图层结构与样式保留
建筑信息成果并非普通属性表导出,而是保留为标准 GeoPackage 空间图层。
@@ -229,9 +165,9 @@ flowchart LR
BuildingInfo 图层不由平台重新定义业务颜色,其图例直接沿用源空间数据中已配置的 QGIS 样式。市场级成果保留相交楼宇和原始样式;全网汇总成果保留完整 BuildingInfo 图层及其样式信息。
-### 12. QGIS 工程化成果封装
+### 9. QGIS 工程化成果封装
-平台会将 GIS 项目模板与每个市场的专题图层、建筑图层和指标表统一打包。项目模板已注册信号、用户量、弱覆盖用户量、弱覆盖占比和移动优竟对弱用户分布图五张专题图,打开后可以直接切换图层查看。其中移动优竟对弱用户分布图作为核心目标图层默认勾选,其他专题栅格默认关闭,避免透明区域露出下层颜色而混淆目标范围。
+平台会将 GIS 项目模板与每个市场的专题图层、建筑图层和指标表统一打包。项目模板只注册用户量和目标栅格竟对 RSRP 两张专题图;目标图默认勾选,用户量图默认关闭。
最终交付物不再是零散文件,而是围绕市场网格组织好的工程化成果包。
@@ -244,7 +180,7 @@ BuildingInfo 图层不由平台重新定义业务颜色,其图例直接沿用
项目打开时会根据当前市场的 BuildingInfo 实际空间范围自动设置主画布,并在范围四周保留适当留白。这样成果包打开后即可进入当前市场的楼宇区域,减少人工缩放和图层定位操作。
-### 13. 指标表标准化输出
+### 10. 指标表标准化输出
平台同步输出楼宇指标表和栅格指标表,并统一增加市场网格标识字段。
@@ -271,15 +207,12 @@ BuildingInfo 图层不由平台重新定义业务颜色,其图例直接沿用
| 成果图层 | 指标来源或作用 | 图例规则 | 无数据规则 |
| --- | --- | --- | --- |
-| 信号.tif | 平均信号值(ssb_rsrp_dl) | `<= -105` 红、`-95` 黄、`>= -80` 绿,区间连续渐变 | 透明 |
| 用户量.tif | 总采样点(mro_total_dl) | 市场内动态四分位:红、黄、蓝、绿 | 透明 |
-| 信号差用户量.tif | 弱覆盖采样点(rsrp_lt_neg105_dl) | 最低值绿、第 75 百分位黄、最高值红,连续渐变 | 透明 |
-| 弱覆盖占比.tif | rsrp_lt_neg105_dl / mro_total_dl | `0%` 绿、`5%` 蓝、`10%` 黄、`20%` 红,区间连续渐变 | 总采样点无效时透明 |
-| 移动优竟对弱用户分布图.tif | `ssb_rsrp_yd > -95` 时的 `mro_total_dl + max(rsrp_lt_neg105_dl, 0)` | 最低正值绿、第 75 百分位黄、最高值红,连续渐变 | 移动未达标或总采样量无效时透明 |
+| 目标栅格竟对RSRP.tif | 三项条件筛选后的 ssb_rsrp_dl | `< -110` 至 `[-74, 0]` 共八档固定颜色 | 未通过筛选或 RSRP 无效时透明 |
| BuildingInfo.gpkg | 建筑信息空间图层 | 沿用源 QGIS 图层样式 | 不适用 |
| GIS.qgz | GIS 项目与图层组织 | 集中加载上述图层并自动定位 | 不适用 |
-五张专题 TIF 的有效像元均使用约 75% 不透明度,便于在保留专题颜色的同时观察底图和建筑纹理。信号和弱覆盖占比采用固定物理或业务锚点,适合跨市场比较;用户量、弱覆盖用户量和移动优竟对弱用户分布图采用动态分布规则,重点反映当前处理范围内的相对热点。
+两张专题 TIF 的有效像元均使用约 75% 不透明度。用户量采用动态四分位,目标 RSRP 采用固定筛选口径和固定八档颜色。
### 2. 标准成果包
@@ -287,15 +220,12 @@ BuildingInfo 图层不由平台重新定义业务颜色,其图例直接沿用
- GIS 项目文件
- 建筑信息空间图层
-- 信号质量专题图
- 用户量专题图
-- 弱覆盖用户量专题图
-- 弱覆盖占比专题图
-- 移动优竟对弱用户分布专题图
+- 目标栅格竟对 RSRP 专题图
- 楼宇指标明细表
- 栅格指标明细表
-同时生成全网汇总成果包,包含五张全域专题 TIF、完整 BuildingInfo 空间图层和 GIS 项目,不包含指标 CSV。全网汇总中的用户量、弱覆盖用户量和移动优竟对弱用户分布图会按全域有效像元重新计算动态阈值;信号和弱覆盖占比继续使用固定锚点,确保市场级与全网级解释口径一致。
+同时生成全网汇总成果包,包含两张全域专题 TIF、完整 BuildingInfo 空间图层和 GIS 项目,不包含指标 CSV。全网汇总中的用户量会按全域有效像元重新计算动态四分位;目标 RSRP 继续使用同一筛选口径和固定八档颜色。
全局还会生成图例说明和处理汇总信息,用于追溯每个市场的输出结果、阈值记录和处理统计。
@@ -315,11 +245,11 @@ BuildingInfo 图层不由平台重新定义业务颜色,其图例直接沿用
### 4. 支撑精细化运营
-成果可以直接用于识别信号较差区域、弱覆盖用户聚集区域、弱覆盖高占比区域、高用户量区域,以及“移动信号良好、竟对用户规模较大或弱覆盖机会较高”的目标区域,为网络优化和精细化运营提供依据。
+成果可以直接用于识别高用户量区域,以及“移动弱覆盖比例低于 20%、竟对采样量超过 1000、竟对弱覆盖比例高于 20%”的目标 Grid,为精细化运营提供依据。
### 5. 便于汇报展示
-连续色带与动态分位体系直观清晰,成果包可直接加载到 GIS 项目中进行展示,适合专题汇报和问题复盘。
+动态四分位和固定八档 RSRP 图例直观清晰,成果包可直接加载到 GIS 项目中进行展示,适合专题汇报和问题复盘。
## 七、技术价值总结
diff --git a/main.py b/main.py
index cd572b8..355753f 100644
--- a/main.py
+++ b/main.py
@@ -31,7 +31,8 @@ GIS_PROJECT_SOURCE = MAP_PARK_DIR / "GIS.qgz" # 每个市场网格结果包要
RSRP_FIELD = "ssb_rsrp_dl" # 用于生成热力图的电信 RSRP 字段名。
EXCELLENT_CELL_FIELD = "mro_total_dl" # 用于生成用户量热力图的字段名,值越大越红。
WEAK_COVER_FIELD = "rsrp_lt_neg105_dl" # 用于生成信号差用户量热力图的字段名,值越大越红。
-MOBILE_RSRP_FIELD = "ssb_rsrp_yd" # 移动 RSRP 字段名,用于筛选移动信号达到正常水平的 Grid。
+MOBILE_TOTAL_FIELD = "mro_total_yd" # 移动采样点总数字段,用作移动弱覆盖比例分母。
+MOBILE_WEAK_COVER_FIELD = "rsrp_lt_neg105_yd" # 移动弱覆盖采样点字段,用作目标 Grid 筛选。
MARKET_LAYER = None # 市场网格图层名;None 表示自动使用 GPKG 中第一个 feature 图层。
GRID_LAYER = None # Grid 指标图层名;None 表示自动使用 GPKG 中第一个 feature 图层。
BUILDING_LAYER = None # Building 建筑指标图层名;None 表示自动使用 GPKG 中第一个 feature 图层。
@@ -39,7 +40,6 @@ BUILDING_INFO_LAYER = None # BuildingInfo 建筑信息图层名;None 表示
MARKET_CODE_FIELD = "fid" # 市场网格唯一 ID 前缀字段,新版 MarketMap 使用 fid。
MARKET_NAME_FIELD = "Name" # 市场网格名称字段,新版 MarketMap 使用 Name。
MARKET_ID_SEPARATOR = "-" # 市场网格唯一 ID 拼接符,输出为 fid-name,例如 1-城区蓬江。
-SIGNAL_OUTPUT_FILENAME = "信号.tif" # RSRP 连续红黄绿热力图输出文件名。
BUILDING_INFO_OUTPUT_FILENAME = "BuildingInfo.gpkg" # 每个市场网格结果包内输出的建筑信息拆分文件名。
BUILDING_METRICS_CSV_FILENAME = "楼宇指标.csv" # 每个市场网格结果包内输出的楼宇指标 CSV 文件名。
GRID_METRICS_CSV_FILENAME = "栅格指标.csv" # 每个市场网格结果包内输出的栅格指标 CSV 文件名。
@@ -48,43 +48,36 @@ CSV_SOURCE_FIELDS = ("area_type", "area_name", "longitude", "latitude", "mro_tot
SIGNAL_BAD_THRESHOLD = -105.0 # 信号等级“较差”的阈值,小于等于该值输出较差。
SIGNAL_NORMAL_THRESHOLD = -95.0 # 信号等级“一般/正常”的分界,大于该值输出正常。
GIS_PROJECT_OUTPUT_FILENAME = "GIS.qgz" # 每个市场网格结果包内输出的 QGIS 项目文件名,画布范围按 BuildingInfo 自动更新。
-HEATMAP_MID_RSRP = -95.0 # 热力图黄色中间阈值。
-HEATMAP_BAD_RSRP = -105.0 # 热力图红色端阈值;RSRP 小于等于该值视为信号差。
-HEATMAP_GOOD_RSRP = -80.0 # 热力图绿色端阈值;RSRP 大于等于该值使用纯绿色。
HEATMAP_SMOOTH_RADIUS = 10 # 热力图平滑半径,数值越大边界感越弱但细节越柔。
HEATMAP_ALPHA = 191 # 热力图有效像元透明度;191 约等于 75% 不透明度。
PROJECT_EXTENT_PADDING_RATIO = 0.05 # QGIS 打开后的画布留白比例;0.05 表示在 BuildingInfo 范围四周各增加 5%。
USER_COUNT_OUTPUT_FILENAME = "用户量.tif" # 采样点数量热力图输出文件名。
-WEAK_COVER_OUTPUT_FILENAME = "信号差用户量.tif" # 信号差用户量热力图输出文件名。
-WEAK_COVER_RATIO_OUTPUT_FILENAME = "弱覆盖占比.tif" # 弱覆盖采样点占总采样点比例的分级 TIF 输出文件名。
-MOBILE_ADVANTAGE_OUTPUT_FILENAME = "移动优竟对弱用户分布图.tif" # 移动信号好区域内的竟对潜在用户机会分布图文件名。
-MOBILE_ADVANTAGE_GOOD_RSRP_THRESHOLD = -95.0 # 移动信号门槛;仅 ssb_rsrp_yd 严格大于该值的 Grid 参与目标热力图。
-MOBILE_ADVANTAGE_YELLOW_PERCENTILE = 0.75 # 目标热力图黄色锚点百分位;高于该位置的热点逐步由黄色趋向红色。
-MOBILE_ADVANTAGE_SMOOTH_RADIUS = 5 # 目标热力图平滑半径;默认 5 以保留定位精度,可改为 10 或其他非负整数。
-MOBILE_ADVANTAGE_SCORE_FORMULA = f"{EXCELLENT_CELL_FIELD} + max({WEAK_COVER_FIELD}, 0)" # 机会分值:竟对总采样量计一次,弱覆盖采样量额外加一次。
-WEAK_COVER_RATIO_GREEN_ANCHOR = 0.0 # 弱覆盖占比连续色带绿色端点,单位为百分比。
-WEAK_COVER_RATIO_BLUE_ANCHOR = 5.0 # 弱覆盖占比连续色带蓝色锚点,单位为百分比。
-WEAK_COVER_RATIO_YELLOW_ANCHOR = 10.0 # 弱覆盖占比连续色带黄色锚点,单位为百分比。
-WEAK_COVER_RATIO_RED_ANCHOR = 20.0 # 弱覆盖占比连续色带红色端点,达到该值后保持红色。
-WEAK_COVER_RATIO_GREEN = (0, 176, 80) # 弱覆盖占比低值档颜色。
-WEAK_COVER_RATIO_BLUE = (0, 112, 255) # 弱覆盖占比偏低档颜色。
-WEAK_COVER_RATIO_YELLOW = (255, 255, 0) # 弱覆盖占比偏高档颜色。
-WEAK_COVER_RATIO_RED = (255, 0, 0) # 弱覆盖占比高值档颜色。
+TARGET_RSRP_OUTPUT_FILENAME = "目标栅格竟对RSRP.tif" # 满足移动非弱覆盖、竟对高价值弱覆盖条件的 Grid 八档 RSRP 图。
+TARGET_MOBILE_WEAK_RATIO_MAX = 20.0 # 移动弱覆盖比例必须严格小于该百分比。
+TARGET_COMPETITOR_TOTAL_MIN = 200.0 # 竟对采样点总数必须严格大于该值。
+TARGET_COMPETITOR_WEAK_RATIO_MIN = 20.0 # 竟对弱覆盖比例必须严格大于该百分比。
+TARGET_RSRP_BREAKS = (-110.0, -104.0, -98.0, -92.0, -86.0, -80.0, -74.0) # 八档颜色的七个分界点。
+TARGET_RSRP_COLORS = (
+ (253, 0, 5), # < -110,红色。
+ (255, 138, 0), # [-110, -104),橙色。
+ (254, 253, 2), # [-104, -98),黄色。
+ (214, 251, 199), # [-98, -92),浅绿色。
+ (42, 231, 41), # [-92, -86),亮绿色。
+ (34, 174, 51), # [-86, -80),深绿色。
+ (0, 149, 231), # [-80, -74),蓝色。
+ (58, 14, 247), # [-74, 0],紫色。
+)
SUMMARY_OUTPUT_ENABLED = True # 是否额外生成全部市场网格汇总 TIF 结果包。
-SUMMARY_OUTPUT_FILENAME = "所有网格汇总.zip" # 汇总结果包文件名,包含五张 TIF、GIS.qgz 和完整 BuildingInfo.gpkg。
+SUMMARY_OUTPUT_FILENAME = "所有网格汇总.zip" # 汇总结果包文件名,包含两张 TIF、GIS.qgz 和完整 BuildingInfo.gpkg。
SUMMARY_MARKET_CODE = "所有网格汇总" # 汇总任务在日志和 summary.json 中使用的标识。
SUMMARY_MAX_RASTER_PIXELS = 100_000_000 # 汇总 TIF 最大像元数;提高该值可增强清晰度,但会增加内存、耗时和文件体积。
-EXCELLENT_PERCENT_STEPS = (0.25, 0.5, 0.75) # 按最终有效像元降序四等分,取 25%、50%、75% 位置作为结果记录阈值。
+EXCELLENT_PERCENT_STEPS = (0.1, 0.4, 0.7) # 按最终有效像元降序四等分,取 25%、50%、75% 位置作为结果记录阈值。
EXCELLENT_COLORS = (
(255, 0, 0), # 高值端,红色。
(255, 255, 0), # 偏高值,黄色。
(0, 112, 255), # 偏低值,蓝色。
(0, 176, 80), # 低值端,绿色。
)
-CONTINUOUS_HEATMAP_RED = (255, 0, 0) # 连续热力图高风险端颜色。
-CONTINUOUS_HEATMAP_YELLOW = (255, 255, 0) # 连续热力图中间颜色。
-CONTINUOUS_HEATMAP_GREEN = (0, 176, 80) # 连续热力图低风险端颜色。
-WEAK_COVER_YELLOW_PERCENTILE = 0.75 # 信号差用户量黄色锚点百分位;0.75 使红色集中在最高值约 25% 区域。
PIXEL_WIDTH = None # 输出像元宽度;None 表示自动按 Grid 单元宽度估算。
PIXEL_HEIGHT = None # 输出像元高度;None 表示自动按 Grid 单元高度估算。
SCALE = 5.0 # 分辨率倍数;2.0 表示像元宽高减半,放大查看更清晰。
@@ -145,24 +138,12 @@ def build_summary_market(markets):
return MarketFeature(0, SUMMARY_MARKET_CODE, SUMMARY_MARKET_CODE, geometry)
-def heatmap_raster_filename(_field):
- return SIGNAL_OUTPUT_FILENAME
-
-
def excellent_heatmap_raster_filename(_field):
return USER_COUNT_OUTPUT_FILENAME
-def weak_cover_heatmap_raster_filename(_field):
- return WEAK_COVER_OUTPUT_FILENAME
-
-
-def weak_cover_ratio_raster_filename():
- return WEAK_COVER_RATIO_OUTPUT_FILENAME
-
-
-def mobile_advantage_raster_filename():
- return MOBILE_ADVANTAGE_OUTPUT_FILENAME
+def target_rsrp_raster_filename():
+ return TARGET_RSRP_OUTPUT_FILENAME
def set_xml_extent(extent_element, extent):
@@ -245,11 +226,8 @@ def copy_gis_project_to_market(source_path, output_path, market, building_extent
set_xml_extent(layer_extent_element, layer_extent)
raster_filenames = {
- SIGNAL_OUTPUT_FILENAME,
USER_COUNT_OUTPUT_FILENAME,
- WEAK_COVER_OUTPUT_FILENAME,
- WEAK_COVER_RATIO_OUTPUT_FILENAME,
- MOBILE_ADVANTAGE_OUTPUT_FILENAME,
+ TARGET_RSRP_OUTPUT_FILENAME,
}
for layer in root.findall(".//projectlayers/maplayer"):
datasource = (layer.findtext("datasource") or "").replace("\\", "/")
@@ -899,85 +877,6 @@ def estimate_pixel_size(conn, layer, sample_size):
return float(np.median(widths)), float(np.median(heights))
-def continuous_heatmap_rgb_for_scores(scores, yellow_score=0.5):
- if not 0 < yellow_score < 1:
- raise ValueError("yellow_score 必须大于 0 且小于 1")
- normalized = np.clip(np.asarray(scores, dtype=np.float32), 0.0, 1.0)
- result = np.empty((*normalized.shape, 3), dtype=np.float32)
- green = np.asarray(CONTINUOUS_HEATMAP_GREEN, dtype=np.float32)
- yellow = np.asarray(CONTINUOUS_HEATMAP_YELLOW, dtype=np.float32)
- red = np.asarray(CONTINUOUS_HEATMAP_RED, dtype=np.float32)
-
- lower_mask = normalized <= yellow_score
- lower_weight = (normalized[lower_mask] / yellow_score)[..., None]
- result[lower_mask] = green + (yellow - green) * lower_weight
-
- upper_mask = ~lower_mask
- upper_weight = ((normalized[upper_mask] - yellow_score) / (1.0 - yellow_score))[..., None]
- result[upper_mask] = yellow + (red - yellow) * upper_weight
- return np.rint(np.clip(result, 0, 255)).astype(np.uint8)
-
-
-def heatmap_rgb_for_values(values):
- values = np.asarray(values, dtype=np.float32)
- scores = np.empty(values.shape, dtype=np.float32)
- scores[values <= HEATMAP_BAD_RSRP] = 1.0
-
- middle_mask = (values > HEATMAP_BAD_RSRP) & (values <= HEATMAP_MID_RSRP)
- scores[middle_mask] = 1.0 - 0.5 * (
- (values[middle_mask] - HEATMAP_BAD_RSRP) / (HEATMAP_MID_RSRP - HEATMAP_BAD_RSRP)
- )
-
- good_mask = (values > HEATMAP_MID_RSRP) & (values < HEATMAP_GOOD_RSRP)
- scores[good_mask] = 0.5 * (
- (HEATMAP_GOOD_RSRP - values[good_mask]) / (HEATMAP_GOOD_RSRP - HEATMAP_MID_RSRP)
- )
- scores[values >= HEATMAP_GOOD_RSRP] = 0.0
- return continuous_heatmap_rgb_for_scores(scores)
-
-
-def weak_cover_ratio_rgb_for_values(values):
- values = np.asarray(values, dtype=np.float32)
- colors = np.empty((*values.shape, 3), dtype=np.float32)
- anchors = (
- (WEAK_COVER_RATIO_GREEN_ANCHOR, WEAK_COVER_RATIO_GREEN),
- (WEAK_COVER_RATIO_BLUE_ANCHOR, WEAK_COVER_RATIO_BLUE),
- (WEAK_COVER_RATIO_YELLOW_ANCHOR, WEAK_COVER_RATIO_YELLOW),
- (WEAK_COVER_RATIO_RED_ANCHOR, WEAK_COVER_RATIO_RED),
- )
- colors[:] = anchors[0][1]
- for (lower_value, lower_color), (upper_value, upper_color) in zip(anchors, anchors[1:]):
- mask = (values > lower_value) & (values < upper_value)
- weight = ((values[mask] - lower_value) / (upper_value - lower_value))[..., None]
- lower_rgb = np.asarray(lower_color, dtype=np.float32)
- upper_rgb = np.asarray(upper_color, dtype=np.float32)
- colors[mask] = lower_rgb + (upper_rgb - lower_rgb) * weight
- colors[values == upper_value] = upper_rgb
- colors[values >= WEAK_COVER_RATIO_RED_ANCHOR] = WEAK_COVER_RATIO_RED
- return np.rint(np.clip(colors, 0, 255)).astype(np.uint8)
-
-
-def percentile_scores_for_values(values, data_mask, anchor_scores=(0.0, 0.5, 1.0)):
- scores = np.zeros(values.shape, dtype=np.float32)
- valid_values = values[data_mask]
- if valid_values.size == 0:
- return scores, []
-
- unique_values, inverse, counts = np.unique(valid_values, return_inverse=True, return_counts=True)
- if unique_values.size == 1:
- scores[data_mask] = anchor_scores[len(anchor_scores) // 2]
- return scores, [float(unique_values[0])] * len(anchor_scores)
-
- cumulative_before = np.cumsum(counts, dtype=np.int64) - counts
- rank_scores = cumulative_before.astype(np.float32) / float(cumulative_before[-1])
- scores[data_mask] = rank_scores[inverse]
- anchor_values = []
- for anchor_score in anchor_scores:
- index = min(int(np.searchsorted(rank_scores, anchor_score, side="left")), unique_values.size - 1)
- anchor_values.append(float(unique_values[index]))
- return scores, anchor_values
-
-
def percentile_thresholds_from_values(values, percent_steps):
sorted_values = np.sort(np.asarray(values, dtype=np.float32))[::-1]
sorted_values = sorted_values[np.isfinite(sorted_values)]
@@ -1079,13 +978,39 @@ def to_float(value):
return None
-def mobile_advantage_opportunity_score(mobile_rsrp, total_users, weak_cover_users):
- if mobile_rsrp is None or total_users is None:
- return None
- if mobile_rsrp <= MOBILE_ADVANTAGE_GOOD_RSRP_THRESHOLD or total_users <= 0:
- return None
- weak_cover_bonus = weak_cover_users if weak_cover_users is not None and weak_cover_users > 0 else 0.0
- return total_users + weak_cover_bonus
+def target_grid_filter_reason(mobile_weak, mobile_total, competitor_weak, competitor_total):
+ values = (mobile_weak, mobile_total, competitor_weak, competitor_total)
+ if any(value is None for value in values):
+ return "invalid_fields"
+ if mobile_total <= 0 or mobile_weak < 0 or competitor_total <= 0 or competitor_weak < 0:
+ return "invalid_fields"
+ mobile_weak_ratio = mobile_weak / mobile_total * 100.0
+ if mobile_weak_ratio >= TARGET_MOBILE_WEAK_RATIO_MAX:
+ return "mobile_weak_ratio"
+ if competitor_total <= TARGET_COMPETITOR_TOTAL_MIN:
+ return "competitor_total"
+ competitor_weak_ratio = competitor_weak / competitor_total * 100.0
+ if competitor_weak_ratio <= TARGET_COMPETITOR_WEAK_RATIO_MIN:
+ return "competitor_weak_ratio"
+ return None
+
+
+def target_grid_is_eligible(mobile_weak, mobile_total, competitor_weak, competitor_total):
+ return target_grid_filter_reason(mobile_weak, mobile_total, competitor_weak, competitor_total) is None
+
+
+def target_rsrp_rgb_for_values(values):
+ values = np.asarray(values, dtype=np.float32)
+ colors = np.zeros((*values.shape, 3), dtype=np.uint8)
+ valid_mask = np.isfinite(values) & (values <= 0)
+ if np.any(valid_mask):
+ color_indices = np.searchsorted(
+ np.asarray(TARGET_RSRP_BREAKS, dtype=np.float32),
+ values[valid_mask],
+ side="right",
+ )
+ colors[valid_mask] = np.asarray(TARGET_RSRP_COLORS, dtype=np.uint8)[color_indices]
+ return colors, valid_mask
def geotiff_extratags(minx, maxy, pixel_width, pixel_height):
@@ -1171,49 +1096,6 @@ def market_raster_layout(bounds, pixel_width, pixel_height, max_raster_pixels=No
return minx, miny, maxx, maxy, pixel_width, pixel_height, width, height, scale_factor
-def smooth_weighted_values(value_sum, value_weight, radius):
- data_mask = value_weight > 0
- smoothed_value = np.zeros_like(value_sum)
- if np.any(data_mask):
- smoothed_sum = gaussian_blur(value_sum, radius)
- smoothed_weight = gaussian_blur(value_weight, radius)
- np.divide(smoothed_sum, smoothed_weight, out=smoothed_value, where=smoothed_weight > 0)
- return smoothed_value, data_mask
-
-
-def render_signal_raster(state, market, output_path, minx, maxy, pixel_width, pixel_height, width, height, candidates):
- image = np.full((height, width, 4), TRANSPARENT_PIXEL, dtype=np.uint8)
- smoothed_value, data_mask = smooth_weighted_values(
- state["value_sum"],
- state["value_weight"],
- HEATMAP_SMOOTH_RADIUS,
- )
- if np.any(data_mask):
- image[data_mask, :3] = heatmap_rgb_for_values(smoothed_value)[data_mask]
- image[data_mask, 3] = HEATMAP_ALPHA
-
- write_rgba_geotiff(output_path, image, minx, maxy, pixel_width, pixel_height)
- return {
- "market_code": market.code,
- "market_name": market.name,
- "output": str(output_path),
- "candidates": candidates,
- "painted_pixels": state["painted_cells"],
- "data_pixels": int(np.count_nonzero(data_mask)),
- "skipped_no_value": state["skipped_no_value"],
- "color_mode": "continuous_fixed_rsrp",
- "color_anchors": {
- "red": HEATMAP_BAD_RSRP,
- "yellow": HEATMAP_MID_RSRP,
- "green": HEATMAP_GOOD_RSRP,
- },
- "smooth_radius": HEATMAP_SMOOTH_RADIUS,
- "width": width,
- "height": height,
- "skipped": False,
- }
-
-
def replace_file_with_retry(source_path, target_path, attempts=20, delay_seconds=0.5):
for attempt in range(attempts):
try:
@@ -1225,104 +1107,6 @@ def replace_file_with_retry(source_path, target_path, attempts=20, delay_seconds
sleep(delay_seconds)
-def render_percentile_heatmap_raster(
- state,
- market,
- output_path,
- minx,
- maxy,
- pixel_width,
- pixel_height,
- width,
- height,
- candidates,
- yellow_percentile,
- smooth_radius,
-):
- image = np.full((height, width, 4), TRANSPARENT_PIXEL, dtype=np.uint8)
- smoothed_value, data_mask = smooth_weighted_values(
- state["value_sum"],
- state["value_weight"],
- smooth_radius,
- )
- anchor_values = []
- if np.any(data_mask):
- anchor_scores = (0.0, yellow_percentile, 1.0)
- scores, anchor_values = percentile_scores_for_values(smoothed_value, data_mask, anchor_scores)
- image[data_mask, :3] = continuous_heatmap_rgb_for_scores(
- scores,
- yellow_score=yellow_percentile,
- )[data_mask]
- image[data_mask, 3] = HEATMAP_ALPHA
-
- write_rgba_geotiff(output_path, image, minx, maxy, pixel_width, pixel_height)
- return {
- "market_code": market.code,
- "market_name": market.name,
- "output": str(output_path),
- "candidates": candidates,
- "painted_cells": state["painted_cells"],
- "data_pixels": int(np.count_nonzero(data_mask)),
- "skipped_no_value": state["skipped_no_value"],
- "color_mode": "continuous_percentile",
- "yellow_percentile": yellow_percentile,
- "color_anchor_values": {
- "green": anchor_values[0],
- "yellow": anchor_values[1],
- "red": anchor_values[2],
- } if anchor_values else None,
- "smooth_radius": smooth_radius,
- "width": width,
- "height": height,
- "skipped": False,
- }
-
-
-def render_weak_cover_ratio_raster(
- state,
- market,
- output_path,
- minx,
- maxy,
- pixel_width,
- pixel_height,
- width,
- height,
- candidates,
-):
- image = np.full((height, width, 4), TRANSPARENT_PIXEL, dtype=np.uint8)
- smoothed_value, data_mask = smooth_weighted_values(
- state["value_sum"],
- state["value_weight"],
- HEATMAP_SMOOTH_RADIUS,
- )
- if np.any(data_mask):
- image[data_mask, :3] = weak_cover_ratio_rgb_for_values(smoothed_value)[data_mask]
- image[data_mask, 3] = HEATMAP_ALPHA
-
- write_rgba_geotiff(output_path, image, minx, maxy, pixel_width, pixel_height)
- return {
- "market_code": market.code,
- "market_name": market.name,
- "output": str(output_path),
- "candidates": candidates,
- "painted_cells": state["painted_cells"],
- "data_pixels": int(np.count_nonzero(data_mask)),
- "skipped_no_value": state["skipped_no_value"],
- "color_mode": "continuous_fixed_weak_cover_ratio",
- "percentage_anchors": {
- "green": WEAK_COVER_RATIO_GREEN_ANCHOR,
- "blue": WEAK_COVER_RATIO_BLUE_ANCHOR,
- "yellow": WEAK_COVER_RATIO_YELLOW_ANCHOR,
- "red": WEAK_COVER_RATIO_RED_ANCHOR,
- },
- "smooth_radius": HEATMAP_SMOOTH_RADIUS,
- "width": width,
- "height": height,
- "skipped": False,
- }
-
-
def render_ranked_raster(
state,
market,
@@ -1375,6 +1159,60 @@ def render_ranked_raster(
}
+def render_target_rsrp_raster(
+ state,
+ market,
+ output_path,
+ minx,
+ maxy,
+ pixel_width,
+ pixel_height,
+ width,
+ height,
+ candidates,
+):
+ image = np.full((height, width, 4), TRANSPARENT_PIXEL, dtype=np.uint8)
+ value_sum = state["value_sum"]
+ value_weight = state["value_weight"]
+ data_mask = value_weight > 0
+ class_pixel_counts = [0] * len(TARGET_RSRP_COLORS)
+ if np.any(data_mask):
+ value_raster = np.zeros_like(value_sum)
+ np.divide(value_sum, value_weight, out=value_raster, where=data_mask)
+ colors, valid_rsrp_mask = target_rsrp_rgb_for_values(value_raster)
+ render_mask = data_mask & valid_rsrp_mask
+ image[render_mask, :3] = colors[render_mask]
+ image[render_mask, 3] = HEATMAP_ALPHA
+ class_indices = np.searchsorted(
+ np.asarray(TARGET_RSRP_BREAKS, dtype=np.float32),
+ value_raster[render_mask],
+ side="right",
+ )
+ class_pixel_counts = np.bincount(
+ class_indices,
+ minlength=len(TARGET_RSRP_COLORS),
+ ).astype(int).tolist()
+
+ write_rgba_geotiff(output_path, image, minx, maxy, pixel_width, pixel_height)
+ return {
+ "market_code": market.code,
+ "market_name": market.name,
+ "output": str(output_path),
+ "candidates": candidates,
+ "painted_cells": state["painted_cells"],
+ "data_pixels": int(np.count_nonzero(image[..., 3])),
+ "skipped_no_value": state["skipped_no_value"],
+ "color_mode": "discrete_target_rsrp",
+ "rsrp_breaks": list(TARGET_RSRP_BREAKS),
+ "colors": [list(color) for color in TARGET_RSRP_COLORS],
+ "class_pixel_counts": class_pixel_counts,
+ "smooth_radius": 0,
+ "width": width,
+ "height": height,
+ "skipped": False,
+ }
+
+
def export_market_grid_outputs(
grid_conn,
grid_layer,
@@ -1382,11 +1220,8 @@ def export_market_grid_outputs(
market,
pixel_width,
pixel_height,
- signal_path,
user_count_path,
- weak_cover_path,
- weak_cover_ratio_path,
- mobile_advantage_path,
+ target_rsrp_path,
csv_path,
max_raster_pixels=None,
):
@@ -1396,12 +1231,18 @@ def export_market_grid_outputs(
pixel_height,
max_raster_pixels,
)
- raster_fields = (RSRP_FIELD, EXCELLENT_CELL_FIELD, WEAK_COVER_FIELD, MOBILE_RSRP_FIELD)
+ raster_fields = (
+ EXCELLENT_CELL_FIELD,
+ RSRP_FIELD,
+ WEAK_COVER_FIELD,
+ MOBILE_TOTAL_FIELD,
+ MOBILE_WEAK_COVER_FIELD,
+ )
skipped_no_value = {field: 0 for field in raster_fields}
painted_cells = {field: 0 for field in raster_fields}
raster_cells = []
- fields = list(dict.fromkeys(CSV_SOURCE_FIELDS if csv_path is not None else raster_fields))
+ fields = list(dict.fromkeys((*CSV_SOURCE_FIELDS, *raster_fields) if csv_path is not None else raster_fields))
if csv_path is None and CLIP_MODE == "center":
fields.extend(field for field in ("longitude", "latitude") if field not in fields)
require_columns(grid_conn, grid_layer.table_name, fields)
@@ -1484,10 +1325,11 @@ def export_market_grid_outputs(
row_stop,
col_start,
col_stop,
- numeric_values[RSRP_FIELD],
numeric_values[EXCELLENT_CELL_FIELD],
+ numeric_values[RSRP_FIELD],
numeric_values[WEAK_COVER_FIELD],
- numeric_values[MOBILE_RSRP_FIELD],
+ numeric_values[MOBILE_TOTAL_FIELD],
+ numeric_values[MOBILE_WEAK_COVER_FIELD],
)
)
finally:
@@ -1511,12 +1353,7 @@ def export_market_grid_outputs(
"skipped_no_value": skipped_no_value[field],
}
- signal_state = build_state(RSRP_FIELD, 0)
- signal_result = render_signal_raster(
- signal_state, market, signal_path, minx, maxy, pixel_width, pixel_height, width, height, candidates
- )
- del signal_state
- user_count_state = build_state(EXCELLENT_CELL_FIELD, 1)
+ user_count_state = build_state(EXCELLENT_CELL_FIELD, 0)
user_count_result = render_ranked_raster(
user_count_state,
market,
@@ -1532,48 +1369,49 @@ def export_market_grid_outputs(
EXCELLENT_PERCENT_STEPS,
)
del user_count_state
- weak_cover_state = build_state(WEAK_COVER_FIELD, 2)
- weak_cover_result = render_percentile_heatmap_raster(
- weak_cover_state,
- market,
- weak_cover_path,
- minx,
- maxy,
- pixel_width,
- pixel_height,
- width,
- height,
- candidates,
- WEAK_COVER_YELLOW_PERCENTILE,
- HEATMAP_SMOOTH_RADIUS,
- )
- del weak_cover_state
- ratio_value_sum = np.zeros((height, width), dtype=np.float32)
- ratio_value_weight = np.zeros((height, width), dtype=np.uint16)
- ratio_painted_cells = 0
- ratio_skipped_no_value = 0
- for cell in raster_cells:
- row_start, row_stop, col_start, col_stop = cell[:4]
- total = cell[5]
- weak_cover = cell[6]
- if total is None or total <= 0 or weak_cover is None or weak_cover < 0:
- ratio_skipped_no_value += 1
- continue
- ratio = weak_cover / total * 100.0
- ratio_value_sum[row_start:row_stop, col_start:col_stop] += ratio
- ratio_value_weight[row_start:row_stop, col_start:col_stop] += 1
- ratio_painted_cells += 1
- ratio_state = {
- "value_sum": ratio_value_sum,
- "value_weight": ratio_value_weight,
- "painted_cells": ratio_painted_cells,
- "skipped_no_value": ratio_skipped_no_value,
+ target_value_sum = np.zeros((height, width), dtype=np.float32)
+ target_value_weight = np.zeros((height, width), dtype=np.uint16)
+ target_cells = 0
+ exclusion_counts = {
+ "invalid_fields": 0,
+ "mobile_weak_ratio": 0,
+ "competitor_total": 0,
+ "competitor_weak_ratio": 0,
+ "invalid_rsrp": 0,
}
- weak_cover_ratio_result = render_weak_cover_ratio_raster(
- ratio_state,
+ for cell in raster_cells:
+ competitor_total = cell[4]
+ competitor_rsrp = cell[5]
+ competitor_weak = cell[6]
+ mobile_total = cell[7]
+ mobile_weak = cell[8]
+ exclusion_reason = target_grid_filter_reason(
+ mobile_weak,
+ mobile_total,
+ competitor_weak,
+ competitor_total,
+ )
+ if exclusion_reason is not None:
+ exclusion_counts[exclusion_reason] += 1
+ continue
+ if competitor_rsrp is None or competitor_rsrp > 0:
+ exclusion_counts["invalid_rsrp"] += 1
+ continue
+ row_start, row_stop, col_start, col_stop = cell[:4]
+ target_value_sum[row_start:row_stop, col_start:col_stop] += competitor_rsrp
+ target_value_weight[row_start:row_stop, col_start:col_stop] += 1
+ target_cells += 1
+ target_state = {
+ "value_sum": target_value_sum,
+ "value_weight": target_value_weight,
+ "painted_cells": target_cells,
+ "skipped_no_value": sum(exclusion_counts.values()),
+ }
+ target_rsrp_result = render_target_rsrp_raster(
+ target_state,
market,
- weak_cover_ratio_path,
+ target_rsrp_path,
minx,
maxy,
pixel_width,
@@ -1582,81 +1420,23 @@ def export_market_grid_outputs(
height,
candidates,
)
- del ratio_state, ratio_value_sum, ratio_value_weight
-
- mobile_advantage_value_sum = np.zeros((height, width), dtype=np.float32)
- mobile_advantage_value_weight = np.zeros((height, width), dtype=np.uint16)
- mobile_advantage_cells = 0
- excluded_by_mobile_gate = 0
- excluded_without_total_users = 0
- included_without_weak_cover = 0
- included_with_weak_cover_bonus = 0
- missing_weak_cover_bonus = 0
- for cell in raster_cells:
- mobile_rsrp = cell[7]
- total_users = cell[5]
- weak_cover_users = cell[6]
- target_value = mobile_advantage_opportunity_score(mobile_rsrp, total_users, weak_cover_users)
- if target_value is None:
- if mobile_rsrp is None or mobile_rsrp <= MOBILE_ADVANTAGE_GOOD_RSRP_THRESHOLD:
- excluded_by_mobile_gate += 1
- else:
- excluded_without_total_users += 1
- continue
- if weak_cover_users is None:
- missing_weak_cover_bonus += 1
- included_without_weak_cover += 1
- elif weak_cover_users > 0:
- included_with_weak_cover_bonus += 1
- else:
- included_without_weak_cover += 1
- row_start, row_stop, col_start, col_stop = cell[:4]
- mobile_advantage_value_sum[row_start:row_stop, col_start:col_stop] += target_value
- mobile_advantage_value_weight[row_start:row_stop, col_start:col_stop] += 1
- mobile_advantage_cells += 1
- mobile_advantage_state = {
- "value_sum": mobile_advantage_value_sum,
- "value_weight": mobile_advantage_value_weight,
- "painted_cells": mobile_advantage_cells,
- "skipped_no_value": excluded_by_mobile_gate + excluded_without_total_users,
- }
- mobile_advantage_result = render_percentile_heatmap_raster(
- mobile_advantage_state,
- market,
- mobile_advantage_path,
- minx,
- maxy,
- pixel_width,
- pixel_height,
- width,
- height,
- candidates,
- MOBILE_ADVANTAGE_YELLOW_PERCENTILE,
- MOBILE_ADVANTAGE_SMOOTH_RADIUS,
- )
- mobile_advantage_result.update({
- "gate_field": MOBILE_RSRP_FIELD,
- "gate_operator": ">",
- "gate_threshold": MOBILE_ADVANTAGE_GOOD_RSRP_THRESHOLD,
- "score_formula": MOBILE_ADVANTAGE_SCORE_FORMULA,
- "value_fields": [EXCELLENT_CELL_FIELD, WEAK_COVER_FIELD],
- "zero_weak_cover_is_included": True,
- "eligible_cells": mobile_advantage_cells,
- "excluded_by_mobile_gate": excluded_by_mobile_gate,
- "excluded_without_total_users": excluded_without_total_users,
- "included_without_weak_cover": included_without_weak_cover,
- "included_with_weak_cover_bonus": included_with_weak_cover_bonus,
- "missing_weak_cover_bonus": missing_weak_cover_bonus,
+ target_rsrp_result.update({
+ "mobile_weak_ratio_formula": f"{MOBILE_WEAK_COVER_FIELD} / {MOBILE_TOTAL_FIELD} * 100",
+ "mobile_weak_ratio_operator": "<",
+ "mobile_weak_ratio_threshold": TARGET_MOBILE_WEAK_RATIO_MAX,
+ "competitor_total_field": EXCELLENT_CELL_FIELD,
+ "competitor_total_operator": ">",
+ "competitor_total_threshold": TARGET_COMPETITOR_TOTAL_MIN,
+ "competitor_weak_ratio_formula": f"{WEAK_COVER_FIELD} / {EXCELLENT_CELL_FIELD} * 100",
+ "competitor_weak_ratio_operator": ">",
+ "competitor_weak_ratio_threshold": TARGET_COMPETITOR_WEAK_RATIO_MIN,
+ "rsrp_field": RSRP_FIELD,
+ "eligible_cells": target_cells,
+ "exclusion_counts": exclusion_counts,
})
- del mobile_advantage_state, mobile_advantage_value_sum, mobile_advantage_value_weight
+ del target_state, target_value_sum, target_value_weight
- for result in (
- signal_result,
- user_count_result,
- weak_cover_result,
- weak_cover_ratio_result,
- mobile_advantage_result,
- ):
+ for result in (user_count_result, target_rsrp_result):
result["raster_extent"] = [
minx,
maxy - height * pixel_height,
@@ -1677,27 +1457,12 @@ def export_market_grid_outputs(
"skipped": csv_skipped,
}
return (
- signal_result,
user_count_result,
- weak_cover_result,
- weak_cover_ratio_result,
- mobile_advantage_result,
+ target_rsrp_result,
csv_result,
)
-def write_heatmap_legend(output_dir, field):
- legend_path = output_dir / "heatmap_legend.csv"
- with legend_path.open("w", newline="", encoding="utf-8-sig") as file:
- writer = csv.writer(file)
- writer.writerow(["field", "rsrp_anchor", "red", "green", "blue", "alpha", "meaning"])
- writer.writerow([field, f"<= {HEATMAP_BAD_RSRP}", *CONTINUOUS_HEATMAP_RED, HEATMAP_ALPHA, "bad signal red endpoint"])
- writer.writerow([field, HEATMAP_MID_RSRP, *CONTINUOUS_HEATMAP_YELLOW, HEATMAP_ALPHA, "continuous yellow anchor"])
- writer.writerow([field, f">= {HEATMAP_GOOD_RSRP}", *CONTINUOUS_HEATMAP_GREEN, HEATMAP_ALPHA, "good signal green endpoint"])
- writer.writerow([field, "nodata", 0, 0, 0, 0, "transparent no data"])
- return legend_path
-
-
def write_excellent_heatmap_legend(output_dir, field):
legend_path = output_dir / "excellent_heatmap_legend.csv"
with legend_path.open("w", newline="", encoding="utf-8-sig") as file:
@@ -1710,42 +1475,29 @@ def write_excellent_heatmap_legend(output_dir, field):
return legend_path
-def write_weak_cover_heatmap_legend(output_dir, field):
- legend_path = output_dir / "weak_cover_heatmap_legend.csv"
+def write_target_rsrp_legend(output_dir):
+ legend_path = output_dir / "target_rsrp_legend.csv"
with legend_path.open("w", newline="", encoding="utf-8-sig") as file:
writer = csv.writer(file)
- writer.writerow(["field", "percentile_anchor", "red", "green", "blue", "alpha", "meaning"])
- writer.writerow([field, "highest_value", *CONTINUOUS_HEATMAP_RED, HEATMAP_ALPHA, "most weak-cover users"])
- writer.writerow([field, f"percentile_{WEAK_COVER_YELLOW_PERCENTILE}", *CONTINUOUS_HEATMAP_YELLOW, HEATMAP_ALPHA, "continuous yellow anchor"])
- writer.writerow([field, "lowest_value", *CONTINUOUS_HEATMAP_GREEN, HEATMAP_ALPHA, "fewest weak-cover users"])
- writer.writerow([field, "nodata", 0, 0, 0, 0, "transparent no data"])
- return legend_path
-
-
-def write_weak_cover_ratio_legend(output_dir):
- legend_path = output_dir / "weak_cover_ratio_legend.csv"
- with legend_path.open("w", newline="", encoding="utf-8-sig") as file:
- writer = csv.writer(file)
- writer.writerow(["formula", "percentage_range", "red", "green", "blue", "alpha", "meaning"])
- formula = f"{WEAK_COVER_FIELD} / {EXCELLENT_CELL_FIELD} * 100"
- writer.writerow([formula, f"<= {WEAK_COVER_RATIO_GREEN_ANCHOR}%", *WEAK_COVER_RATIO_GREEN, HEATMAP_ALPHA, "green endpoint"])
- writer.writerow([formula, f"{WEAK_COVER_RATIO_BLUE_ANCHOR}%", *WEAK_COVER_RATIO_BLUE, HEATMAP_ALPHA, "blue anchor"])
- writer.writerow([formula, f"{WEAK_COVER_RATIO_YELLOW_ANCHOR}%", *WEAK_COVER_RATIO_YELLOW, HEATMAP_ALPHA, "yellow anchor"])
- writer.writerow([formula, f">= {WEAK_COVER_RATIO_RED_ANCHOR}%", *WEAK_COVER_RATIO_RED, HEATMAP_ALPHA, "red endpoint"])
- writer.writerow([formula, "no valid total", 0, 0, 0, 0, "transparent no data"])
- return legend_path
-
-
-def write_mobile_advantage_legend(output_dir):
- legend_path = output_dir / "mobile_advantage_legend.csv"
- with legend_path.open("w", newline="", encoding="utf-8-sig") as file:
- writer = csv.writer(file)
- writer.writerow(["gate", "score_formula", "percentile_anchor", "red", "green", "blue", "alpha", "meaning"])
- gate = f"{MOBILE_RSRP_FIELD} > {MOBILE_ADVANTAGE_GOOD_RSRP_THRESHOLD}"
- writer.writerow([gate, MOBILE_ADVANTAGE_SCORE_FORMULA, "highest_value", *CONTINUOUS_HEATMAP_RED, HEATMAP_ALPHA, "highest opportunity score"])
- writer.writerow([gate, MOBILE_ADVANTAGE_SCORE_FORMULA, f"percentile_{MOBILE_ADVANTAGE_YELLOW_PERCENTILE}", *CONTINUOUS_HEATMAP_YELLOW, HEATMAP_ALPHA, "continuous yellow anchor"])
- writer.writerow([gate, MOBILE_ADVANTAGE_SCORE_FORMULA, "lowest_positive_value", *CONTINUOUS_HEATMAP_GREEN, HEATMAP_ALPHA, "lowest positive opportunity score"])
- writer.writerow([gate, MOBILE_ADVANTAGE_SCORE_FORMULA, "gate_failed_or_no_users", 0, 0, 0, 0, "transparent non-target area"])
+ writer.writerow(["field", "rsrp_range", "red", "green", "blue", "alpha", "target_filter"])
+ target_filter = (
+ f"{MOBILE_WEAK_COVER_FIELD}/{MOBILE_TOTAL_FIELD} < {TARGET_MOBILE_WEAK_RATIO_MAX}%"
+ f" and {EXCELLENT_CELL_FIELD} > {TARGET_COMPETITOR_TOTAL_MIN}"
+ f" and {WEAK_COVER_FIELD}/{EXCELLENT_CELL_FIELD} > {TARGET_COMPETITOR_WEAK_RATIO_MIN}%"
+ )
+ ranges = (
+ "< -110",
+ "[-110, -104)",
+ "[-104, -98)",
+ "[-98, -92)",
+ "[-92, -86)",
+ "[-86, -80)",
+ "[-80, -74)",
+ "[-74, 0]",
+ )
+ for value_range, color in zip(ranges, TARGET_RSRP_COLORS):
+ writer.writerow([RSRP_FIELD, value_range, *color, HEATMAP_ALPHA, target_filter])
+ writer.writerow([RSRP_FIELD, "not_target_or_invalid", 0, 0, 0, 0, target_filter])
return legend_path
@@ -1809,19 +1561,13 @@ def process_market(market, pixel_width, pixel_height, output_dir):
market_dir = Path(temp_dir)
gis_project_path = market_dir / GIS_PROJECT_OUTPUT_FILENAME
- signal_path = market_dir / heatmap_raster_filename(RSRP_FIELD)
user_count_path = market_dir / excellent_heatmap_raster_filename(EXCELLENT_CELL_FIELD)
- weak_cover_path = market_dir / weak_cover_heatmap_raster_filename(WEAK_COVER_FIELD)
- weak_cover_ratio_path = market_dir / weak_cover_ratio_raster_filename()
- mobile_advantage_path = market_dir / mobile_advantage_raster_filename()
+ target_rsrp_path = market_dir / target_rsrp_raster_filename()
grid_metrics_path = market_dir / GRID_METRICS_CSV_FILENAME
grid_started_at = perf_counter()
(
- signal_result,
user_count_result,
- weak_cover_result,
- weak_cover_ratio_result,
- mobile_advantage_result,
+ target_rsrp_result,
grid_metrics_result,
) = export_market_grid_outputs(
grid_conn,
@@ -1830,11 +1576,8 @@ def process_market(market, pixel_width, pixel_height, output_dir):
market,
pixel_width,
pixel_height,
- signal_path,
user_count_path,
- weak_cover_path,
- weak_cover_ratio_path,
- mobile_advantage_path,
+ target_rsrp_path,
grid_metrics_path,
)
grid_elapsed = perf_counter() - grid_started_at
@@ -1853,7 +1596,7 @@ def process_market(market, pixel_width, pixel_height, output_dir):
gis_project_path,
market,
building_info_result["extent"],
- signal_result["raster_extent"],
+ target_rsrp_result["raster_extent"],
)
building_metrics_path = market_dir / BUILDING_METRICS_CSV_FILENAME
building_metrics_result = export_market_building_metrics_csv(
@@ -1877,11 +1620,8 @@ def process_market(market, pixel_width, pixel_height, output_dir):
"market_fid": market.fid,
"market_code": market.code,
"market_name": market.name,
- "heatmap_result": rewrite_result_for_zip(signal_result, zip_path, market_dir),
"excellent_heatmap_result": rewrite_result_for_zip(user_count_result, zip_path, market_dir),
- "weak_cover_heatmap_result": rewrite_result_for_zip(weak_cover_result, zip_path, market_dir),
- "weak_cover_ratio_result": rewrite_result_for_zip(weak_cover_ratio_result, zip_path, market_dir),
- "mobile_advantage_result": rewrite_result_for_zip(mobile_advantage_result, zip_path, market_dir),
+ "target_rsrp_result": rewrite_result_for_zip(target_rsrp_result, zip_path, market_dir),
"building_info_result": rewrite_result_for_zip(building_info_result, zip_path, market_dir),
"building_metrics_csv_result": rewrite_result_for_zip(building_metrics_result, zip_path, market_dir),
"grid_metrics_csv_result": rewrite_result_for_zip(grid_metrics_result, zip_path, market_dir),
@@ -1919,17 +1659,11 @@ def process_summary_grid_outputs(markets, pixel_width, pixel_height, output_dir)
grid_rtree = rtree_name(grid_conn, grid_layer)
with tempfile.TemporaryDirectory(prefix="market_grid_summary_") as temp_dir:
summary_dir = Path(temp_dir)
- signal_path = summary_dir / heatmap_raster_filename(RSRP_FIELD)
user_count_path = summary_dir / excellent_heatmap_raster_filename(EXCELLENT_CELL_FIELD)
- weak_cover_path = summary_dir / weak_cover_heatmap_raster_filename(WEAK_COVER_FIELD)
- weak_cover_ratio_path = summary_dir / weak_cover_ratio_raster_filename()
- mobile_advantage_path = summary_dir / mobile_advantage_raster_filename()
+ target_rsrp_path = summary_dir / target_rsrp_raster_filename()
(
- signal_result,
user_count_result,
- weak_cover_result,
- weak_cover_ratio_result,
- mobile_advantage_result,
+ target_rsrp_result,
_,
) = export_market_grid_outputs(
grid_conn,
@@ -1938,11 +1672,8 @@ def process_summary_grid_outputs(markets, pixel_width, pixel_height, output_dir)
summary_market,
pixel_width,
pixel_height,
- signal_path,
user_count_path,
- weak_cover_path,
- weak_cover_ratio_path,
- mobile_advantage_path,
+ target_rsrp_path,
None,
SUMMARY_MAX_RASTER_PIXELS,
)
@@ -1967,16 +1698,13 @@ def process_summary_grid_outputs(markets, pixel_width, pixel_height, output_dir)
gis_project_path,
summary_market,
building_info_extent,
- signal_result["raster_extent"],
+ target_rsrp_result["raster_extent"],
)
zip_result = write_market_zip(summary_dir, zip_path, summary_market)
return {
"market_code": summary_market.code,
- "heatmap_result": rewrite_result_for_zip(signal_result, zip_path, summary_dir),
"excellent_heatmap_result": rewrite_result_for_zip(user_count_result, zip_path, summary_dir),
- "weak_cover_heatmap_result": rewrite_result_for_zip(weak_cover_result, zip_path, summary_dir),
- "weak_cover_ratio_result": rewrite_result_for_zip(weak_cover_ratio_result, zip_path, summary_dir),
- "mobile_advantage_result": rewrite_result_for_zip(mobile_advantage_result, zip_path, summary_dir),
+ "target_rsrp_result": rewrite_result_for_zip(target_rsrp_result, zip_path, summary_dir),
"building_info_result": rewrite_result_for_zip(building_info_result, zip_path, summary_dir),
"gis_project_result": rewrite_result_for_zip(gis_project_result, zip_path, summary_dir),
"zip_result": zip_result,
@@ -1993,18 +1721,17 @@ def main():
raise ValueError("GEOMETRY_BATCH_SIZE 必须大于 0")
if PROJECT_EXTENT_PADDING_RATIO < 0:
raise ValueError("PROJECT_EXTENT_PADDING_RATIO 不能小于 0")
- if not HEATMAP_BAD_RSRP < HEATMAP_MID_RSRP < HEATMAP_GOOD_RSRP:
- raise ValueError("RSRP 热力图阈值必须满足 HEATMAP_BAD_RSRP < HEATMAP_MID_RSRP < HEATMAP_GOOD_RSRP")
- if not 0 < WEAK_COVER_YELLOW_PERCENTILE < 1:
- raise ValueError("WEAK_COVER_YELLOW_PERCENTILE 必须大于 0 且小于 1")
validate_smoothing_radius("HEATMAP_SMOOTH_RADIUS", HEATMAP_SMOOTH_RADIUS)
- if not math.isfinite(MOBILE_ADVANTAGE_GOOD_RSRP_THRESHOLD):
- raise ValueError("MOBILE_ADVANTAGE_GOOD_RSRP_THRESHOLD 必须是有限数值")
- if not 0 < MOBILE_ADVANTAGE_YELLOW_PERCENTILE < 1:
- raise ValueError("MOBILE_ADVANTAGE_YELLOW_PERCENTILE 必须大于 0 且小于 1")
- validate_smoothing_radius("MOBILE_ADVANTAGE_SMOOTH_RADIUS", MOBILE_ADVANTAGE_SMOOTH_RADIUS)
- if not 0 <= WEAK_COVER_RATIO_GREEN_ANCHOR < WEAK_COVER_RATIO_BLUE_ANCHOR < WEAK_COVER_RATIO_YELLOW_ANCHOR < WEAK_COVER_RATIO_RED_ANCHOR:
- raise ValueError("弱覆盖占比锚点必须满足 0 <= GREEN < BLUE < YELLOW < RED")
+ if not 0 <= TARGET_MOBILE_WEAK_RATIO_MAX <= 100:
+ raise ValueError("TARGET_MOBILE_WEAK_RATIO_MAX 必须在 0 到 100 之间")
+ if TARGET_COMPETITOR_TOTAL_MIN < 0 or not math.isfinite(TARGET_COMPETITOR_TOTAL_MIN):
+ raise ValueError("TARGET_COMPETITOR_TOTAL_MIN 必须是非负有限数值")
+ if not 0 <= TARGET_COMPETITOR_WEAK_RATIO_MIN <= 100:
+ raise ValueError("TARGET_COMPETITOR_WEAK_RATIO_MIN 必须在 0 到 100 之间")
+ if len(TARGET_RSRP_COLORS) != len(TARGET_RSRP_BREAKS) + 1:
+ raise ValueError("目标 RSRP 颜色数量必须比分界点数量多 1")
+ if any(left >= right for left, right in zip(TARGET_RSRP_BREAKS, TARGET_RSRP_BREAKS[1:])):
+ raise ValueError("TARGET_RSRP_BREAKS 必须严格递增")
if MAX_RASTER_PIXELS is not None and MAX_RASTER_PIXELS <= 0:
raise ValueError("MAX_RASTER_PIXELS 必须大于 0 或设置为 None")
if SUMMARY_MAX_RASTER_PIXELS is None or SUMMARY_MAX_RASTER_PIXELS <= 0:
@@ -2037,7 +1764,7 @@ def main():
require_columns(
grid_conn,
grid_layer.table_name,
- CSV_SOURCE_FIELDS,
+ (*CSV_SOURCE_FIELDS, MOBILE_TOTAL_FIELD, MOBILE_WEAK_COVER_FIELD),
)
require_columns(building_info_conn, building_info_layer.table_name, ["name"])
rtree_name(grid_conn, grid_layer)
@@ -2066,11 +1793,8 @@ def main():
"building_info": building_info_layer.table_name,
}
- heatmap_legend_path = write_heatmap_legend(OUTPUT_DIR, RSRP_FIELD)
excellent_legend_path = write_excellent_heatmap_legend(OUTPUT_DIR, EXCELLENT_CELL_FIELD)
- weak_cover_legend_path = write_weak_cover_heatmap_legend(OUTPUT_DIR, WEAK_COVER_FIELD)
- weak_cover_ratio_legend_path = write_weak_cover_ratio_legend(OUTPUT_DIR)
- mobile_advantage_legend_path = write_mobile_advantage_legend(OUTPUT_DIR)
+ target_rsrp_legend_path = write_target_rsrp_legend(OUTPUT_DIR)
worker_count = max(1, min(MAX_WORKERS, len(markets))) if markets else 1
print(f"市场网格数量:{len(markets)}")
print(f"并行进程数:{worker_count}")
@@ -2078,11 +1802,8 @@ def main():
print(f"Building 图层:{layer_names['building']}")
print(f"BuildingInfo 图层:{layer_names['building_info']}")
print(f"像元大小:{pixel_width}, {pixel_height}")
- print(f"热力图图例:{heatmap_legend_path}")
print(f"用户量图例:{excellent_legend_path}")
- print(f"信号差用户量图例:{weak_cover_legend_path}")
- print(f"弱覆盖占比图例:{weak_cover_ratio_legend_path}")
- print(f"移动优竟对弱用户分布图图例:{mobile_advantage_legend_path}")
+ print(f"目标栅格竟对 RSRP 图例:{target_rsrp_legend_path}")
started_at = perf_counter()
outcomes = []
@@ -2090,7 +1811,7 @@ def main():
for index, market in enumerate(markets, start=1):
outcome = process_market(market, pixel_width, pixel_height, OUTPUT_DIR)
outcomes.append(outcome)
- scale_factor = outcome.get("heatmap_result", {}).get("resolution_scale_factor", 1.0)
+ scale_factor = outcome.get("target_rsrp_result", {}).get("resolution_scale_factor", 1.0)
resolution_note = f",分辨率自动调整 x{scale_factor:.2f}" if scale_factor > 1.001 else ""
print(
f"[{index}/{len(markets)}] 完成 {market.code},"
@@ -2111,7 +1832,7 @@ def main():
raise RuntimeError(f"市场网格处理失败:{market.code}") from error
outcomes.append(outcome)
completed += 1
- scale_factor = outcome.get("heatmap_result", {}).get("resolution_scale_factor", 1.0)
+ scale_factor = outcome.get("target_rsrp_result", {}).get("resolution_scale_factor", 1.0)
resolution_note = f",分辨率自动调整 x{scale_factor:.2f}" if scale_factor > 1.001 else ""
print(
f"[{completed}/{len(markets)}] 完成 {market.code},"
@@ -2128,11 +1849,8 @@ def main():
f"耗时 {summary_grid_result['elapsed_seconds']:.1f} 秒"
)
result_mappings = {
- "heatmap_results": "heatmap_result",
"excellent_heatmap_results": "excellent_heatmap_result",
- "weak_cover_heatmap_results": "weak_cover_heatmap_result",
- "weak_cover_ratio_results": "weak_cover_ratio_result",
- "mobile_advantage_results": "mobile_advantage_result",
+ "target_rsrp_results": "target_rsrp_result",
"building_info_results": "building_info_result",
"building_metrics_csv_results": "building_metrics_csv_result",
"grid_metrics_csv_results": "grid_metrics_csv_result",
@@ -2148,11 +1866,13 @@ def main():
"rsrp_field": RSRP_FIELD,
"excellent_cell_field": EXCELLENT_CELL_FIELD,
"weak_cover_field": WEAK_COVER_FIELD,
- "mobile_rsrp_field": MOBILE_RSRP_FIELD,
- "mobile_advantage_gate": f"{MOBILE_RSRP_FIELD} > {MOBILE_ADVANTAGE_GOOD_RSRP_THRESHOLD}",
- "mobile_advantage_score_formula": MOBILE_ADVANTAGE_SCORE_FORMULA,
- "mobile_advantage_smooth_radius": MOBILE_ADVANTAGE_SMOOTH_RADIUS,
- "weak_cover_ratio_formula": f"{WEAK_COVER_FIELD} / {EXCELLENT_CELL_FIELD} * 100",
+ "mobile_total_field": MOBILE_TOTAL_FIELD,
+ "mobile_weak_cover_field": MOBILE_WEAK_COVER_FIELD,
+ "target_mobile_weak_ratio_formula": f"{MOBILE_WEAK_COVER_FIELD} / {MOBILE_TOTAL_FIELD} * 100",
+ "target_mobile_weak_ratio_rule": f"< {TARGET_MOBILE_WEAK_RATIO_MAX}",
+ "target_competitor_total_rule": f"{EXCELLENT_CELL_FIELD} > {TARGET_COMPETITOR_TOTAL_MIN}",
+ "target_competitor_weak_ratio_formula": f"{WEAK_COVER_FIELD} / {EXCELLENT_CELL_FIELD} * 100",
+ "target_competitor_weak_ratio_rule": f"> {TARGET_COMPETITOR_WEAK_RATIO_MIN}",
"clip_mode": CLIP_MODE,
"scale": SCALE,
"pixel_width": pixel_width,
diff --git a/source/MapPark/GIS.qgz b/source/MapPark/GIS.qgz
index 7894339..0a808b7 100644
Binary files a/source/MapPark/GIS.qgz and b/source/MapPark/GIS.qgz differ
diff --git a/tests/test_main.py b/tests/test_main.py
index b8edf61..706bfdd 100644
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -18,23 +18,6 @@ class SignalRulesTest(unittest.TestCase):
self.assertEqual(main.signal_level(-95), "一般")
self.assertEqual(main.signal_level(-94.9), "正常")
- def test_signal_raster_colors(self):
- values = np.array([[-110.0, -105.0, -100.0, -95.0, -87.5, -80.0, -70.0]], dtype=np.float32)
- colors = main.heatmap_rgb_for_values(values)
- self.assertEqual(
- colors.tolist(),
- [[
- [255, 0, 0],
- [255, 0, 0],
- [255, 128, 0],
- [255, 255, 0],
- [128, 216, 40],
- [0, 176, 80],
- [0, 176, 80],
- ]],
- )
-
-
class RankedHeatmapTest(unittest.TestCase):
def test_equal_values_are_not_split_between_colors(self):
values = np.array([[10.0, 0.0, 0.0], [0.0, 0.0, 0.0]], dtype=np.float32)
@@ -58,50 +41,46 @@ class RankedHeatmapTest(unittest.TestCase):
main.ranked_pixel_rgb_for_values(values, mask, ((255, 0, 0),), (0.5,))
-class ContinuousHeatmapTest(unittest.TestCase):
- def test_percentile_heatmap_is_continuous_and_preserves_ties(self):
- values = np.array([[0.0, 0.0, 5.0, 10.0, 20.0]], dtype=np.float32)
- mask = np.ones(values.shape, dtype=bool)
- anchor_scores = (0.0, main.WEAK_COVER_YELLOW_PERCENTILE, 1.0)
- scores, anchors = main.percentile_scores_for_values(values, mask, anchor_scores)
- colors = main.continuous_heatmap_rgb_for_scores(scores, main.WEAK_COVER_YELLOW_PERCENTILE)
+class TargetGridRsrpTest(unittest.TestCase):
+ def test_target_grid_requires_all_three_strict_conditions(self):
+ self.assertTrue(main.target_grid_is_eligible(199.0, 1000.0, 201.0, 1001.0))
+ self.assertFalse(main.target_grid_is_eligible(200.0, 1000.0, 201.0, 1001.0))
+ self.assertFalse(main.target_grid_is_eligible(199.0, 1000.0, 300.0, 1000.0))
+ self.assertFalse(main.target_grid_is_eligible(199.0, 1000.0, 200.0, 1001.0))
- self.assertEqual(anchors, [0.0, 10.0, 20.0])
- self.assertEqual(colors[0, 0].tolist(), list(main.CONTINUOUS_HEATMAP_GREEN))
- self.assertEqual(colors[0, 0].tolist(), colors[0, 1].tolist())
- self.assertNotIn(colors[0, 2].tolist(), [
- list(main.CONTINUOUS_HEATMAP_GREEN),
- list(main.CONTINUOUS_HEATMAP_YELLOW),
- list(main.CONTINUOUS_HEATMAP_RED),
- ])
- self.assertEqual(colors[0, 4].tolist(), list(main.CONTINUOUS_HEATMAP_RED))
+ def test_target_grid_rejects_invalid_ratio_fields(self):
+ invalid_cases = (
+ (None, 1000.0, 201.0, 1001.0),
+ (1.0, 0.0, 201.0, 1001.0),
+ (-1.0, 1000.0, 201.0, 1001.0),
+ (199.0, 1000.0, None, 1001.0),
+ (199.0, 1000.0, -1.0, 1001.0),
+ )
+ for values in invalid_cases:
+ with self.subTest(values=values):
+ self.assertEqual(main.target_grid_filter_reason(*values), "invalid_fields")
- def test_single_value_percentile_heatmap_uses_yellow_anchor(self):
- values = np.full((2, 2), 7.0, dtype=np.float32)
- mask = np.ones(values.shape, dtype=bool)
- anchor_scores = (0.0, main.WEAK_COVER_YELLOW_PERCENTILE, 1.0)
- scores, anchors = main.percentile_scores_for_values(values, mask, anchor_scores)
- colors = main.continuous_heatmap_rgb_for_scores(scores, main.WEAK_COVER_YELLOW_PERCENTILE)
-
- self.assertEqual(anchors, [7.0, 7.0, 7.0])
- self.assertTrue(np.all(colors == main.CONTINUOUS_HEATMAP_YELLOW))
-
-
-class MobileOpportunityHeatmapTest(unittest.TestCase):
- def test_opportunity_requires_good_mobile_signal_and_total_users(self):
- self.assertIsNone(main.mobile_advantage_opportunity_score(None, 100.0, 10.0))
- self.assertIsNone(main.mobile_advantage_opportunity_score(-95.0, 100.0, 10.0))
- self.assertIsNone(main.mobile_advantage_opportunity_score(-94.9, None, 10.0))
- self.assertIsNone(main.mobile_advantage_opportunity_score(-94.9, 0.0, 10.0))
-
- def test_opportunity_includes_good_competitor_and_rewards_weak_users(self):
- self.assertEqual(main.mobile_advantage_opportunity_score(-94.9, 100.0, None), 100.0)
- self.assertEqual(main.mobile_advantage_opportunity_score(-94.9, 100.0, 0.0), 100.0)
- self.assertEqual(main.mobile_advantage_opportunity_score(-94.9, 100.0, -1.0), 100.0)
- self.assertEqual(main.mobile_advantage_opportunity_score(-94.9, 100.0, 20.0), 120.0)
-
- def test_target_heatmap_uses_independent_smoothing_radius(self):
- self.assertEqual(main.MOBILE_ADVANTAGE_SMOOTH_RADIUS, 5)
+ def test_target_rsrp_uses_eight_discrete_color_classes(self):
+ values = np.array(
+ [[-200.0, -110.1, -110.0, -104.0, -98.0, -92.0, -86.0, -80.0, -74.0, 0.0, 0.1, np.nan]],
+ dtype=np.float32,
+ )
+ colors, valid_mask = main.target_rsrp_rgb_for_values(values)
+ expected_colors = [
+ main.TARGET_RSRP_COLORS[0],
+ main.TARGET_RSRP_COLORS[0],
+ main.TARGET_RSRP_COLORS[1],
+ main.TARGET_RSRP_COLORS[2],
+ main.TARGET_RSRP_COLORS[3],
+ main.TARGET_RSRP_COLORS[4],
+ main.TARGET_RSRP_COLORS[5],
+ main.TARGET_RSRP_COLORS[6],
+ main.TARGET_RSRP_COLORS[7],
+ main.TARGET_RSRP_COLORS[7],
+ ]
+ self.assertEqual(colors[0, :10].tolist(), [list(color) for color in expected_colors])
+ self.assertEqual(valid_mask.tolist(), [[True] * 10 + [False, False]])
+ self.assertEqual(colors[0, 10:].tolist(), [[0, 0, 0], [0, 0, 0]])
def test_smoothing_radius_must_be_a_nonnegative_integer(self):
main.validate_smoothing_radius("radius", 0)
@@ -112,24 +91,6 @@ class MobileOpportunityHeatmapTest(unittest.TestCase):
main.validate_smoothing_radius("radius", value)
-class WeakCoverRatioTest(unittest.TestCase):
- def test_continuous_percentage_color_anchors(self):
- values = np.array([[0.0, 2.5, 5.0, 7.5, 10.0, 15.0, 20.0, 100.0]], dtype=np.float32)
- colors = main.weak_cover_ratio_rgb_for_values(values)
- self.assertEqual(colors[0, 0].tolist(), list(main.WEAK_COVER_RATIO_GREEN))
- self.assertEqual(colors[0, 2].tolist(), list(main.WEAK_COVER_RATIO_BLUE))
- self.assertEqual(colors[0, 4].tolist(), list(main.WEAK_COVER_RATIO_YELLOW))
- self.assertEqual(colors[0, 6].tolist(), list(main.WEAK_COVER_RATIO_RED))
- self.assertEqual(colors[0, 7].tolist(), list(main.WEAK_COVER_RATIO_RED))
- for index in (1, 3, 5):
- self.assertNotIn(colors[0, index].tolist(), [
- list(main.WEAK_COVER_RATIO_GREEN),
- list(main.WEAK_COVER_RATIO_BLUE),
- list(main.WEAK_COVER_RATIO_YELLOW),
- list(main.WEAK_COVER_RATIO_RED),
- ])
-
-
class SpatialNameIndexTest(unittest.TestCase):
def test_largest_intersection_wins(self):
geometries = [box(0, 0, 1, 1), box(0, 0, 2, 2)]
@@ -231,8 +192,8 @@ class QgisProjectTest(unittest.TestCase):
100100200200
BuildingInfo./BuildingInfo.gpkg|layername=BuildingInfo0011
- 弱覆盖占比./弱覆盖占比.tif100100200200100100200200
- 移动优竟对弱用户分布图./移动优竟对弱用户分布图.tif100100200200100100200200
+ 用户量./用户量.tif100100200200100100200200
+ 目标栅格竟对RSRP./目标栅格竟对RSRP.tif100100200200100100200200
'''
with tempfile.TemporaryDirectory() as temp_dir:
@@ -264,28 +225,28 @@ class QgisProjectTest(unittest.TestCase):
canvas = project.find(".//mapcanvas[@name='theMapCanvas']/extent")
overview = project.find(".//mapcanvas[@name='mAreaCanvas']/extent")
building_layer = project.find(".//projectlayers/maplayer/extent")
- ratio_layer = next(
+ user_count_layer = next(
layer
for layer in project.findall(".//projectlayers/maplayer")
- if layer.findtext("datasource") == "./弱覆盖占比.tif"
+ if layer.findtext("datasource") == f"./{main.USER_COUNT_OUTPUT_FILENAME}"
)
- mobile_advantage_layer = next(
+ target_rsrp_layer = next(
layer
for layer in project.findall(".//projectlayers/maplayer")
- if layer.findtext("datasource") == f"./{main.MOBILE_ADVANTAGE_OUTPUT_FILENAME}"
+ if layer.findtext("datasource") == f"./{main.TARGET_RSRP_OUTPUT_FILENAME}"
)
self.assertEqual(read_extent(canvas), (9, 19, 31, 41))
self.assertEqual(read_extent(overview), (100, 100, 200, 200))
self.assertEqual(read_extent(building_layer), (10, 20, 30, 40))
- self.assertEqual(read_extent(ratio_layer.find("extent")), (0, -1, 2, 1))
- self.assertEqual(read_extent(ratio_layer.find("wgs84extent")), (0, -1, 2, 1))
- self.assertEqual(read_extent(mobile_advantage_layer.find("extent")), (0, -1, 2, 1))
- self.assertEqual(read_extent(mobile_advantage_layer.find("wgs84extent")), (0, -1, 2, 1))
+ self.assertEqual(read_extent(user_count_layer.find("extent")), (0, -1, 2, 1))
+ self.assertEqual(read_extent(user_count_layer.find("wgs84extent")), (0, -1, 2, 1))
+ self.assertEqual(read_extent(target_rsrp_layer.find("extent")), (0, -1, 2, 1))
+ self.assertEqual(read_extent(target_rsrp_layer.find("wgs84extent")), (0, -1, 2, 1))
self.assertEqual(result["extent_source"], "building_info")
self.assertEqual(result["raster_extent"], [0, -1, 2, 1])
self.assertEqual(result["canvas_extent"], [9.0, 19.0, 31.0, 41.0])
- def test_repository_template_contains_mobile_advantage_layer(self):
+ def test_repository_template_contains_only_two_thematic_rasters(self):
with zipfile.ZipFile(main.GIS_PROJECT_SOURCE) as archive:
self.assertIsNone(archive.testzip())
qgs_members = [name for name in archive.namelist() if name.lower().endswith(".qgs")]
@@ -295,9 +256,9 @@ class QgisProjectTest(unittest.TestCase):
layer = next(
item
for item in project.findall(".//projectlayers/maplayer")
- if item.findtext("layername") == Path(main.MOBILE_ADVANTAGE_OUTPUT_FILENAME).stem
+ if item.findtext("layername") == Path(main.TARGET_RSRP_OUTPUT_FILENAME).stem
)
- self.assertEqual(layer.findtext("datasource"), f"./{main.MOBILE_ADVANTAGE_OUTPUT_FILENAME}")
+ self.assertEqual(layer.findtext("datasource"), f"./{main.TARGET_RSRP_OUTPUT_FILENAME}")
layer_id = layer.findtext("id")
tree_layer = next(
item
@@ -305,14 +266,17 @@ class QgisProjectTest(unittest.TestCase):
if item.get("id") == layer_id
)
self.assertEqual(tree_layer.get("checked"), "Qt::Checked")
- other_raster_names = {"信号", "用户量", "信号差用户量", "弱覆盖占比"}
- other_raster_layers = [
+ raster_tree_layers = [
item
for item in project.iter("layer-tree-layer")
- if item.get("name") in other_raster_names
+ if (item.get("source") or "").lower().endswith(".tif")
]
- self.assertEqual(len(other_raster_layers), len(other_raster_names))
- self.assertTrue(all(item.get("checked") == "Qt::Unchecked" for item in other_raster_layers))
+ self.assertEqual(
+ {item.get("name") for item in raster_tree_layers},
+ {"用户量", Path(main.TARGET_RSRP_OUTPUT_FILENAME).stem},
+ )
+ user_count_tree = next(item for item in raster_tree_layers if item.get("name") == "用户量")
+ self.assertEqual(user_count_tree.get("checked"), "Qt::Unchecked")
if __name__ == "__main__":