Skip to content

Commit

Permalink
Add simple stats to correlation result processing script (#2229)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Flor Chacón authored Jun 10, 2022
1 parent 8b07a0e commit 7d86fc0
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions tools/CorrelationTestbed/Process-CorrelationResults.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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

0 comments on commit 7d86fc0

Please sign in to comment.