Skip to content

GelinType/app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

紫金财险 · 智能人伤自核引擎(Human Injury Estimator)

基于多场景预测的动态阈值估损与实时预警系统。后端采用 FastAPI + Python 机器学习(严格模式:仅真实模型,无模拟回退),前端采用 Vue 3 + Element Plus,内置批量处理、历史相似案例分析、报告导出与全链路监控(Prometheus/Grafana)。

目录

  • 项目简介
  • 最新变更摘要(2025-11-11)
  • 当前状态速览
  • 技术栈
  • 系统架构概览
  • 端到端数据流(从输入 → 模型调用 → 处理 → 分析 → 输出)
  • 主要能力与接口
  • 系统需求与范围
  • 本地运行(Docker Compose)
  • 监控与可观测性
  • 目录结构
  • 开发与测试
  • 常见问题(FAQ)

项目简介

本项目用于对人伤案件进行“动态阈值估损”和“实时风险预警”,并提供:

  • 单笔估损与批量估损(同步/异步)
  • 智能模型选择(按伤情/地区/金额等自适应配置)
  • 历史相似案例检索与对比分析
  • 报告导出(估损、历史分析、批量结果)
  • 业务与系统级监控(Prometheus 指标 + Grafana 看板)

面向典型医疗人伤理赔场景,目标是提升自核准确性、降低超赔风险、缩短处理时长并增强可追溯性与决策辅助:

  • 准确性:通过多模型+自适应阈值选择减少经验拍脑袋估损误差;
  • 风险预警:在检测费用结构与超阈比的同时基于伤情/地区等风险因子生成增强画像;
  • 批量能力:支持理赔集中处理高峰期导入 Excel 批量评估与报告产出;
  • 历史学习:基于相似案例与趋势分析提供横向/纵向参考,提高核查效率;
  • 可观测性:通过指标/告警/看板保障稳定性与模型可运营性;
  • 可演进性:严格模式下当真实模型不可用将直接返回错误(不再提供模拟输出,以避免误导决策);同时为后续替换/多模集成预留接口。

最新变更摘要(2025-11-11)

  • 解释性集成:移除旧的 /api/v1/estimate/explain 图片端点,改为在主接口 /api/v1/estimate 中直接返回数值型 SHAP 解释字段 shap_explanation,包含 Top-15 蜂群图数据(训练分布 + 当前样本)。
  • 前端可视化:EstimateView.vue 改为仅蜂群图(ECharts Scatter),红/蓝双向色,菱形高亮当前样本;去除柱状图与旧图片渲染。防重复提交:仅保留底部按钮触发,移除顶部按钮与表单 submit 事件。
  • 一致性保障:无论真实 SHAP 还是回退(特征贡献启发式),都严格返回 15 个特征项,字段为 { feature, values[], sample_value }
  • 阈值稳健性:对 GAN 阈值负数进行下限钳制(≥ 0)。
  • 安全加固:Redis 不再映射外部端口,启用 protected-moderequirepass,内部服务使用 redis://:password@redis:6379/0 连接。
  • 监控修复:
    • Grafana 仪表盘 JSON 规范化,修复“Dashboard title cannot be empty”。
    • Nginx 暴露 location = /nginx_status { stub_status; },Prometheus 以该路径采集基础状态(注意:非 Prometheus 原生指标,建议后续接入 nginx-prometheus-exporter)。
  • 测试增强:tests/test_api.py 增加断言 len(shap_explanation.beeswarm) == 15 与项字段校验。
  • 持久化迁移:从 SQLite 迁移至 MySQL(SQLAlchemy ORM)。新增 backend/models_db.py 中的 Case ORM 模型与配套 CRUD;连接串与环境变量说明见 docs/REQUIREMENTS.md;后续将引入 Alembic 管理数据库迁移。

当前状态速览

  • 已完成
    • /api/v1/estimate 集成数值型 SHAP,Top-15 蜂群图统一输出;前端仅保留蜂群图并去重提交触发。
    • Redis 加固、Nginx /nginx_status 暴露、Prometheus 抓取与 Grafana 看板修复。
    • GAN 阈值非负钳制;批量与历史分析链路稳定;DB 已迁移至 MySQL(SQLAlchemy)。
    • 测试覆盖增加(SHAP 结构长度 15 的断言)。
  • 待办/后续
    • 验证运行日志仅出现一次“单条预测模式”(排除重复提交的运行态确认)。
    • 视需要在单条响应中显式合入 enhanced_alert 字段并补充测试。
    • 建立 Alembic 初始迁移与备份策略,接入 mysqld_exporter 丰富数据库指标。

技术栈

  • 后端:FastAPI、Pydantic、MySQL 8.0(SQLAlchemy ORM)、Celery(异步)、Redis(队列)、Prometheus 客户端
  • 机器学习:TensorFlow、scikit-learn、jieba、NumPy、Pandas
  • 前端:Vue 3、Vite、Element Plus、ECharts
  • 部署/监控:Docker、Docker Compose、Prometheus、Grafana、Alertmanager、Node Exporter

系统架构概览

[Vue3 前端] ⇄ [FastAPI 后端]
                      ├─ services.estimate_injury_case()
                      │    ├─ model_selector.select_model_for_case()
                      │    ├─ predict_model.CompensationThresholdPredictorFull.predict_single_case()
                      │    ├─ enhanced_alert_service.get_enhanced_alert_analysis()
                      │    └─ database.save_case()
                      ├─ 批量:process_batch_file() / Celery 异步任务
                      ├─ 历史分析:HistoricalAnalysisService(相似/对比/趋势)
                      ├─ 报表:report_export_service(PDF/Excel)
                      └─ 监控:Prometheus /metrics + Instrumentator

端到端数据流(从输入 → 模型调用 → 处理 → 分析 → 输出)

以下以“单笔估损接口 /api/v1/estimate”为例,详细说明核心数据流:

  1. 前端提交输入
  • 页面:frontend-vue/src/views/EstimateView.vue
  • 用户填写基础信息(性别、伤势等级、责任系数、治疗情况等)、诊断信息、各项费用(医疗费/营养费/护理费/误工费/后续治疗/精神抚慰金/其他费用)。
  • 表单校验通过后,向后端 POST /api/v1/estimate 提交 InjuryCaseInput(Pydantic)结构化 JSON。
  1. 后端接收与模型前置处理
  • 入口:backend/main.py@app.post("/api/v1/estimate")
  • 反序列化为 models.InjuryCaseInput,并计数/耗时等指标写入 Prometheus。
  1. 智能模型选择(自适应配置)
  • services.estimate_injury_case() 首先调用 model_selector.select_model_for_case()
    • 计算案件总费用、金额区间、伤情复杂度、治疗复杂度、地区经济水平、风险指标等
    • 产出最优“伤情级别模型”与参数(阈值倍数、风险敏感度、置信度修正等)
  1. 模型推理(严格模式:仅真实模型)
  • 使用 predict_model.CompensationThresholdPredictorFullbackend/ml/full_pipeline_gan.py::FullPipelineGANPredictor(经 backend/ml/gan_predictor.py 适配):
    • 内含 DataProcessor 完成特征工程(证件地区映射、文本分词、数值归一化等)
    • 加载模型资产(见 backend/model_assets/)进行推理,得到基础预测与阈值信息
  • 严格模式:若真实模型不可用,将返回明确错误,不再模拟降级。
  1. 业务后处理、解释与增强分析
  • 费用总额与阈值融合“智能模型配置”得到 final_thresholdpredicted_amount
  • 依据超阈比与配置评估四级 risk_level(green/yellow/orange/red)与 confidence,并计算 exceed_ratio
  • 生成 cost_breakdown(各费用项分解)、risk_factorsrecommendations
  • 调用 enhanced_alert_service.get_enhanced_alert_analysis() 输出更细粒度的预警画像(结合伤情/治疗/地区/复杂度)
  • 生成解释:构造 shap_explanation 字段(Top-15 蜂群图数据);真实 SHAP 可用时返回训练分布的 |SHAP| 排序分位与当前样本数值;不可用时回退到规则化的多项成本贡献与责任系数,并补齐占位特征以严格 15 项。
  1. 结果持久化与兼容字段
  • 通过 database.save_case() 将案件核心结果落库(MySQL,使用 SQLAlchemy ORM)
  • 同时填充兼容字段:final_thresholdtotal_compensationis_above_thresholdinjury_severityregion_name
  1. 最终响应
  • 统一返回 InjuryEstimateResponse(包含预测、阈值、四级风险、exceed_ratio、分解、建议、增强预警、shap_explanation 与原始输出快照),前端渲染卡片/图表展示。

并行/周边能力的数据流:

  • 批量估损(同步):POST /api/v1/batch-estimate 解析 CSV/Excel(Pandas),逐条走单笔流程并汇总;响应包含 resultsresults_token
  • 批量估损(异步):POST /api/v1/batch-estimate-async 投递 Celery 任务,GET /api/v1/task-status/{taskId} 轮询进度;完成后任务结果同样包含 results_token
  • 历史分析:/api/v1/historical-analysis/* 调用 HistoricalAnalysisService,包含相似案例检索、明细对比与趋势分析
  • 报表导出:/api/v1/reports/*report_export_service 生成报告文件,/api/v1/reports/download/{filename} 下载
  • 监控指标:所有请求在 REQUEST_COUNT/REQUEST_DURATION/metrics 暴露;另有 prometheus_fastapi_instrumentator 自动指标

前端视图数据流(批量与历史分析)

以下梳理前端关键视图与后端 API 的交互路径,便于排查问题与扩展功能。

  1. 批量案件处理(frontend-vue/src/views/BatchProcessView.vue
  • 上传与处理

    • 触发:Element Plus el-upload 拖拽/选择文件

    • 目标:POST /api/v1/batch-estimate(由 uploadUrl = api.defaults.baseURL + '/batch-estimate' 计算,api.defaults.baseURL 固定为 /api/v1

    • 载荷:浏览器自动构造 multipart/form-data,支持 .xlsx/.xls/.csv

    • 后端:解析文件 → 逐条调用单笔估损 → 汇总成列表并返回,同时生成 results_token

    • 前端:接收 { success, data, results_token },渲染表格/统计,并优先在导出时使用 results_token

    • 大文件自动异步:当上传文件超过 1MB 时,前端自动切换至 POST /api/v1/batch-estimate-async;完成后在 GET /api/v1/task-status/{id}result 中同样可获得 results_token

  • 模板下载

    • GET /api/v1/reports/template?template_type=batch&file_format=excel
    • 返回 { success, filename, report_url },前端创建 <a> 触发下载
  • 批量结果导出

    • POST /api/v1/reports/batch

    • Body(推荐,避免大 JSON):{ results_token: '<服务返回的token>', export_format: 'excel', include_summary: true, include_charts: true }

    • Body(兼容老流程):{ batch_results: [...], export_format: 'excel' }

    • 返回 { success, filename, report_url },用于下载 Excel 报告

    • Windows PowerShell 示例(token 方式,避免复杂转义):

      • 使用 Invoke-WebRequestcurl.exe 时注意 JSON 转义;建议优先通过前端按钮导出。
  • 展示与字段映射

    • 风险状态:四级 risk_level(green/yellow/orange/red)与 exceed_ratio 可视化;is_above_threshold 兼容显示
    • 预测阈值:final_threshold
    • 伤情等级/地区:injury_severityregion_name
    • 费用明细:如 fee_yiliaounit_fee_wugong * quantity_wugong
  • 认证/头信息

    • 组件示例中加入了 Authorization: Bearer <token>(如后端未启用校验,可忽略)
  • CSV 解码容错:后端对 CSV 读取已支持 utf-8 → gbk → latin-1 回退,降低因编码导致的解析失败。

  • 反向代理容忍度:前端 Nginx 已设置 client_max_body_size 50m 与较长超时,降低 413/502 风险。

  1. 历史分析视图(frontend-vue/src/views/HistoricalAnalysisView.vue
  • 相似案件检索

    • POST /api/v1/historical-analysis/similar-cases
    • Body:{ current_case, similarity_threshold, max_results, date_range_months }
    • 返回:{ success, similar_cases, search_summary }
    • UI:卡片网格展示相似度、伤情/治疗/金额/日期与匹配因素;支持多选(最多5个)
  • 详细对比分析

    • POST /api/v1/historical-analysis/detailed-comparison
    • Body:{ current_case, comparison_case_ids, analysis_dimensions: ['cost','timeline','treatment','outcome'] }
    • 返回:{ success, comparison_result },前端渲染费用统计分位、风险因素、建议清单等
  • 趋势分析

    • GET /api/v1/historical-analysis/trends?injury_type=&period_months=&region_filter=
    • 返回:{ success, trend_data },用于绘制趋势与预测(变化率、方向、未来 3 个月预测等)
  • 报告导出(历史分析)

    • 统一走 POST /api/v1/reports/historical
    • Body:
      • 相似检索:{ analysis_type: 'similar_cases', analysis_data: { query, results, summary }, export_format: 'pdf' }
      • 详细对比:{ analysis_type: 'detailed_comparison', analysis_data: { comparison, selected_cases }, export_format: 'pdf' }
      • 趋势分析:{ analysis_type: 'trend_analysis', analysis_data: { trend, query }, export_format: 'pdf' }
    • 返回:{ success, filename, report_url },创建 <a> 进行下载
  • 其他说明

    • Axios 实例 src/api/index.jsbaseURL 设为 /api/v1,通过 vite 代理转发;部分导出接口直接使用 fetch('/api/v1/...')
    • 视图内包含基础输入校验、加载态与错误提示;无状态依赖后端会返回 detail/error 字段

主要能力与接口

核心 REST 接口(节选):

  • 估损预测:POST /api/v1/estimate
  • 案件记录:GET /api/v1/casesPOST /api/v1/cases/{id}/feedback
  • 批量估损:POST /api/v1/batch-estimate(同步)、POST /api/v1/batch-estimate-async(异步)
  • 任务管理:GET /api/v1/task-status/{taskId}DELETE /api/v1/task/{taskId}
  • 历史分析:相似案例、详细对比、趋势配置(多条接口)
  • 报表导出:估损/历史/批量报告生成与模板下载(批量优先使用 results_token 进行导出)
  • 健康检查:/health/ready;监控指标:/metrics

建议参考 tests/test_api.py 获取端到端示例。

估损预测返回的 SHAP 数值解释(Top-15)

  • 字段:response.shap_explanation.beeswarm 为长度 15 的数组,每项:
    • feature: string,特征名(回退模式下可能为“成本/责任相关”的合成特征名);
    • values: number[],训练数据上的 SHAP 值分布(用于蜂群图散点)或启发式分布;
    • sample_value: number,当前样本的该特征 SHAP 值(菱形标注)。
  • 颜色:x<0 蓝色,x>=0 红色;x 轴单位为 SHAP 值。
  • 约束:无论真实/回退,严格 15 项,便于前端固定渲染。

历史分析接口契约(简要)

以下为核心历史分析接口的请求/响应字段示例(仅示意,字段可能随版本演进细化)。

  1. 相似案件检索
  • 方法与路径:POST /api/v1/historical-analysis/similar-cases
  • 请求示例:
{
  "current_case": {
    "clinical_diagnosis": "右胫骨骨折",
    "injured_part2": "右腿",
    "treat_way": "手术治疗",
    "fee_yiliao": 35000,
    "certi_code": "110101199001010001"
  },
  "similarity_threshold": 0.6,
  "max_results": 10,
  "date_range_months": 12
}

端到端前端交互时序图

sequenceDiagram
  autonumber
  participant U as User
  participant F as Frontend (Vue)
  participant A as API (FastAPI)
  participant S as ModelSelector
  participant P as Predictor (ML)
  participant E as AlertService
  participant D as DB (MySQL)
  participant C as Celery
  participant R as Redis
  participant M as Prometheus

  rect rgb(245, 247, 250)
  note over U,F: 单笔估损 – EstimateView
  U->>F: 填写表单并提交
  F->>A: POST /api/v1/estimate (InjuryCaseInput)
  A->>S: select_model_for_case(case)
  S-->>A: model_config
  A->>P: predict_single_case(processed_features)
  P-->>A: base_prediction/threshold
  A->>E: enhanced_alert_analysis(case, result)
  E-->>A: alert_profile
  A->>D: save_case(summary)
  A-->>F: InjuryEstimateResponse
  A-->>M: /metrics 记录请求/耗时/自定义计数
  end

  rect rgb(245, 247, 250)
  note over U,F: 批量处理 – BatchProcessView
  U->>F: 上传 Excel/CSV
  F->>A: POST /api/v1/batch-estimate (multipart)
  loop 对每条记录
    A->>A: 复用单笔估损流程
  end
  A-->>F: {results, results_token}
  U->>F: 导出结果
  F->>A: POST /api/v1/reports/batch
  A-->>F: { filename, report_url }
  end

  rect rgb(245, 247, 250)
  note over U,F: 历史分析 – HistoricalAnalysisView
  U->>F: 相似检索/对比/趋势
  F->>A: POST /historical-analysis/similar-cases
  A-->>F: similar_cases
  F->>A: POST /historical-analysis/detailed-comparison
  A-->>F: comparison_result
  F->>A: GET /historical-analysis/trends
  A-->>F: trend_data
  U->>F: 导出历史分析报告
  F->>A: POST /reports/historical (analysis_type=...)
  A-->>F: { filename, report_url }
  end

  note over A,C,R: 异步批处理(可选)\nPOST /batch-estimate-async -> Celery 入队 -> 轮询 task-status
Loading
  • 响应示例:
{
  "success": true,
  "similar_cases": [
    {
      "case_id": "HIST-20231015-000123",
      "similarity_score": 0.78,
      "matched_factors": ["injury_type", "treatment_method", "total_cost"],
      "case_summary": {
        "injury_type": "胫腓骨骨折",
        "treatment_method": "手术治疗",
        "total_cost": 42000,
        "created_date": "2023-10-15"
      }
    }
  ],
  "search_summary": { "total_searched": 15432 }
}
  1. 详细对比分析
  • 方法与路径:POST /api/v1/historical-analysis/detailed-comparison
  • 请求示例:
{
  "current_case": { "clinical_diagnosis": "右胫骨骨折", "treat_way": "手术治疗" },
  "comparison_case_ids": ["HIST-20231015-000123", "HIST-20220908-000045"],
  "analysis_dimensions": ["cost", "timeline", "treatment", "outcome"]
}
  • 响应示例(节选):
{
  "success": true,
  "comparison_result": {
    "cost_analysis": {
      "cost_statistics": {
        "medical_fee": { "average": 32000, "median": 30000, "percentile_75": 36000, "percentile_90": 42000 }
      }
    },
    "risk_assessment": {
      "overall_risk_level": "",
      "risk_factors": [
        { "factor": "手术耗材占比", "severity": "", "description": "高于均值 15%", "current_value": 0.35, "reference_value": 0.30 }
      ]
    },
    "recommendations": [
      { "type": "费用优化", "priority": "", "suggestion": "复核术后耗材清单", "reasoning": "显著高于对照组" }
    ]
  }
}
  1. 趋势分析
  • 方法与路径:GET /api/v1/historical-analysis/trends
  • 请求参数:injury_typeperiod_monthsregion_filter
  • 响应示例(节选):
{
  "success": true,
  "trend_data": {
    "cost_trends": { "trend_direction": "increasing", "change_rate": 0.12, "analysis_period": "2024-11~2025-10" },
    "prediction": { "next_3_months": [38000, 39500, 40500], "confidence_level": 0.82, "recommendation": "关注术后康复费用增长" }
  }
}

本地运行(Docker Compose)

使用项目根目录下 docker-compose.yml 一键启动:

# Windows PowerShell
cd human-injury-estimator
docker compose up -d --build

停止与清理:

docker compose down -v

监控与可观测性

  • 应用内指标:
    • prometheus_client 业务指标(请求数、耗时、模型预测计数等)
    • prometheus_fastapi_instrumentator 自动采集 HTTP 指标
  • 外部监控:
    • Prometheus 抓取 /metrics;规则见 monitoring/prometheus.ymlmonitoring/alert_rules.yml
    • Grafana 自动加载数据源/看板(monitoring/grafana/provisioning
    • Node Exporter 提供主机级指标;Alertmanager 负责告警收敛

附注(Nginx 状态采集):

  • 前端容器内的 nginx.conf 已暴露 GET /nginx_status(stub_status),monitoring/prometheus.yml 中 frontend job 使用 metrics_path: /nginx_status;由于输出为 Nginx 基础状态文本,若需要标准 Prometheus Nginx 指标,建议部署 nginx-prometheus-exporter 并改为抓取 exporter 的 /metrics

附注(MySQL 监控):

  • 建议引入 mysqld_exporter 将数据库指标暴露到 Prometheus(连接、QPS、缓冲命中率、慢查询等),并在 Grafana 增加 MySQL 看板与告警规则。

附注(严格模式):不再提供模拟降级路径。若模型加载失败,应通过 /ready 就绪探针与日志/告警快速定位处理;原 prediction_fallback_total 指标若保留,其值应恒为 0。

目录结构(关键路径)

human-injury-estimator/
├─ backend/
│  ├─ main.py                      # FastAPI 路由 & 指标
│  ├─ services/                    # 估损业务编排(核心在 core.py)
│  ├─ models/                      # Pydantic 输入/输出模型
│  ├─ ml/
│  │   ├─ full_pipeline_gan.py     # GAN 全流程管线(权重/预处理/推理)
│  │   └─ gan_predictor.py         # 服务层适配器(封装校验与错误处理)
│  ├─ historical/                  # 历史分析服务
│  ├─ reports/                     # 报告导出服务
│  ├─ alerts/                      # 批量预警分析
│  ├─ data_access/                 # MySQL/SQLAlchemy、Repository 封装
│  ├─ tasks/                       # Celery 应用与任务
│  ├─ utils/                       # 工具与存储封装
│  ├─ model_selector.py            # 智能模型选择(阈值倍数/风险/置信度)
│  ├─ predict_model.py             # 真实模型及数据预处理(历史保留/可迁移)
│  ├─ full_pipeline_shap.py        # SHAP 数值解释与 Top-15 蜂群图
│  ├─ models_db.py                 # SQLAlchemy ORM 模型定义(Case 等)
│  └─ model_assets/                # 模型权重/统计数据
├─ frontend-vue/                   # Vue3 + Element Plus 前端
├─ monitoring/                     # Prometheus/Grafana/Alertmanager 配置
├─ docker-compose.yml              # 一键编排:前后端/Redis/Celery/监控
└─ tests/                          # API 与性能测试

开发与测试

  • 本地开发:
    • 后端:backend/requirements.txt 安装后运行 uvicorn backend.main:app --reload
    • 前端:cd frontend-vue && npm i && npm run dev
  • 单元/集成测试:
    • pytest -q(见 tests/test_api.py
    • 已增加断言 shap_explanation.beeswarm 结构与长度 15 的校验。
  • 性能压测:
    • locust -f tests/locustfile.py(浏览器打开 8089 配置目标地址)

常见问题(FAQ)

  • Q: 真实模型不可用是否影响服务?
    • A: 严格模式下会返回明确错误(5xx)。请检查 backend/model_assets/ 是否齐全,并通过 /ready 与日志/告警确认模型加载状态。为避免误导决策,当前版本不再提供模拟回退。
  • Q: 阈值与风险等级如何确定?
    • A: 阈值由模型输出与“智能模型配置”叠加得到;风险等级依据超阈比等多因素确定,采用四级分级(green/yellow/orange/red),并暴露 exceed_ratio
  • Q: 指标出口在哪里?
    • A: 统一在 /metrics 暴露,Prometheus 按配置周期抓取。

如需进一步了解设计与演进,请查看:

系统需求与范围

1. 功能需求

  1. 单笔估损:根据案件输入生成动态阈值、预测金额、风险等级、增强预警;
  2. 批量估损:支持上传 CSV/Excel(≥1000 条记录),同步与异步两种模式,生成批量统计与可导出报告;
  3. 历史分析:
  • 相似案例检索:按伤情、治疗、费用聚类/向量特征匹配;
  • 详细对比:多维度费用结构差异、风险因子解释、建议输出;
  • 趋势分析:费用与治疗方式演变、未来短期预测;
  1. 报告导出:估损单、批量结果、历史分析报告(PDF/Excel),包含图表与摘要;
  2. 反馈记录:允许对预测结果进行人工反馈(提升数据闭环后续迭代);
  3. 监控与告警:系统健康(CPU/内存/请求耗时)、业务指标(预测次数、超阈案例比、模型降级次数)。

2. 非功能需求

  • 性能:单笔估损 P95 < 800ms(真实模型加载后);批量 1000 条同步 < 120s 或建议异步;
  • 可用性(严格模式):模型加载失败将返回错误;通过 /ready 与监控保障快速恢复;
  • 可观察性:至少暴露请求数、时延、预测成功/失败、降级次数、批量任务进度;
  • 扩展性:模型选择逻辑模块化,可添加新伤情层级与地区经济参数;
  • 安全性:后续可集成鉴权(JWT / OAuth2),日志不输出敏感证件号;
  • 追溯性:持久化关键输入、输出、阈值参数与风险因子,支持审计。

3. 输入数据范围(核心字段)

  • 基础身份:证件号(解析地区用于经济水平分层)、性别、年龄(可扩展);
  • 伤情与治疗:临床诊断、受伤部位、治疗方式、伤情等级(轻/中/重/术后)、康复措施;
  • 费用项:医疗、护理、营养、误工(单价+天数)、后续治疗预估、精神抚慰金、其他附加费用;
  • 案件属性:责任系数、是否涉及残疾评定(可扩展)、地区类别(城镇/农村)。

4. 输出数据范围

  • 预测金额(predicted_amount)、最终阈值(final_threshold)、是否超阈(is_above_threshold)、超阈比例(exceed_ratio);
  • 风险等级(risk_level:green/yellow/orange/red)、置信度(confidence)、风险因子列表(risk_factors);
  • 增强预警画像:复杂度标签、地区经济等级、建议动作列表;
  • 费用分解:各项费用原值与加总、可优化项提示;
  • 历史分析:相似案例摘要(相似度、关键差异)、对比统计分位、趋势方向与变化率、预测未来窗口值;
  • 报告元数据:文件名、下载地址、生成时间、包含图表标记。

5. 模型与算法需求(迭代基线)

  • 模型选择:按伤情等级、总费用区间、复杂度指标(治疗方式、费用结构占比)、地区经济水平综合打分;
  • 预测模型:初期使用静态保存的 TensorFlow / Sklearn 模型;后续支持多模型集成(加权或 stacking)与在线更新;
  • 相似检索:可扩展为 embedding(诊断文本 + 特征向量)+ Ann 索引(当前简化为规则+统计);
  • 趋势分析:费用时间序列基础上(季节性/异常点)进行简易回归或指数平滑预测;
  • 风险因子:对超阈比、费用结构异常(如某费用异常占比高)、治疗路径偏差、地区经济对比进行加权评分。

6. 监控指标规划(示例)

指标 类型 说明
prediction_requests_total Counter 估损请求次数
prediction_latency_seconds Histogram 单笔估损耗时分布
prediction_fallback_total Counter 触发模拟降级次数(严格模式下应恒为 0,或可替换为 model_load_failures_total
batch_jobs_total Counter 批量任务提交次数
batch_job_duration_seconds Histogram 批量任务处理耗时
historical_queries_total Counter 历史分析查询次数(相似+对比+趋势)
above_threshold_cases_total Counter 超阈案例次数
alert_high_risk_total Counter 高风险预警产生次数

7. 异常与错误模式

  • 输入校验失败:返回 4xx + detail;
  • 模型加载失败:记录日志 + 增量计数(prediction_fallback_total)使用模拟逻辑;
  • 批量文件解析错误:返回部分成功 + 错误行列表(后续迭代可添加);
  • 趋势分析数据不足:返回 trend_direction = insufficient_data 并附加建议;
  • 导出报告失败:返回 error 字段并建议重试(前端使用重试封装再次尝试)。

8. 未来演进建议(Roadmap 补充)

  • 模型层:引入轻量向量检索(Faiss / Milvus)完善相似检索准确度;
  • 数据层:接入真实理赔流水与外部医疗费用基准数据;
  • 决策层:引入规则引擎(Drools / custom DSL)组合模型结果与审核策略;
  • 质量治理:增加预测偏差自动回收与再训练流程(模型漂移监测);
  • 安全合规:脱敏策略、访问审计日志、角色权限;
  • UI 体验:实时进度 WebSocket、可编辑费用结构对比调整建议场景。

9. 当前范围界限(Out of Scope)

  • 不包含支付理赔流程(仅估损与分析);
  • 不包含 OCR/图像识别(费用票据解析);
  • 不包含自动残疾等级评定算法(可后续扩展);
  • 不包含实时流式处理(Kafka 等),当前以批/请求驱动。

10. 成功度量(KPIs 初稿)

  • 平均预测误差(与人工后核对比)下降 ≥ 15%;
  • 高风险案件提前识别率 ≥ 85%;
  • 批量处理人工耗时缩短 ≥ 40%;
  • 估损服务可用性(含降级)≥ 99%;
  • 模型降级触发次数逐步下降(上线真实模型后 < 2% 请求)。

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors