private/Compare-ProcessorsPerMarket.ps1
function Compare-ProcessorsPerMarket([Message[]] $core, [Message[]] $adapter, [string[]] $producers, [string] $progressMessage, [bool] $displayEqual){ $i=0; $j=0 $countEqual = 0; $countDiff = 0; $maxAdapter=0; $maxProvider=0 $items = @() while ($true){ #while (($i -lt $core.Count) -and -not ($core[$i].producer -in $producers)) { $i++ } # it there are no messages for compare, terminate if (($i -ge $core.Count) -and ($j -ge $adapter.Count)) { break } # compare message timestamps # TODO Timestamp reason to be checked if it is Refresh or Recovery while (($i -ge $core.Count) -or ($j -ge $adapter.Count) -or ($core[$i].uniqueIdentifier -ne $adapter[$j].uniqueIdentifier)){ while (($core[$i].other.reason -in ('Recovery', 'Refresh'))) { if ($j -ne 0) { $j--; break }} while (($adapter[$j].other.reason -in ('Recovery', 'Refresh'))) { if ($i -ne 0) { $i--; break }} while ($core[$i].message.event.isForced) { $i++; continue } while ($adapter[$j].message.event.isForced) { $i++; continue } if (($j -ge $adapter.Count) -or ($i -ge $core.Count)) { $reason='missing' } if (($j -ge $adapter.Count) -and -not ($i -ge $core.Count) -or ($core[$i].uniqueIdentifier -lt $adapter[$j].uniqueIdentifier)) { $countDiff++ $time = $core[$i].createdAt $messageId = $core[$i].id foreach ($market in $core[$i].event.markets) { $items += ([PSCustomObject]@{reason=$reason; sourceTime=''; targetTime=$time; sourceId=''; targetId=$messageId; sourceOdds=''; targetOdds=$market.OutcomesToString() }) } $i++ } elseif ($i -ge $core.Count -and -not ($j -ge $adapter.Count) -or ($adapter[$j].uniqueIdentifier -lt $core[$i].uniqueIdentifier)) { $countDiff++ $time = $adapter[$j].createdAt $messageId = $adapter[$j].id foreach ($market in $adapter[$j].event.markets) { $items += ([PSCustomObject]@{reason=$reason; sourceTime=$time; targetTime=''; sourceId=$messageId; ` targetId=''; sourceOdds=$market.OutcomesToString(); targetOdds='' }) } $j++ } else { break } $percentage = (100*($i+$j)/($core.Count + $adapter.Count)) Write-Progress -Activity $progressMessage -PercentComplete $percentage } if (($i -lt $core.Count) -and ($j -lt $adapter.Count)){ $core[$i].CalculatePerformance($adapter[$j].sourceType, $true, $true) $k = 0 # case when in the adapter there are multiple catalogs mapped with same definition while ($k -lt $core[$i].event.markets.Count) { $marketCore = $core[$i].event.markets[$k] $marketAdapter = $adapter[$j].event.markets[$k] if ($marketCore.Equal($marketAdapter, $false)){ $countEqual++ $reason = 'equal' } else { $countDiff++ $reason = 'odds' } if ($reason -ne 'equal' -or ($reason -eq 'equal' -and $displayEqual)){ $items += ([PSCustomObject]@{reason=$reason; ` sourceTime=$adapter[$j].createdAt; targetTime=$core[$i].createdAt; ` sourceId=$adapter[$j].id; targetId=$core[$i].id; ` sourceOdds=$marketAdapter.OutcomesToString(); targetOdds=$marketCore.OutcomesToString() }) } if (($core[$i].performance.travelFromAdapter + $core[$i].performance.processingAdapter) -gt $maxAdapter){ $maxAdapter = ($core[$i].performance.travelFromAdapter + $core[$i].performance.processingAdapter) } if ($core[$i].performance.total -gt $maxAdapter){ $maxProvider = $core[$i].performance.total } $k++ } $i++ $j++ } $percentage = (100*($i+$j)/($core.Count + $adapter.Count)) Write-Progress -Activity $progressMessage -PercentComplete $percentage } Write-Progress -Activity $progressMessage -Completed return ([PSCustomObject]@{same=$countSame; diff=$countDiff; maxAdapter=$maxAdapter; maxProvider=$maxProvider; items=$items}) } |