enet-validator/scripts/session/analyze_mute.ps1

70 lines
3.5 KiB
PowerShell
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[Console]::OutputEncoding = [Text.Encoding]::UTF8
$ErrorActionPreference = "Stop"
function H2B($hex) {
if (-not $hex) { return $null }
$n = $hex.Length / 2
$b = New-Object byte[] $n
for ($i = 0; $i -lt $n; $i++) { $b[$i] = [Convert]::ToByte($hex.Substring(2*$i, 2), 16) }
return $b
}
$lines = [IO.File]::ReadAllLines("$env:TEMP\opencode\ss123.tsv")
# 事件提取: 0003广播MUTE / 0002定向UNMUTE / 脉冲
$events = New-Object System.Collections.ArrayList
foreach ($l in $lines) {
$p = $l -split "`t"; if ($p.Count -lt 5 -or -not $p[4]) { continue }
$b = H2B $p[4]; if ($b.Length -lt 0x30) { continue }
$t = [double]$p[0]
if ($p[1] -eq "192.168.123.113" -and $p[2] -eq "192.168.123.1" -and [int]$b[4] -eq 4 -and $b.Length -gt 0x51 -and $b.Length -lt 2000 -and $b[0x20] -eq 2 -and $b[0x21] -eq 0 -and $b[0x30] -eq 0 -and $b[0x3C] -eq 1 -and $b[0x3D] -eq 0x18) {
$pid2 = "{0:x2}{1:x2}" -f $b[0x50], $b[0x51]
$uid = ($b[0x3E..0x43] | ForEach-Object { $_.ToString("x2") }) -join ""
if ($pid2 -eq "0003") { [void]$events.Add(@{ t=$t; kind="MUTE"; uid=$uid }) }
if ($pid2 -eq "0002") { [void]$events.Add(@{ t=$t; kind="UNMUTE"; uid=$uid }) }
}
if ($p[1] -eq "192.168.123.1" -and $p[2] -eq "192.168.123.113" -and $b.Length -lt 200 -and $b[0x2A] -eq 0xAA) {
# 解码脉冲 UID
$uid = ""
for ($i = 0; $i -lt 6; $i++) {
$b1 = $b[0x2B + 2*$i]; $b2 = $b[0x2C + 2*$i]
$byte = ([int]$b1 -band 0x55) -bor ([int]$b2 -band 0xAA)
$uid += $byte.ToString("x2")
}
[void]$events.Add(@{ t=$t; kind="PULSE"; uid=$uid })
}
}
$mutes = @($events | Where-Object { $_.kind -eq "MUTE" })
$unmutes = @($events | Where-Object { $_.kind -eq "UNMUTE" })
$pulses = @($events | Where-Object { $_.kind -eq "PULSE" })
Write-Host ("MUTE={0} UNMUTE={1} 脉冲={2}" -f $mutes.Count, $unmutes.Count, $pulses.Count)
# MUTE 时间点与脉冲静默窗口: 每个 MUTE 后 3s 内脉冲数 vs 3-15s 脉冲数
Write-Host "`n--- 广播 MUTE(0003) 时间点 vs 脉冲密度 ---"
foreach ($m in $mutes) {
$before = @($pulses | Where-Object { $_.t -ge $m.t - 3 -and $_.t -lt $m.t }).Count
$after3 = @($pulses | Where-Object { $_.t -ge $m.t -and $_.t -lt $m.t + 3 }).Count
$after12 = @($pulses | Where-Object { $_.t -ge $m.t + 3 -and $_.t -lt $m.t + 15 }).Count
Write-Host (" MUTE t={0,7:F2} 前3s脉冲={1,-3} 后0-3s={2,-3} 后3-15s={3}" -f $m.t, $before, $after3, $after12)
}
# UNMUTE 时间点 vs 其后脉冲 (同 UID)
Write-Host "`n--- 定向 UNMUTE(0002) vs 其后 1s 内同 UID 脉冲 ---"
foreach ($u in ($unmutes | Select-Object -First 10)) {
$same = @($pulses | Where-Object { $_.t -ge $u.t -and $_.t -lt $u.t + 1 -and $_.uid -eq $u.uid }).Count
$any = @($pulses | Where-Object { $_.t -ge $u.t -and $_.t -lt $u.t + 1 }).Count
Write-Host (" UNMUTE t={0,7:F2} UID={1} 后1s同UID脉冲={2} 任意={3}" -f $u.t, $u.uid, $same, $any)
}
# 脉冲的 UID 分布随时间 (每 15s 桶)
Write-Host "`n--- 脉冲 UID×15s 桶 ---"
$buckets = @{}
foreach ($pu in $pulses) {
$bk = [int]($pu.t / 15)
if (-not $buckets.ContainsKey($bk)) { $buckets[$bk] = @{} }
if (-not $buckets[$bk].ContainsKey($pu.uid)) { $buckets[$bk][$pu.uid] = 0 }
$buckets[$bk][$pu.uid]++
}
foreach ($bk in ($buckets.Keys | Sort-Object)) {
$s = ($buckets[$bk].GetEnumerator() | ForEach-Object { "$($_.Key.Substring(8))×$($_.Value)" }) -join " "
Write-Host (" t={0,3}-{1,-3}s: {2}" -f ($bk*15), ($bk*15+15), $s)
}