feat(dc): Add multi-metric transformation feature (direction 1+2)

Summary:
- Implement intelligent multi-metric grouping detection algorithm
- Add direction 1: timepoint-as-row, metric-as-column (analysis format)
- Add direction 2: timepoint-as-column, metric-as-row (display format)
- Fix column name pattern detection (FMA___ issue)
- Maintain original Record ID order in output
- Add full-select/clear buttons in UI
- Integrate into TransformDialog with Radio selection
- Update 3 documentation files

Technical Details:
- Python: detect_metric_groups(), apply_multi_metric_to_long(), apply_multi_metric_to_matrix()
- Backend: 3 new methods in QuickActionService
- Frontend: MultiMetricPanel.tsx (531 lines)
- Total: ~1460 lines of new code

Status: Fully tested and verified, ready for production
This commit is contained in:
2025-12-21 15:06:15 +08:00
parent 8be8cdcf53
commit 9b81aef9a7
123 changed files with 4781 additions and 150 deletions

View File

@@ -106,7 +106,7 @@ npm run build
#### 阿里云资源
- [ ] **后端服务SAE** 已部署并运行
- 后端 VPC 内网地址已获取(如 `http://172.16.0.30:3001`
- 后端 VPC 内网地址已获取(如 `http://172.17.x.x:3001`
- 后端健康检查可访问
- [ ] **阿里云容器镜像服务 ACR** 已开通
@@ -120,7 +120,7 @@ npm run build
```bash
# 后端服务内网地址(关键)
BACKEND_SERVICE_URL=http://172.16.0.30:3001
BACKEND_SERVICE_URL=http://172.17.x.x:3001
# 如果需要配置环境变量(可选)
# VITE_API_BASE_URL 在构建时注入(很少使用)
@@ -217,7 +217,7 @@ ASL 模块GET /api/v1/asl/projects
Nginx 反向代理
后端服务http://172.16.0.30:3001/api/v1/asl/projects
后端服务http://172.17.x.x:3001/api/v1/asl/projects
```
### 📝 构建流程
@@ -363,7 +363,7 @@ http {
server ${BACKEND_SERVICE_HOST}:${BACKEND_SERVICE_PORT} fail_timeout=30s max_fails=3;
# 如果有多个后端实例(负载均衡)
# server 172.16.0.30:3001 weight=1;
# server 172.17.x.x:3001 weight=1;
# server 172.16.0.31:3001 weight=1;
keepalive 32; # 保持连接池
@@ -485,7 +485,7 @@ http {
access_log off;
# 仅允许内网访问
allow 10.0.0.0/8;
allow 172.16.0.0/12;
allow 172.17.0.0/16;
allow 192.168.0.0/16;
deny all;
}
@@ -547,7 +547,7 @@ Nginx接收请求
Nginxproxy_pass http://backend
后端服务http://172.16.0.30:3001/api/v1/projects
后端服务http://172.17.x.x:3001/api/v1/projects
后端返回数据
@@ -806,7 +806,7 @@ nginx.conf.template模板:
↓ envsubst 替换
nginx.conf最终配置:
server 172.16.0.30:3001;
server 172.17.x.x:3001;
```
#### 3. 健康检查
@@ -987,7 +987,7 @@ docker rm frontend-test
```bash
# 登录(使用 ACR 密码,不是阿里云账号密码)
docker login --username=your-aliyun-account registry.cn-hangzhou.aliyuncs.com
docker login --username=your-aliyun-account registry.cn-beijing.aliyuncs.com
# 输入密码后看到:
# Login Succeeded
@@ -998,21 +998,21 @@ docker login --username=your-aliyun-account registry.cn-hangzhou.aliyuncs.com
```bash
# 格式registry地址/命名空间/仓库名:版本号
docker tag frontend-service:v1.0.0 \
registry.cn-hangzhou.aliyuncs.com/clinical-research/frontend-service:v1.0.0
registry.cn-beijing.aliyuncs.com/clinical-research/frontend-service:v1.0.0
# 同时打一个 latest 标签
docker tag frontend-service:v1.0.0 \
registry.cn-hangzhou.aliyuncs.com/clinical-research/frontend-service:latest
registry.cn-beijing.aliyuncs.com/clinical-research/frontend-service:latest
```
### 步骤 3推送镜像
```bash
# 推送指定版本
docker push registry.cn-hangzhou.aliyuncs.com/clinical-research/frontend-service:v1.0.0
docker push registry.cn-beijing.aliyuncs.com/clinical-research/frontend-service:v1.0.0
# 推送 latest
docker push registry.cn-hangzhou.aliyuncs.com/clinical-research/frontend-service:latest
docker push registry.cn-beijing.aliyuncs.com/clinical-research/frontend-service:latest
# 推送过程需要 1-3 分钟(镜像很小)
```
@@ -1055,7 +1055,7 @@ docker push registry.cn-hangzhou.aliyuncs.com/clinical-research/frontend-service
| 配置项 | 值 |
|-------|-----|
| **镜像类型** | 容器镜像服务企业版实例 |
| **镜像仓库** | `registry.cn-hangzhou.aliyuncs.com/clinical-research/frontend-service` |
| **镜像仓库** | `registry.cn-beijing.aliyuncs.com/clinical-research/frontend-service` |
| **镜像版本** | `v1.0.0` |
| **镜像拉取策略** | 总是拉取镜像 |
@@ -1085,7 +1085,7 @@ docker push registry.cn-hangzhou.aliyuncs.com/clinical-research/frontend-service
```bash
# ⚠️ 必须配置(否则容器启动失败)
BACKEND_SERVICE_HOST=172.16.0.30
BACKEND_SERVICE_HOST=172.17.x.x
# 可选配置(默认 3001
BACKEND_SERVICE_PORT=3001
@@ -1108,7 +1108,7 @@ upstream backend {
server ${BACKEND_SERVICE_URL}; # ❌ 无法解析 http://172.16.0.30:3001
# 拆分后:
server 172.16.0.30:3001; # ✅ 正确
server 172.17.x.x:3001; # ✅ 正确
```
### 步骤 5配置健康检查
@@ -1337,7 +1337,7 @@ API 代理:响应时间 50-500ms取决于后端
# ✅ 正常启动
============================================
Starting Frontend Nginx Service
Backend Service: 172.16.0.30:3001
Backend Service: 172.17.x.x:3001
============================================
nginx: configuration file /etc/nginx/nginx.conf test is successful
@@ -1354,7 +1354,7 @@ nginx: configuration file /etc/nginx/nginx.conf test is successful
# ❌ 错误日志(后端连接失败)
2025/12/13 10:30:04 [error] 7#7: *1 connect() failed (111: Connection refused) while connecting to upstream
client: 172.31.0.10, server: _, request: "GET /api/v1/projects HTTP/1.1"
upstream: "http://172.16.0.30:3001/api/v1/projects"
upstream: "http://172.17.x.x:3001/api/v1/projects"
```
#### 3. Nginx 状态监控
@@ -1419,7 +1419,7 @@ curl http://localhost/nginx_status
cd frontend
npm run build
docker build -t frontend-service:v1.0.1 .
docker push registry.cn-hangzhou.aliyuncs.com/clinical-research/frontend-service:v1.0.1
docker push registry.cn-beijing.aliyuncs.com/clinical-research/frontend-service:v1.0.1
# 2. 在 SAE 中更新镜像
# SAE 控制台 → 应用详情 → 部署
@@ -1556,7 +1556,7 @@ location / {
# 2. 测试后端内网地址是否可达
# 登录前端应用的 Webshell
curl http://172.16.0.30:3001/api/v1/health
curl http://172.17.x.x:3001/api/v1/health
# 如果返回错误,说明:
# - 后端服务未启动
@@ -1567,7 +1567,7 @@ curl http://172.16.0.30:3001/api/v1/health
cat /etc/nginx/nginx.conf | grep -A 5 "upstream backend"
# 应该看到正确的后端地址:
# server 172.16.0.30:3001 fail_timeout=30s max_fails=3;
# server 172.17.x.x:3001 fail_timeout=30s max_fails=3;
# 4. 查看 Nginx 错误日志
tail -f /var/log/nginx/error.log | grep "upstream"
@@ -1579,14 +1579,14 @@ tail -f /var/log/nginx/error.log | grep "upstream"
# 方法 1更新环境变量
# SAE 控制台 → frontend-service → 应用配置 → 环境变量
# 确认:
BACKEND_SERVICE_HOST=172.16.0.30 # 正确的内网 IP
BACKEND_SERVICE_HOST=172.17.x.x # 正确的内网 IP
BACKEND_SERVICE_PORT=3001
# 重启应用使环境变量生效
# 方法 2测试内网连通性
# 在前端 Webshell 中:
telnet 172.16.0.30 3001
telnet 172.17.x.x 3001
# 如果连接失败,检查:
# - 后端和前端是否在同一 VPC
# - 安全组规则是否允许访问
@@ -1744,7 +1744,7 @@ cat /docker-entrypoint.sh | grep "envsubst"
cat /etc/nginx/nginx.conf | grep "server.*backend"
# 应该看到:
# server 172.16.0.30:3001;
# server 172.17.x.x:3001;
# 如果看到:
# server ${BACKEND_SERVICE_HOST}:${BACKEND_SERVICE_PORT}; # ❌ 未替换
@@ -1809,11 +1809,11 @@ export default defineConfig({
```bash
# ✅ 正确做法:拆分 Host 和 Port
BACKEND_SERVICE_HOST=172.16.0.30
BACKEND_SERVICE_HOST=172.17.x.x
BACKEND_SERVICE_PORT=3001
# ❌ 错误做法:完整 URL
BACKEND_SERVICE_URL=http://172.16.0.30:3001
BACKEND_SERVICE_URL=http://172.17.x.x:3001
# Nginx 无法解析协议前缀
```