Files
forsetsystem/docs/02_接口设计文档.md
shenjianZ e63267cef6 feat: 将数据集从国外员工缺勤数据替换为中国企业缺勤模拟数据
- 新增中国企业员工缺勤模拟数据集生成脚本(generate_dataset.py),覆盖7个行业、180家企业、2600名员工
  - 重构 config.py,更新特征字段为中文名称,调整目标列、员工ID、行业类型等配置
  - 重构 clustering.py,简化聚类逻辑,更新聚类特征和群体命名(高压通勤型、健康波动型等)
  - 重构 feature_mining.py,更新相关性分析和群体比较维度(按行业、班次、婚姻状态等)
  - 新增 model_features.py 定义模型训练特征
  - 更新 preprocessing.py 和 train_model.py 适配新数据结构
  - 更新各 API 路由默认参数(model: random_forest, dimension: industry)
  - 前端更新主题样式和各视图组件适配中文字段
  - 更新系统名称为 China Enterprise Absence Analysis System
2026-03-11 10:46:58 +08:00

183 lines
3.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 接口设计文档
## 1. 接口说明
- 接口风格REST 风格
- 数据格式JSON
- 公共前缀:`/api`
统一返回结构:
```json
{
"code": 200,
"message": "success",
"data": {}
}
```
## 2. 数据概览接口
### 2.1 获取基础统计
- URL`/api/overview/stats`
- 方法:`GET`
- 说明:返回缺勤事件总量、员工覆盖数、平均缺勤时长等指标
返回字段示例:
- `total_records`
- `total_employees`
- `avg_absent_hours`
- `max_absent_hours`
- `min_absent_hours`
- `high_risk_ratio`
- `industries_covered`
### 2.2 获取月度趋势
- URL`/api/overview/trend`
- 方法:`GET`
- 说明:返回月度总缺勤时长、平均时长和记录数
### 2.3 获取星期分布
- URL`/api/overview/weekday`
- 方法:`GET`
- 说明:返回星期维度分布统计
### 2.4 获取原因分布
- URL`/api/overview/reasons`
- 方法:`GET`
- 说明:返回请假原因大类分布
### 2.5 获取季节分布
- URL`/api/overview/seasons`
- 方法:`GET`
- 说明:返回季节维度缺勤统计
## 3. 影响因素分析接口
### 3.1 获取特征重要性
- URL`/api/analysis/importance`
- 方法:`GET`
- 参数:`model`,可选
- 说明:返回模型特征重要性排序
### 3.2 获取相关性矩阵
- URL`/api/analysis/correlation`
- 方法:`GET`
- 说明:返回关键变量相关性矩阵
### 3.3 获取群体对比
- URL`/api/analysis/compare`
- 方法:`GET`
- 参数:`dimension`
- 说明:返回指定维度下的群体平均缺勤时长对比
支持维度:
- `industry`
- `shift_type`
- `job_family`
- `marital_status`
- `chronic_disease`
## 4. 缺勤预测接口
### 4.1 单次预测
- URL`/api/predict/single`
- 方法:`POST`
- 说明:输入核心字段,返回预测缺勤时长与风险等级
请求体示例:
```json
{
"leave_type": "病假",
"leave_reason_category": "身体不适",
"absence_month": 5,
"weekday": 2,
"near_holiday_flag": 0,
"medical_certificate_flag": 1,
"shift_type": "标准白班",
"is_night_shift": 0,
"monthly_overtime_hours": 26,
"commute_minutes": 42,
"chronic_disease_flag": 0,
"children_count": 1,
"industry": "制造业",
"marital_status": "已婚"
}
```
返回字段:
- `predicted_hours`
- `risk_level`
- `risk_label`
- `confidence`
- `model_used`
- `model_name_cn`
### 4.2 模型对比
- URL`/api/predict/compare`
- 方法:`POST`
- 说明:返回多个模型在同一输入下的预测对比结果
### 4.3 获取模型列表
- URL`/api/predict/models`
- 方法:`GET`
- 说明:返回可用模型及其性能指标
### 4.4 获取模型信息
- URL`/api/predict/model-info`
- 方法:`GET`
- 说明:返回训练样本量、特征数量和训练日期
## 5. 员工画像接口
### 5.1 获取聚类结果
- URL`/api/cluster/result`
- 方法:`GET`
- 参数:`n_clusters`
- 说明:返回聚类后的群体列表
### 5.2 获取聚类画像
- URL`/api/cluster/profile`
- 方法:`GET`
- 参数:`n_clusters`
- 说明:返回雷达图所需的群体画像数据
### 5.3 获取散点数据
- URL`/api/cluster/scatter`
- 方法:`GET`
- 参数:
- `n_clusters`
- `x_axis`
- `y_axis`
## 6. 错误处理
- `400`:请求参数错误
- `500`:服务器内部错误
常见错误场景:
- 请求体为空
- 维度参数非法
- 模型文件缺失或加载失败
- 后端依赖未正确安装