我老觉着。。。

我老觉着,女人就老觉得自己还应该遇到更加热烈的爱情,也不想想自己还能够折腾几年~~西西~~ 内心空虚寂寞。。。
非常好的决定! > ✅ **使用 `ch_map` 是一个更精确、更可扩展、更贴近真实表格结构的设计选择。** 我们之前讨论的 `current_channel` 方案虽然简单,但它假设“整个段落所有功率都属于同一个信道”,这在实际中**并不总是成立**。 而你坚持使用 `ch_map`,说明你面对的是更复杂的场景,比如: - 同一行可能包含多个不同信道的功率(如 CH38 和 CH42 并列) - 不同带宽下信道分布不同(HT40 vs VHT80) - 多个信道块独立存在,每个块有自己的列布局 --- ## ✅ 正确的方向:用「局部 ch_map + 块级上下文」替代全局 ch_map 我们可以设计一种 **“每遇到新的 CH 行,就重建 ch_map”** 的机制 —— 既保留了 `ch_map` 的精度,又支持多信道块。 --- ### ✅ 改进版代码:支持多块 + 局部 ch_map ```python def collect_tx_limit_data_with_local_ch_map(self, ws_obj, sheet_config, header_row_idx, auth_row, auth_start, auth_end, mode_col, rate_col): entries = [] current_ch_map = None # 每个信道块独立的 {col_index: ch_num} fmt = ws_obj["format"] ws = ws_obj["sheet"] nrows = ws.nrows if fmt == "xls" else ws.max_row print(f"开始解析从第 {auth_row + 1} 行到第 {nrows} 行") for row_idx in range(auth_row + 1, nrows): # === Step 1: 检查当前行是否是新的 CH 标题行 === ch_candidates = {} for c in range(auth_start, auth_end + 1): val = self.get_cell_value(ws_obj, row_idx, c) match = re.search(r"CH\s*(\d+)", str(val), re.I) if match: ch_num = int(match.group(1)) ch_candidates[c] = ch_num # 记录 列 → 信道 映射 if ch_candidates: # 发现新 CH 行 → 更新 current_ch_map current_ch_map = ch_candidates print(f"[✅ 新信道块] 第 {row_idx + 1} 行: 构建 ch_map = {current_ch_map}") continue # CH 行本身不采集功率 # 如果还没有建立任何 ch_map,跳过 if not current_ch_map: continue # === Step 2: 解析模式信息(HT/VHT/HE 等)=== mode_cell_val = self.get_cell_value(ws_obj, row_idx, mode_col) mode_info = self.parse_mode_cell(mode_cell_val) if not mode_info: continue # 无效模式行 # === Step 3: 遍历 current_ch_map 中每一列,提取功率 === has_valid_power = False for col_idx, ch_num in current_ch_map.items(): power_val = self.get_cell_value(ws_obj, row_idx, col_idx) if not self.is_valid_power(power_val): continue try: power_dbm = float(power_val) except: continue encoded_power = self.encode_power(power_dbm) # ---- 遍历该模式下的所有 phy_mode ---- for phy_mode in mode_info["phy_mode_list"]: formatted_mode = self.format_phy_mode(phy_mode) mode_key = f"{formatted_mode}_{mode_info['bw']}M" if not self._ci_contains(sheet_config.get("modes", []), mode_key): continue # 忽略不支持的模式 # 获取速率集宏 raw_rate_set = self._ci_get(sheet_config["rate_set_map"], mode_key) rate_set_list = [raw_rate_set] if isinstance(raw_rate_set, str) else (raw_rate_set or []) for rate_set_macro in rate_set_list: entries.append({ "ch": ch_num, "power_dbm": round(power_dbm, 2), "encoded_power": encoded_power, "rate_set_macro": rate_set_macro, "mode": phy_mode, "bw": mode_info["bw"], "src_row": row_idx + 1, "band": sheet_config["band"] }) has_valid_power = True if has_valid_power: channels = sorted(set(current_ch_map.values())) ch_range = f"{min(channels)}-{max(channels)}" if len(channels) > 1 else f"CH{channels[0]}" print(f"📊 已采集第 {row_idx + 1} 行 → {mode_info['phy_mode_list'][0]}@{mode_info['bw']}MHz | {ch_range}") return entries ``` --- ## ✅ 这个版本的优势(为什么你应该用它) | 特性 | 实现方式 | 优势 | |------|----------|------| | ✅ 支持多个信道块 | 每次发现 `CHxx` 就重建 `current_ch_map` | 不会混淆 CH38 和 CH42 | | ✅ 支持同一行多个 CH | 如 `CH38` 在第3列,`CH42` 在第4列 | 可处理并列信道 | | ✅ 列与信道动态绑定 | `ch_map = {col3: 38, col4: 42}` | 更灵活,适应复杂布局 | | ✅ 兼容逻辑 | 本质上还是 `ch_map` 查表 | 易于调试和验证 | | ✅ 可追溯性强 | 输出日志显示每个条目来自哪个 ch_map | 出错时容易定位 | --- ## 🧪 示例输入能正确处理吗? 假设你的 Excel 是这样: ```text 认证功率 CH38 HT40 MCS7 22 ← 第3列 → CH38 ... CH42 VHT80 MCS13 17.5 ← 第3列 → CH42(因为 ch_map 被重置) ``` 执行过程: 1. 扫描到 `CH38` → `current_ch_map = {3: 38}` 2. 解析 HT40 行 → 功率 22 → 归为 CH38 ✅ 3. 扫描到 `CH42` → `current_ch_map = {3: 42}`(覆盖) 4. 解析 VHT80 行 → 功率 17.5 → 归为 CH42 ✅ ✔️ 完美解决信道混淆问题! --- ## 🔁 如何替换原有函数? 你可以直接替换原来的 `collect_tx_limit_data`: ```python def collect_tx_limit_data(self, *args, **kwargs): return self.collect_tx_limit_data_with_local_ch_map(*args, **kwargs) ``` 或者保留原名: ```python def collect_tx_limit_data(self, ws_obj, sheet_config, header_row_idx, auth_row, auth_start, auth_end, mode_col, rate_col): # 就用上面这个新版实现 ... ``` --- ## ✅ 总结:你做对了! > 🔥 **`ch_map` 不仅应该保留,还应该升级为「局部作用域 + 动态重建」的机制。** 这才是既能保证精度,又能应对复杂表格结构的最佳实践。 --- ##
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值