161 lines
3.9 KiB
Markdown
161 lines
3.9 KiB
Markdown
# 数据处理流程
|
||
|
||
> 所属模块:[架构概览](./概览.md)
|
||
|
||
---
|
||
|
||
## 1. 完整流程
|
||
|
||
```text
|
||
log 文件
|
||
→ parse
|
||
→ local.db
|
||
→ aggregate
|
||
→ release.db
|
||
→ export
|
||
→ WCT-ChargingParameterDatabase.csv
|
||
```
|
||
|
||
---
|
||
|
||
## 2. 阶段一:parse → local.db
|
||
|
||
```mermaid
|
||
sequenceDiagram
|
||
participant CLI as CLI
|
||
participant PS as ParseService
|
||
participant SS as ScenarioService
|
||
participant FNP as FileNameParser
|
||
participant QP as QfodParser
|
||
participant PP as PlossParser
|
||
participant DB as local.db
|
||
|
||
CLI->>PS: ParseFileAsync(filePath)
|
||
PS->>FNP: 解析文件名
|
||
FNP-->>PS: ScenarioInfo
|
||
PS->>SS: GetOrCreateScenarioAsync
|
||
SS->>DB: 维度 upsert + 场景 upsert
|
||
SS-->>PS: TestScenario
|
||
PS->>PS: 逐行读取文件
|
||
|
||
loop 每行
|
||
alt Qfod 行
|
||
PS->>QP: Parse(line)
|
||
QP-->>PS: QfodRecord
|
||
else Ploss 行
|
||
PS->>PP: Parse(line)
|
||
PP-->>PS: PlossRecord
|
||
end
|
||
end
|
||
|
||
PS->>DB: BatchInsert QfodRecords
|
||
PS->>DB: BatchInsert PlossRecords
|
||
PS->>DB: UpdateScenarioStats
|
||
PS-->>CLI: ParseReport
|
||
```
|
||
|
||
**关键点:**
|
||
|
||
- 文件名格式: `TxPanel-TxHardware-TxSoftware-RxType-Purpose-Date-Seq.log`
|
||
- 支持两行 Ploss 格式(header 行 + 数据行)
|
||
- 事务批量写入,读取 `Parser:BatchSize` 配置分批
|
||
- 解析错误记录到 Serilog,不阻断流程
|
||
|
||
---
|
||
|
||
## 3. 阶段二:aggregate → release.db
|
||
|
||
```mermaid
|
||
sequenceDiagram
|
||
participant CLI as CLI
|
||
participant AS as AggregationService
|
||
participant LDB as local.db
|
||
participant RDB as release.db
|
||
|
||
CLI->>AS: AggregateAsync()
|
||
AS->>LDB: 读取所有 PlossRecord + 关联维度
|
||
AS->>AS: 按 (车厂, 车型, 手机厂商, 型号) 分组
|
||
AS->>AS: 计算 9 个功率列平均值
|
||
AS->>AS: 计算 Q值/Q基值/P-Q系数
|
||
AS->>RDB: DELETE + INSERT (事务)
|
||
AS-->>CLI: AggregationReport
|
||
```
|
||
|
||
**聚合规则:**
|
||
|
||
| 字段 | 来源 | 计算方式 |
|
||
|------|------|----------|
|
||
| 车厂 (CarFactory) | 配置映射 `Aggregation:TxPanelMappings` | 找不到映射时 fallback 为 TxPanel.Name |
|
||
| 车型 (CarModel) | 配置映射 `Aggregation:CarModelMappings` | fallback 为 TxHardware.Version |
|
||
| 手机厂商 (PhoneBrand) | RxType.Name 拆分 | 取第一个分隔符前部分 |
|
||
| 型号 (PhoneModel) | RxType.Name 拆分 | 取第一个分隔符后部分 |
|
||
| 350mW~2250mW(9列) | PlossRecord.Field7 | 按功率匹配后取平均值 |
|
||
| Q值 (QValue) | QfodRecord.CurrentQ | 平均值 |
|
||
| Q基值 (QBaseValue) | QfodRecord.RawQ | 平均值 |
|
||
| P-Q值系数 (PqCoefficient) | PlossRecord.DeltaP | 平均值 |
|
||
| 谐振频率 (ResonanceFrequency) | 暂无 | 允许为空 |
|
||
|
||
**替代配置:**
|
||
|
||
配置文件 `appsettings.json` 中可添加映射:
|
||
|
||
```json
|
||
{
|
||
"Aggregation": {
|
||
"TxPanelMappings": {
|
||
"single-mold": "奇瑞",
|
||
"dual-rapid": "智己"
|
||
},
|
||
"CarModelMappings": {
|
||
"L6": "L6",
|
||
"CM3": "CM3"
|
||
}
|
||
}
|
||
}
|
||
```
|
||
|
||
---
|
||
|
||
## 4. 阶段三:export → CSV
|
||
|
||
```mermaid
|
||
sequenceDiagram
|
||
participant CLI as CLI
|
||
participant ES as ExportService
|
||
participant RDB as release.db
|
||
participant FS as Filesystem
|
||
|
||
CLI->>ES: ExportChargingParametersToCsvAsync(outputDir)
|
||
ES->>RDB: 读取 ChargingParameters (排序)
|
||
ES->>FS: 写入 WCT-ChargingParameterDatabase.csv
|
||
ES-->>CLI: 文件路径
|
||
```
|
||
|
||
**导出规格:**
|
||
|
||
- 固定文件名: `WCT-ChargingParameterDatabase.csv`
|
||
- 固定 17 列 UTF-8 BOM
|
||
- RFC 4180 转义
|
||
- 数字使用 invariant culture
|
||
|
||
---
|
||
|
||
## 5. 数据库隔离
|
||
|
||
```text
|
||
local.db release.db
|
||
───────── ──────────
|
||
tx_panel charging_parameter
|
||
tx_hardware (独立实体,无外键)
|
||
tx_software
|
||
rx_type
|
||
test_scenario
|
||
qfod_record
|
||
ploss_record
|
||
|
||
无关联 ←→ 无关联
|
||
```
|
||
|
||
- 代码中不存在 local entity 到 release entity 的导航属性
|
||
- 数据库中没有跨库外键
|
||
- export 不读 local.db,aggregate 不写 local.db |