SSPC-Tester/SSPCTester.Seed/Program.cs

179 lines
7.1 KiB
C#
Raw Permalink Normal View History

using SSPCTester.Logic.Models;
using SSPCTester.Logic.Storage;
namespace SSPCTester.Seed;
public static class Program
{
public static async Task<int> Main(string[] args)
{
// 项目根目录:参数 > 环境变量 > 默认 %LOCALAPPDATA%\SSPCTester\Projects
string root = args.FirstOrDefault()
?? Environment.GetEnvironmentVariable("SSPCTESTER_PROJECTS")
?? Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"SSPCTester", "Projects");
Directory.CreateDirectory(root);
Console.WriteLine($"Seeding into: {root}");
var store = new ProjectStore { ProjectsRoot = root };
var projects = new[]
{
BuildProject(
name: "合格样机-常温功能验证 A",
serial: "SSPC-QA-2026-0001",
model: "SSPC-24CH-28V-1A",
manufacturer: "SPC DynaTest 实验室",
tester: "张工",
daysAgo: 1,
seed: 1101,
temperatureC: 24.8,
humidityPct: 52.0,
pressureKpa: 101.2,
remark: "常温常压条件下完成 24 路基础、曲线、功率及保护功能测试,综合判定合格。"),
BuildProject(
name: "合格样机-低温启动验证 B",
serial: "SSPC-QA-2026-0002",
model: "SSPC-24CH-28V-1A-LT",
manufacturer: "SPC DynaTest 实验室",
tester: "李工",
daysAgo: 2,
seed: 2202,
temperatureC: -20.0,
humidityPct: 38.0,
pressureKpa: 100.9,
remark: "低温启动后完成全通道闭合、关断、动态响应与保护功能复核,全部项目合格。"),
BuildProject(
name: "合格样机-高温老化复测 C",
serial: "SSPC-QA-2026-0003",
model: "SSPC-24CH-28V-1A-HT",
manufacturer: "SPC DynaTest 实验室",
tester: "王工",
daysAgo: 3,
seed: 3303,
temperatureC: 55.0,
humidityPct: 46.0,
pressureKpa: 100.6,
remark: "高温老化后复测 24 路输出特性、时序曲线、功率损耗及六项保护,结果均满足判定阈值。"),
};
foreach (var p in projects)
{
await store.SaveAsync(p);
Console.WriteLine($" [OK] {p.Name} -> {p.FolderPath}");
}
Console.WriteLine($"Done. {projects.Length} projects written.");
return 0;
}
private static Project BuildProject(
string name, string serial, string model, string manufacturer,
string tester, int daysAgo, int seed,
double temperatureC, double humidityPct, double pressureKpa, string remark)
{
var rng = new Random(seed);
var testDate = DateTime.Today.AddDays(-daysAgo);
var lastTestedAt = DateTime.Now.AddDays(-daysAgo).AddHours(-rng.Next(0, 8));
var p = new Project
{
Name = name,
CreatedAt = lastTestedAt.AddMinutes(-rng.Next(20, 90)),
LastTestedAt = lastTestedAt,
Dut = new DutInfo
{
ProductName = "固态功率控制器",
Model = model,
SerialNumber = serial,
Manufacturer = manufacturer
},
Site = new TestSiteInfo
{
Tester = tester,
TestDate = testDate,
TemperatureC = temperatureC,
HumidityPct = humidityPct,
PressureKpa = pressureKpa,
Remark = remark
},
Selection = new TestSelection { Basic = true, Curve = true, Power = true, Protect = true },
Report = new ReportSelection { Cover = true, Basic = true, Curve = true, Power = true, Protect = true },
TestFunction = new TestFunctionNotes
{
Basic = "逐通道验证开合状态、导通电压、负载电流与关断残压。",
Curve = "采集通道开启及关断动态曲线,统计开启、上升、关断、下降时间。",
Power = "采集输入输出电压电流,计算压降、损耗功率与效率。",
Protect = "执行跳闸、短路、过温、过压、欠压及限流保护功能验证。"
},
CurveThresholds = new CurveThresholds
{
MaxOnTimeMs = 5.0,
MaxRiseTimeMs = 3.0,
MaxOffTimeMs = 5.0,
MaxFallTimeMs = 3.0
}
};
// 24 通道
int channels = 24;
for (int ch = 1; ch <= channels; ch++)
{
// 基础测试
var basic = new ChannelResult { Channel = ch };
basic.VoltageOn = Math.Round(27.78 + rng.NextDouble() * 0.38, 3);
basic.CurrentOn = Math.Round(0.96 + rng.NextDouble() * 0.055, 3);
basic.VoltageOff = Math.Round(rng.NextDouble() * 0.012, 3);
basic.Status = TestStatus.Pass;
p.BasicResults.Add(basic);
// 曲线测试
var curve = new CurveResultRow { Channel = ch };
curve.OnTimeMs = Math.Round(1.05 + rng.NextDouble() * 0.25, 3);
curve.RiseTimeMs = Math.Round(0.95 + rng.NextDouble() * 0.20, 3);
curve.OffTimeMs = Math.Round(1.08 + rng.NextDouble() * 0.22, 3);
curve.FallTimeMs = Math.Round(0.98 + rng.NextDouble() * 0.18, 3);
curve.Status = TestStatus.Pass;
p.CurveResults.Add(curve);
// 功率损耗
var pw = new PowerLossRow { Channel = ch };
pw.Vin = Math.Round(28.0 + (rng.NextDouble() - 0.5) * 0.06, 3);
pw.Iin = Math.Round(1.000 + (rng.NextDouble() - 0.5) * 0.012, 3);
pw.Vout = Math.Round(27.55 + (rng.NextDouble() - 0.5) * 0.06, 3);
pw.Iout = Math.Round(0.998 + (rng.NextDouble() - 0.5) * 0.012, 3);
pw.Status = TestStatus.Pass;
p.PowerResults.Add(pw);
}
// 保护功能6 项框架占位)
var protects = new (string Type, string Trigger)[]
{
("跳闸", "1.5x额定电流"),
("短路", "输出短路"),
("过温", ">=85 ℃"),
("过压", ">=32 V"),
("欠压", "<=22 V"),
("限流", ">=1.2 A"),
};
for (int i = 0; i < protects.Length; i++)
{
p.ProtectResults.Add(new ProtectRow
{
2026-07-02 17:43:32 +08:00
Index = i + 1,
ProtectType = protects[i].Type,
Trigger = protects[i].Trigger,
2026-07-02 17:43:32 +08:00
MeasuredValue = ProtectRow.BuildMeasuredValue(protects[i].Type, 28.0, 1.0),
JudgeMode = "人工判别",
TripTimeMs = Math.Round(2.0 + i * 0.3 + rng.NextDouble() * 0.2, 2),
Status = TestStatus.Pass
});
}
return p;
}
}