docs: 更新项目架构与数据模型文档
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -6,18 +6,19 @@
|
||||
|
||||
## 1. 命令概览
|
||||
|
||||
| 命令 | 说明 |
|
||||
|------|------|
|
||||
| `parse` | 解析日志文件并存储到数据库 |
|
||||
| `stats` | 查询统计信息 |
|
||||
| `export` | 导出数据 |
|
||||
| `clean` | 清理数据 |
|
||||
| 命令 | 说明 | 数据流 |
|
||||
|------|------|--------|
|
||||
| `parse` | 解析日志文件到本地库 | log → local.db |
|
||||
| `aggregate` | 从本地库汇总生成发布库 | local.db → release.db |
|
||||
| `export` | 导出发布库到 CSV | release.db → CSV |
|
||||
| `stats` | 查询本地库统计信息 | 只读 local.db |
|
||||
| `clean` | 清理本地库数据(软删除) | 只写 local.db |
|
||||
|
||||
---
|
||||
|
||||
## 2. 命令详解
|
||||
|
||||
### 2.1 parse - 解析日志文件
|
||||
### 2.1 parse
|
||||
|
||||
```bash
|
||||
# 解析单个文件
|
||||
@@ -29,41 +30,60 @@ dotnet run parse --dir path/to/logs/
|
||||
# 解析目录(递归)
|
||||
dotnet run parse --dir path/to/logs/ --recursive
|
||||
|
||||
# 强制重新解析(覆盖已有数据)
|
||||
# 强制重新解析
|
||||
dotnet run parse --file log.txt --force
|
||||
```
|
||||
|
||||
### 2.2 stats - 查询统计
|
||||
### 2.2 aggregate
|
||||
|
||||
```bash
|
||||
# 查看文件解析统计
|
||||
dotnet run stats --file log.txt
|
||||
# 从 local.db 汇总生成 release.db(默认重建)
|
||||
dotnet run aggregate
|
||||
|
||||
# 追加模式(不删除已有记录)
|
||||
dotnet run aggregate --rebuild false
|
||||
```
|
||||
|
||||
### 2.3 export
|
||||
|
||||
```bash
|
||||
# 导出正式充电参数 CSV(默认)
|
||||
dotnet run export --output ./data/output
|
||||
|
||||
# 导出正式充电参数 CSV + legacy Qfod/Ploss
|
||||
dotnet run export --type all --output ./data/output
|
||||
|
||||
# 仅导出 legacy Qfod CSV
|
||||
dotnet run export --type qfod --format csv
|
||||
|
||||
# 导出 JSON
|
||||
dotnet run export --format json --type qfod
|
||||
```
|
||||
|
||||
### 2.4 stats
|
||||
|
||||
```bash
|
||||
# 查看整体统计
|
||||
dotnet run stats --summary
|
||||
|
||||
# 按 FOD 类型统计
|
||||
dotnet run stats --by-fod-type
|
||||
|
||||
# 按面板统计
|
||||
dotnet run stats --by-panel
|
||||
|
||||
# 按硬件版本统计
|
||||
dotnet run stats --by-hardware
|
||||
|
||||
# 按 RX 类型统计
|
||||
dotnet run stats --by-rx-type
|
||||
```
|
||||
|
||||
### 2.3 export - 导出数据
|
||||
### 2.5 clean
|
||||
|
||||
```bash
|
||||
# 导出为 CSV
|
||||
dotnet run export --format csv --output ./output/
|
||||
|
||||
# 导出为 JSON
|
||||
dotnet run export --format json --output ./output/
|
||||
|
||||
# 按文件导出
|
||||
dotnet run export --file log.txt --format csv
|
||||
```
|
||||
|
||||
### 2.4 clean - 清理数据
|
||||
|
||||
```bash
|
||||
# 清理指定文件的数据
|
||||
dotnet run clean --file log.txt --confirm
|
||||
# 清理指定场景
|
||||
dotnet run clean --scenario <guid> --confirm
|
||||
|
||||
# 清理所有数据
|
||||
dotnet run clean --all --confirm
|
||||
@@ -71,98 +91,20 @@ dotnet run clean --all --confirm
|
||||
|
||||
---
|
||||
|
||||
## 3. 命令实现
|
||||
## 3. 典型工作流
|
||||
|
||||
```csharp
|
||||
// Commands/ParseCommand.cs
|
||||
using System.CommandLine;
|
||||
```bash
|
||||
# 1. 解析日志
|
||||
dotnet run parse --dir ./data/test_input --recursive
|
||||
|
||||
namespace Gpulse.WCT.DataAnalyzer.Commands;
|
||||
# 2. 查看统计
|
||||
dotnet run stats --summary
|
||||
|
||||
public class ParseCommand : Command
|
||||
{
|
||||
public ParseCommand(ParseService parseService)
|
||||
: base("parse", "Parse log files and store data to database")
|
||||
{
|
||||
var fileOption = new Option<string>(
|
||||
"--file",
|
||||
"Path to a single log file to parse"
|
||||
);
|
||||
# 3. 汇总生成发布库
|
||||
dotnet run aggregate
|
||||
|
||||
var dirOption = new Option<string>(
|
||||
"--dir",
|
||||
"Path to directory containing log files"
|
||||
);
|
||||
|
||||
var recursiveOption = new Option<bool>(
|
||||
"--recursive",
|
||||
() => false,
|
||||
"Recursively search subdirectories"
|
||||
);
|
||||
|
||||
var forceOption = new Option<bool>(
|
||||
"--force",
|
||||
() => false,
|
||||
"Force re-parse even if file already parsed"
|
||||
);
|
||||
|
||||
AddOption(fileOption);
|
||||
AddOption(dirOption);
|
||||
AddOption(recursiveOption);
|
||||
AddOption(forceOption);
|
||||
|
||||
this.SetHandler(async (file, dir, recursive, force) =>
|
||||
{
|
||||
if (!string.IsNullOrEmpty(file))
|
||||
{
|
||||
await parseService.ParseFileAsync(file, force);
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(dir))
|
||||
{
|
||||
await parseService.ParseDirectoryAsync(dir, recursive, force);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Please specify --file or --dir");
|
||||
}
|
||||
}, fileOption, dirOption, recursiveOption, forceOption);
|
||||
}
|
||||
}
|
||||
# 4. 导出正式 CSV
|
||||
dotnet run export --output ./data/output
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 4. Program.cs 入口
|
||||
|
||||
```csharp
|
||||
// Program.cs
|
||||
using System.CommandLine;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Gpulse.WCT.DataAnalyzer.Commands;
|
||||
|
||||
var builder = Host.CreateApplicationBuilder(args);
|
||||
|
||||
// 注册服务
|
||||
builder.Services.AddScoped<ParseService>();
|
||||
builder.Services.AddScoped<StatsService>();
|
||||
builder.Services.AddScoped<ExportService>();
|
||||
builder.Services.AddScoped<CleanService>();
|
||||
builder.Services.AddDatabaseServices(builder.Configuration);
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// 创建根命令
|
||||
var rootCommand = new RootCommand("Gpulse.WCT.DataAnalyzer - FOD Log Data Parser");
|
||||
|
||||
// 使用服务提供者获取服务
|
||||
using var scope = app.Services.CreateScope();
|
||||
var provider = scope.ServiceProvider;
|
||||
|
||||
rootCommand.AddCommand(new ParseCommand(provider.GetRequiredService<ParseService>()));
|
||||
rootCommand.AddCommand(new StatsCommand(provider.GetRequiredService<StatsService>()));
|
||||
rootCommand.AddCommand(new ExportCommand(provider.GetRequiredService<ExportService>()));
|
||||
rootCommand.AddCommand(new CleanCommand(provider.GetRequiredService<CleanService>()));
|
||||
|
||||
return await rootCommand.InvokeAsync(args);
|
||||
```
|
||||
输出文件: `./data/output/WCT-ChargingParameterDatabase.csv`
|
||||
Reference in New Issue
Block a user