feat: 重构项目结构,添加 WPF 应用
- 将核心功能提取到 WCTDataMiner.Core 类库 - 添加 WCTDataMiner.Wpf 桌面应用 - 支持数据解析、导出、统计等功能 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
54
src/WCTDataMiner.Core/Parsers/QfodParser.cs
Normal file
54
src/WCTDataMiner.Core/Parsers/QfodParser.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using WCTDataMiner.Core.Models;
|
||||
|
||||
namespace WCTDataMiner.Core.Parsers;
|
||||
|
||||
/// <summary>
|
||||
/// Qfod日志解析器
|
||||
/// 格式: X#:Q A->B C D E
|
||||
/// 示例: 0#:Q 1->25 45.5 20.5 2
|
||||
/// </summary>
|
||||
public class QfodParser : IParser<QfodRecord>
|
||||
{
|
||||
private static readonly Regex QfodPattern = new(
|
||||
@"^(\d)#:Q\s+(\d+)->(-?\d+)\s+([-\d.]+)\s+([-\d.]+)\s+(\d+)$",
|
||||
RegexOptions.Compiled
|
||||
);
|
||||
|
||||
public bool CanParse(string line) => QfodPattern.IsMatch(line);
|
||||
|
||||
public ParseResult<QfodRecord> Parse(string line, Guid scenarioId)
|
||||
{
|
||||
var match = QfodPattern.Match(line);
|
||||
if (!match.Success)
|
||||
{
|
||||
return ParseResult<QfodRecord>.Failure(
|
||||
"FORMAT_MISMATCH",
|
||||
"Line does not match Qfod pattern"
|
||||
);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var record = new QfodRecord
|
||||
{
|
||||
ScenarioId = scenarioId,
|
||||
ChargerIndex = byte.Parse(match.Groups[1].Value),
|
||||
CoilIndex = byte.Parse(match.Groups[2].Value),
|
||||
DeltaQ = int.Parse(match.Groups[3].Value),
|
||||
CurrentQ = float.Parse(match.Groups[4].Value),
|
||||
RawQ = float.Parse(match.Groups[5].Value),
|
||||
FodType = byte.Parse(match.Groups[6].Value)
|
||||
};
|
||||
|
||||
return ParseResult<QfodRecord>.Success(record);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ParseResult<QfodRecord>.Failure(
|
||||
"TYPE_CONVERSION",
|
||||
$"Failed to convert field: {ex.Message}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user