param( [string]$Root = (Join-Path $env:LOCALAPPDATA 'SSPCTester\Projects') ) $ErrorActionPreference = 'Stop' function New-ProjectData { param( [string]$Name, [string]$Serial, [string]$Model, [string]$Manufacturer, [string]$Tester, [int]$DaysAgo, [int]$Seed, [double]$TemperatureC, [double]$HumidityPct, [double]$PressureKpa, [string]$Remark ) $rng = [System.Random]::new($Seed) $createdAt = (Get-Date).Date.AddDays(-$DaysAgo).AddHours(9).AddMinutes($rng.Next(0, 45)) $lastTestedAt = $createdAt.AddHours(1).AddMinutes($rng.Next(10, 35)) $basicResults = @() $curveResults = @() $powerResults = @() for ($ch = 1; $ch -le 24; $ch++) { $basicResults += [ordered]@{ Channel = $ch VoltageOn = [Math]::Round(27.78 + $rng.NextDouble() * 0.38, 3) CurrentOn = [Math]::Round(0.96 + $rng.NextDouble() * 0.055, 3) VoltageOff = [Math]::Round($rng.NextDouble() * 0.012, 3) Status = 2 } $curveResults += [ordered]@{ Channel = $ch OnTimeMs = [Math]::Round(1.05 + $rng.NextDouble() * 0.25, 3) RiseTimeMs = [Math]::Round(0.95 + $rng.NextDouble() * 0.20, 3) OffTimeMs = [Math]::Round(1.08 + $rng.NextDouble() * 0.22, 3) FallTimeMs = [Math]::Round(0.98 + $rng.NextDouble() * 0.18, 3) RisingWaveformPath = $null FallingWaveformPath = $null Status = 2 } $powerResults += [ordered]@{ Channel = $ch Vin = [Math]::Round(28.0 + ($rng.NextDouble() - 0.5) * 0.06, 3) Iin = [Math]::Round(1.000 + ($rng.NextDouble() - 0.5) * 0.012, 3) Vout = [Math]::Round(27.55 + ($rng.NextDouble() - 0.5) * 0.06, 3) Iout = [Math]::Round(0.998 + ($rng.NextDouble() - 0.5) * 0.012, 3) Status = 2 } } $protects = @( @{ ProtectType = '跳闸'; Trigger = '1.5x额定电流' }, @{ ProtectType = '短路'; Trigger = '输出短路' }, @{ ProtectType = '过温'; Trigger = '>=85 ℃' }, @{ ProtectType = '过压'; Trigger = '>=32 V' }, @{ ProtectType = '欠压'; Trigger = '<=22 V' }, @{ ProtectType = '限流'; Trigger = '>=1.2 A' } ) $protectResults = @() for ($i = 0; $i -lt $protects.Count; $i++) { $protectResults += [ordered]@{ ProtectType = $protects[$i].ProtectType Trigger = $protects[$i].Trigger TripTimeMs = [Math]::Round(2.0 + $i * 0.3 + $rng.NextDouble() * 0.2, 2) Status = 2 } } [ordered]@{ Name = $Name CreatedAt = $createdAt LastTestedAt = $lastTestedAt Dut = [ordered]@{ ProductName = '固态功率控制器' Model = $Model SerialNumber = $Serial Manufacturer = $Manufacturer } Site = [ordered]@{ Tester = $Tester TestDate = (Get-Date).Date.AddDays(-$DaysAgo) TemperatureC = $TemperatureC HumidityPct = $HumidityPct PressureKpa = $PressureKpa Remark = $Remark } Selection = [ordered]@{ Basic = $true; Curve = $true; Power = $true; Protect = $true } Report = [ordered]@{ Cover = $true; Basic = $true; Curve = $true; Power = $true; Protect = $true; FileName = 'report.pdf' } TestFunction = [ordered]@{ Basic = '逐通道验证开合状态、导通电压、负载电流与关断残压。' Curve = '采集通道开启及关断动态曲线,统计开启、上升、关断、下降时间。' Power = '采集输入输出电压电流,计算压降、损耗功率与效率。' Protect = '执行跳闸、短路、过温、过压、欠压及限流保护功能验证。' } CurveThresholds = [ordered]@{ MaxOnTimeMs = 5.0; MaxRiseTimeMs = 3.0; MaxOffTimeMs = 5.0; MaxFallTimeMs = 3.0 } BasicResults = $basicResults CurveResults = $curveResults PowerResults = $powerResults ProtectResults = $protectResults } } function Get-SafeName([string]$Name) { $invalid = [IO.Path]::GetInvalidFileNameChars() -join ($Name.ToCharArray() | ForEach-Object { if ($invalid -contains $_) { '_' } else { $_ } }) } $projects = @( New-ProjectData ` -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 路基础、曲线、功率及保护功能测试,综合判定合格。' New-ProjectData ` -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 '低温启动后完成全通道闭合、关断、动态响应与保护功能复核,全部项目合格。' New-ProjectData ` -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 路输出特性、时序曲线、功率损耗及六项保护,结果均满足判定阈值。' ) New-Item -ItemType Directory -Path $Root -Force | Out-Null foreach ($project in $projects) { $folder = Join-Path $Root (Get-SafeName $project.Name) New-Item -ItemType Directory -Path $folder -Force | Out-Null New-Item -ItemType Directory -Path (Join-Path $folder 'curves') -Force | Out-Null $json = $project | ConvertTo-Json -Depth 8 Set-Content -LiteralPath (Join-Path $folder 'project.json') -Value $json -Encoding UTF8 Write-Host "[OK] $($project.Name) -> $folder" } Write-Host "Done. $($projects.Count) qualified projects written to: $Root"