From 7d86fc0a229383a131d834009084e81604024a7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Flor=20Chac=C3=B3n?= Date: Fri, 10 Jun 2022 11:38:59 -0700 Subject: [PATCH] Add simple stats to correlation result processing script (#2229) This changes the script that processes correlation results to produce simple stats of how many packages were correlated successfully. This can be used to easily evaluate if the correlation heuristic is doing well. It also fixes an issue when running the script on powershell instead of pwsh, where a path join didn't use the full path and resulted in not being able to find the result JSON files. --- .../Process-CorrelationResults.ps1 | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/tools/CorrelationTestbed/Process-CorrelationResults.ps1 b/tools/CorrelationTestbed/Process-CorrelationResults.ps1 index 2860fb961c..7e1f4d1529 100644 --- a/tools/CorrelationTestbed/Process-CorrelationResults.ps1 +++ b/tools/CorrelationTestbed/Process-CorrelationResults.ps1 @@ -5,6 +5,7 @@ Param( $resultFile = Join-Path $ResultsPath "results.csv" $failedFile = Join-Path $ResultsPath "failed.csv" +$statsFile = Join-Path $ResultsPath "stats.json" if (Test-Path $resultFile) { @@ -16,22 +17,49 @@ if (Test-Path $failedFile) Remove-Item $failedFile -Force } +$stats = @{ + Total = 0 + Missing = 0 + Completed = 0 + Failed = 0 + CorrelatePackageKnown = 0 + CorrelateArchive = 0 +} + +# Aggregate results in a single CSV file foreach ($result in (Get-ChildItem $ResultsPath -Directory)) { - $resultJSON = Join-Path $result "install_and_correlate.json" - if (-not (Test-Path $resultJSON)) + $stats.Total++ + + $resultJSON = Join-Path $result.FullName "install_and_correlate.json" + if (Test-Path $resultJSON) { - continue + $resultObj = (Get-Content -Path $resultJSON -Encoding utf8 | ConvertFrom-Json) } - $resultObj = (Get-Content -Path $resultJSON -Encoding utf8 | ConvertFrom-Json) + if (-not $resultObj) + { + # Result JSON file does not exist or is empty + $stats.Missing++ + continue + } if ($resultObj.HRESULT -eq 0) { + $stats.Completed++ + $stats.CorrelateArchive += $resultObj.CorrelateArchive + $stats.CorrelatePackageKnown += $resultObj.CorrelatePackageKnown Export-Csv -InputObject ($resultObj | Select-Object -Property * -ExcludeProperty @("Error", "Phase", "Action", "HRESULT") ) -Path $resultFile -Append } else { + $stats.Failed++ Export-Csv -InputObject $resultObj -Path $failedFile -Append } } + +# Write some stats to a file for quick evaluation +$stats.CompletedRatio = $stats.Completed / $stats.Total +$stats.CorrelateArchiveRatio = $stats.CorrelateArchive / $stats.Completed +$stats.CorrelatePackageKnownRatio = $stats.CorrelatePackageKnown / $stats.Completed +$stats | ConvertTo-Json | Out-File $statsFile -Force