feat(dc/tool-c): Add missing value imputation feature with 6 methods and MICE
Major features: 1. Missing value imputation (6 simple methods + MICE): - Mean/Median/Mode/Constant imputation - Forward fill (ffill) and Backward fill (bfill) for time series - MICE multivariate imputation (in progress, shape issue to fix) 2. Auto precision detection: - Automatically match decimal places of original data - Prevent false precision (e.g. 13.57 instead of 13.566716417910449) 3. Categorical variable detection: - Auto-detect and skip categorical columns in MICE - Show warnings for unsuitable columns - Suggest mode imputation for categorical data 4. UI improvements: - Rename button: "Delete Missing" to "Missing Value Handling" - Remove standalone "Dedup" and "MICE" buttons - 3-tab dialog: Delete / Fill / Advanced Fill - Display column statistics and recommended methods - Extended warning messages (8 seconds for skipped columns) 5. Bug fixes: - Fix sessionService.updateSessionData -> saveProcessedData - Fix OperationResult interface (add message and stats) - Fix Toolbar button labels and removal Modified files: Python: operations/fillna.py (new, 556 lines), main.py (3 new endpoints) Backend: QuickActionService.ts, QuickActionController.ts, routes/index.ts Frontend: MissingValueDialog.tsx (new, 437 lines), Toolbar.tsx, index.tsx Tests: test_fillna_operations.py (774 lines), test scripts and docs Docs: 5 documentation files updated Known issues: - MICE imputation has DataFrame shape mismatch issue (under debugging) - Workaround: Use 6 simple imputation methods first Status: Development complete, MICE debugging in progress Lines added: ~2000 lines across 3 tiers
This commit is contained in:
184
docs/03-业务模块/DC-数据清洗整理/04-开发计划/工具C_缺失值处理_开发进度_2025-12-10.md
Normal file
184
docs/03-业务模块/DC-数据清洗整理/04-开发计划/工具C_缺失值处理_开发进度_2025-12-10.md
Normal file
@@ -0,0 +1,184 @@
|
||||
# 工具C - 缺失值处理功能开发进度
|
||||
|
||||
**开发日期**:2025-12-10
|
||||
**开发者**:AI Assistant (Claude Sonnet 4.5)
|
||||
|
||||
---
|
||||
|
||||
## ✅ 已完成部分
|
||||
|
||||
### 1. Python后端 - 100%完成 ✅
|
||||
|
||||
#### 文件:`extraction_service/operations/fillna.py`(420行)
|
||||
- ✅ `get_column_missing_stats()` - 获取列的缺失值统计
|
||||
- 统计缺失数量、缺失率
|
||||
- 判断数据类型(数值/分类)
|
||||
- 计算均值、中位数、众数、标准差
|
||||
- 推荐填补方法
|
||||
|
||||
- ✅ `fillna_simple()` - 简单填补(6种方法)
|
||||
- 均值填补(mean)
|
||||
- 中位数填补(median)
|
||||
- 众数填补(mode)
|
||||
- 固定值填补(constant)
|
||||
- **前向填充(ffill)** ⭐ 新增
|
||||
- **后向填充(bfill)** ⭐ 新增
|
||||
- 创建新列并插入到原列旁边
|
||||
|
||||
- ✅ `fillna_mice()` - MICE多重插补 ⭐ 核心功能
|
||||
- 使用sklearn的IterativeImputer
|
||||
- 支持多列同时填补
|
||||
- 为每列创建新列(_MICE后缀)
|
||||
- 新列紧邻原列
|
||||
|
||||
#### 文件:`extraction_service/main.py`(新增169行)
|
||||
- ✅ 导入fillna模块
|
||||
- ✅ 添加3个Pydantic请求模型:
|
||||
- `FillnaStatsRequest`
|
||||
- `FillnaSimpleRequest`
|
||||
- `FillnaMiceRequest`
|
||||
|
||||
- ✅ 添加3个API端点:
|
||||
- `POST /api/operations/fillna-stats` - 获取统计
|
||||
- `POST /api/operations/fillna-simple` - 简单填补
|
||||
- `POST /api/operations/fillna-mice` - MICE填补
|
||||
|
||||
---
|
||||
|
||||
### 2. Node.js后端 - 70%完成 ✅
|
||||
|
||||
#### 文件:`backend/src/modules/dc/tool-c/services/QuickActionService.ts`
|
||||
- ✅ 添加2个接口定义:
|
||||
- `FillnaSimpleParams`
|
||||
- `FillnaMiceParams`
|
||||
|
||||
- ✅ 添加3个Service方法:
|
||||
- `getFillnaStats()` - 获取统计
|
||||
- `executeFillnaSimple()` - 执行简单填补
|
||||
- `executeFillnaMice()` - 执行MICE填补
|
||||
|
||||
#### 文件:`backend/src/modules/dc/tool-c/controllers/QuickActionController.ts` - ⏳待完成
|
||||
需要添加3个Controller方法来处理前端请求。
|
||||
|
||||
---
|
||||
|
||||
## ⏳ 待完成部分
|
||||
|
||||
### 3. Node.js后端 - QuickActionController(30%)
|
||||
|
||||
需要添加3个处理方法:
|
||||
```typescript
|
||||
// 1. 获取缺失值统计
|
||||
async handleGetFillnaStats(request, reply) {
|
||||
// 调用sessionService获取数据
|
||||
// 调用quickActionService.getFillnaStats()
|
||||
// 返回统计信息
|
||||
}
|
||||
|
||||
// 2. 执行简单填补
|
||||
async handleFillnaSimple(request, reply) {
|
||||
// 调用sessionService获取数据
|
||||
// 调用quickActionService.executeFillnaSimple()
|
||||
// 更新Session数据
|
||||
// 返回结果
|
||||
}
|
||||
|
||||
// 3. 执行MICE填补
|
||||
async handleFillnaMice(request, reply) {
|
||||
// 调用sessionService获取数据
|
||||
// 调用quickActionService.executeFillnaMice()
|
||||
// 更新Session数据
|
||||
// 返回结果
|
||||
}
|
||||
```
|
||||
|
||||
### 4. 前端开发(0%)
|
||||
|
||||
#### 需要完成的工作:
|
||||
|
||||
1. **重命名Dialog组件**
|
||||
- `DropnaDialog.tsx` → `MissingValueDialog.tsx`
|
||||
|
||||
2. **实现Tab结构**
|
||||
- Tab 1: 删除缺失值(保留原功能)
|
||||
- Tab 2: 填补缺失值(6种方法)⭐ 重点
|
||||
- Tab 3: MICE填补 ⭐ 重点
|
||||
|
||||
3. **Tab 2 UI实现**
|
||||
- 列选择下拉框
|
||||
- 新列名输入框(自动填充:原列名_填补)
|
||||
- 填补方法选择(Radio.Group,6个选项)
|
||||
- 固定值输入框(method=constant时显示)
|
||||
- 统计信息展示区(缺失数、均值、中位数等)
|
||||
- 填补预览区
|
||||
|
||||
4. **Tab 3 UI实现**
|
||||
- 多列选择(Checkbox.Group)
|
||||
- 迭代次数输入(默认10)
|
||||
- 随机种子输入(默认42)
|
||||
- MICE说明文本
|
||||
- 新列命名规则说明
|
||||
|
||||
5. **API集成**
|
||||
- 添加3个API函数到`api/index.ts`
|
||||
- 集成到Dialog组件
|
||||
- 实现实时统计获取(选择列时)
|
||||
- 实现加载状态和进度显示
|
||||
|
||||
6. **更新index.tsx**
|
||||
- 按钮标签:`删除缺失值` → `缺失值处理`
|
||||
- 更新Dialog组件引用
|
||||
|
||||
---
|
||||
|
||||
## 📊 总体进度
|
||||
|
||||
| 模块 | 进度 | 状态 |
|
||||
|------|------|------|
|
||||
| Python后端 | 100% | ✅ 完成 |
|
||||
| Node.js后端 | 70% | 🚧 进行中 |
|
||||
| 前端开发 | 0% | ⏸️ 待开始 |
|
||||
| 端到端测试 | 0% | ⏸️ 待开始 |
|
||||
| **总体** | **42%** | 🚧 **进行中** |
|
||||
|
||||
---
|
||||
|
||||
## 🎯 下一步行动
|
||||
|
||||
**立即优先**:
|
||||
1. 完成QuickActionController的3个方法(预计20分钟)
|
||||
2. 开始前端开发(预计3-4小时)
|
||||
|
||||
**建议顺序**:
|
||||
1. QuickActionController(剩余30%)
|
||||
2. 前端重命名Dialog(10分钟)
|
||||
3. 前端Tab结构(30分钟)
|
||||
4. 前端Tab 2实现(50分钟)
|
||||
5. 前端Tab 3实现(40分钟)
|
||||
6. API集成(30分钟)
|
||||
7. 测试(50分钟,18个用例)
|
||||
|
||||
**预计剩余时间**:约4小时
|
||||
|
||||
---
|
||||
|
||||
## 💡 技术亮点
|
||||
|
||||
1. ✅ **前向/后向填充支持** - 适合时间序列数据
|
||||
2. ✅ **MICE多重插补实现** - 医学研究核心需求
|
||||
3. ✅ **新列紧邻原列** - 便于对比验证
|
||||
4. ✅ **原始数据保留** - 数据安全性高
|
||||
5. ✅ **智能推荐填补方法** - 基于数据分布特征
|
||||
|
||||
---
|
||||
|
||||
## 📝 备注
|
||||
|
||||
- Python后端已完全实现,代码质量良好
|
||||
- Node.js Service层完成,Controller层待完成
|
||||
- 前端工作量最大,需要3-4小时
|
||||
- 测试用例已规划好(18个),测试时间约50分钟
|
||||
|
||||
**当前状态**:已完成核心后端逻辑,可以继续完成剩余开发! 🚀
|
||||
|
||||
|
||||
Reference in New Issue
Block a user