From ef4013c9852c523436df3d2f07d56eccd99aaba1 Mon Sep 17 00:00:00 2001 From: Dirk Date: Sun, 8 Sep 2019 17:46:26 +0100 Subject: [PATCH 1/3] Added pipeline functionality and made minor fixes --- Statistics/Add-Bar.ps1 | 45 ++++++----------- Statistics/Get-Histogram.ps1 | 38 ++++++++++----- Statistics/Measure-Object.ps1 | 48 +++++++++++-------- Statistics/Show-Measurement.ps1 | 46 +++++++++--------- Statistics/Statistics.psd1 | 28 +++++------ Tests/Add-Bar.Tests.ps1 | 14 +++--- .../ConvertFrom-PerformanceCounter.Tests.ps1 | 2 +- Tests/Expand-DateTime.Tests.ps1 | 2 +- Tests/Get-Histogram.Tests.ps1 | 3 +- Tests/Get-SlidingAverage.Tests.ps1 | 2 +- Tests/Show-Measurement.Tests.ps1 | 5 +- 11 files changed, 119 insertions(+), 114 deletions(-) diff --git a/Statistics/Add-Bar.ps1 b/Statistics/Add-Bar.ps1 index 4bbb18e..70b6b6e 100644 --- a/Statistics/Add-Bar.ps1 +++ b/Statistics/Add-Bar.ps1 @@ -4,7 +4,7 @@ [Parameter(Mandatory, ValueFromPipeline)] [ValidateNotNullOrEmpty()] [array] - $InputObject + $Data , [Parameter()] [ValidateNotNullOrEmpty()] @@ -17,46 +17,29 @@ $Width = $( if ($Host.UI.RawUI.MaxWindowSize.Width) { $Host.UI.RawUI.MaxWindowSize.Width - 30 } else { 50 } ) ) - Begin { - Write-Verbose ('[{0}] Initializing' -f $MyInvocation.MyCommand) - - $ValueFromParameter = $PSBoundParameters.ContainsKey('InputObject') - $Data = New-Object -TypeName System.Collections.ArrayList - } - - Process { - if ($ValueFromParameter) { - $Data = $InputObject - foreach ($_ in $Data) { - if (-Not (Get-Member -InputObject $_ -MemberType Properties -Name $Property)) { - throw ('Input object does not contain a property called <{0}>.' -f $Property) - } - } - - } else { - Write-Verbose ('[{0}] Processing {1} items' -f $MyInvocation.MyCommand, $InputObject.Length) - - $InputObject | ForEach-Object { - if (-Not (Get-Member -InputObject $_ -MemberType Properties -Name $Property)) { - throw ('Input object does not contain a property called <{0}>.' -f $Property) - } - [void]$Data.Add($_) + End { + # If the argument for the Data parameter was not provided via pipeline set the input to the provided argument + # otherwise use the automatic Input variable + if (!$PSCmdlet.MyInvocation.ExpectingInput) { + $Input = $Data + } + foreach ($_ in $Input) { + if (-Not (Get-Member -InputObject $_ -MemberType Properties -Name $Property)) { + throw ('Input object does not contain a property called <{0}>.' -f $Property) } } - } - - End { + Write-Verbose ('[{0}] Adding bars for width {1}' -f $MyInvocation.MyCommand, $Width) - $Count = $Data | Microsoft.PowerShell.Utility\Measure-Object -Maximum -Property $Property | Select-Object -ExpandProperty Maximum + $Count = $Input| Microsoft.PowerShell.Utility\Measure-Object -Maximum -Property $Property | Select-Object -ExpandProperty Maximum Write-Debug ('[{0}] Maximum value is {1}. This value will be {2} characters long.' -f $MyInvocation.MyCommand, $Count, $Width) - $Bars = foreach ($_ in $Data) { + $Bars = foreach ($_ in $Input) { $RelativeCount = [math]::Round($_.$Property / $Count * $Width, 0) Write-Debug ('[{0}] Value of {1} will be displayed using {2} characters.' -f $MyInvocation.MyCommand, $_.Property, $RelativeCount) Write-Debug ('[{0}] Adding member to input object.' -f $MyInvocation.MyCommand) - $Item = $_ | Select-Object -Property Index,Count,$Property | Add-Member -MemberType NoteProperty -Name Bar -Value ('#' * $RelativeCount) -PassThru + $Item = $_ | Select-Object -Property Index, $Property | Add-Member -MemberType NoteProperty -Name Bar -Value ('#' * $RelativeCount) -PassThru Write-Debug ('[{0}] Adding type name to output object.' -f $MyInvocation.MyCommand) $Item.PSTypeNames.Insert(0, 'HistogramBar') diff --git a/Statistics/Get-Histogram.ps1 b/Statistics/Get-Histogram.ps1 index 6c290dd..1dfb2cf 100644 --- a/Statistics/Get-Histogram.ps1 +++ b/Statistics/Get-Histogram.ps1 @@ -1,7 +1,7 @@ function Get-Histogram { - [CmdletBinding(DefaultParameterSetName='BucketCount')] + [CmdletBinding(DefaultParameterSetName = 'BucketCount')] Param( - [Parameter(Mandatory)] + [Parameter(Mandatory, ValueFromPipeline)] [ValidateNotNullOrEmpty()] [array] $Data @@ -33,13 +33,22 @@ [float] $BucketCount ) - - Process { + Begin { + # Define default display properties + $ddps = New-Object System.Management.Automation.PSPropertySet('DefaultDisplayPropertySet', [string[]]('Index', 'Count', 'lowerBound', 'upperBound')) + $PSStandardMembers = [System.Management.Automation.PSMemberInfo[]]$ddps + } + End { Write-Verbose ('[{0}] Building histogram' -f $MyInvocation.MyCommand) - - Write-Debug ('[{0}] Retrieving measurements from upstream cmdlet for {1} values' -f $MyInvocation.MyCommand, $Data.Count) + # If the argument for the Data parameter was not provided via pipeline set the input to the provided argument + # otherwise use the automatic Input variable + if (!$PSCmdlet.MyInvocation.ExpectingInput) { + $Input = $Data + } + Write-Debug ('[{0}] Retrieving measurements from upstream cmdlet for {1} values' -f $MyInvocation.MyCommand, $Input.Count) Write-Progress -Activity 'Measuring data' - $Stats = $Data | Microsoft.PowerShell.Utility\Measure-Object -Minimum -Maximum -Property $Property + + $Stats = $Input | Microsoft.PowerShell.Utility\Measure-Object -Minimum -Maximum -Property $Property if (-Not $PSBoundParameters.ContainsKey('Minimum')) { $Minimum = $Stats.Minimum @@ -64,7 +73,7 @@ [pscustomobject]@{ Index = $_ lowerBound = $Minimum + ($_ - 1) * $BucketWidth - upperBound = $Minimum + $_ * $BucketWidth + upperBound = $Minimum + $_ * $BucketWidth Count = 0 RelativeCount = 0 Group = New-Object -TypeName System.Collections.ArrayList @@ -74,10 +83,10 @@ Write-Debug ('[{0}] Building histogram' -f $MyInvocation.MyCommand) $DataIndex = 1 - foreach ($_ in $Data) { + foreach ($_ in $Input) { $Value = $_.$Property - Write-Progress -Activity 'Filling buckets' -PercentComplete ($DataIndex / $Data.Count * 100) + Write-Progress -Activity 'Filling buckets' -PercentComplete ($DataIndex / $Input.Count * 100) if ($Value -ge $Minimum -and $Value -le $Maximum) { $BucketIndex = [math]::Floor(($Value - $Minimum) / $BucketWidth) @@ -91,14 +100,19 @@ ++$DataIndex } - Write-Debug ('[{0}] Adding relative count' -f $MyInvocation.MyCommand) + Write-Debug ('[{0}] Adding relative count and default properties' -f $MyInvocation.MyCommand) foreach ($_ in $Buckets) { + # Add an type name to make the default properties work + [void]$_.PSObject.TypeNames.Insert(0, 'Statistics.Buckets') + # Attach default display property set + Add-Member -InputObject $_ -MemberType MemberSet -Name PSStandardMembers -Value $PSStandardMembers $_.RelativeCount = if ($OverallCount -gt 0) { $_.Count / $OverallCount } else { 0 } } Write-Debug ('[{0}] Returning histogram' -f $MyInvocation.MyCommand) $Buckets + } } -New-Alias -Name gh -Value Get-Histogram -Force \ No newline at end of file +New-Alias -Name ghist -Value Get-Histogram -Force \ No newline at end of file diff --git a/Statistics/Measure-Object.ps1 b/Statistics/Measure-Object.ps1 index 42de1c7..2534ecc 100644 --- a/Statistics/Measure-Object.ps1 +++ b/Statistics/Measure-Object.ps1 @@ -1,7 +1,7 @@ function Measure-Object { [CmdletBinding()] Param( - [Parameter(Mandatory)] + [Parameter(Mandatory, ValueFromPipeline)] [ValidateNotNullOrEmpty()] [array] $Data @@ -12,37 +12,43 @@ $Property ) - Process { + End { #region Percentiles require sorted data - $Data = $Data | Sort-Object -Property $Property + # If the argument for the Data parameter was not provided via pipeline set the input to the provided argument + # otherwise use the automatic Input variable + if (!$PSCmdlet.MyInvocation.ExpectingInput) { + $Input = $Data + } + $Input = $Input | Sort-Object -Property $Property #endregion #region Grab basic measurements from upstream Measure-Object - $Stats = $Data | Microsoft.PowerShell.Utility\Measure-Object -Property $Property -Minimum -Maximum -Sum -Average + $Stats = $Input | Microsoft.PowerShell.Utility\Measure-Object -Property $Property -Minimum -Maximum -Sum -Average #endregion #region Calculate median - Write-Debug ('[{0}] Number of data items is <{1}>' -f $MyInvocation.MyCommand.Name, $Data.Count) - if ($Data.Count % 2 -eq 0) { + Write-Debug ('[{0}] Number of data items is <{1}>' -f $MyInvocation.MyCommand.Name, $Input.Count) + if ($Input.Count % 2 -eq 0) { Write-Debug ('[{0}] Even number of data items' -f $MyInvocation.MyCommand.Name) - $MedianIndex = ($Data.Count / 2) - 1 + $MedianIndex = ($Input.Count / 2) - 1 Write-Debug ('[{0}] Index of Median is <{1}>' -f $MyInvocation.MyCommand.Name, $MedianIndex) - $LowerMedian = $Data[$MedianIndex] | Select-Object -ExpandProperty $Property - $UpperMedian = $Data[$MedianIndex + 1] | Select-Object -ExpandProperty $Property + $LowerMedian = $Input[$MedianIndex] | Select-Object -ExpandProperty $Property + $UpperMedian = $Input[$MedianIndex + 1] | Select-Object -ExpandProperty $Property Write-Debug ('[{0}] Lower Median is <{1}> and upper Median is <{2}>' -f $MyInvocation.MyCommand.Name, $LowerMedian, $UpperMedian) $Median = ([double]$LowerMedian + [double]$UpperMedian) / 2 Write-Debug ('[{0}] Average of lower and upper Median is <{1}>' -f $MyInvocation.MyCommand.Name, $Median) - } else { + } + else { Write-Debug ('[{0}] Odd number of data items' -f $MyInvocation.MyCommand.Name) - $MedianIndex = [math]::Ceiling(($Data.Count - 1) / 2) + $MedianIndex = [math]::Ceiling(($Input.Count - 1) / 2) Write-Debug ('[{0}] Index of Median is <{1}>' -f $MyInvocation.MyCommand.Name, $MedianIndex) - $Median = $Data[$MedianIndex] | Select-Object -ExpandProperty $Property + $Median = $Input[$MedianIndex] | Select-Object -ExpandProperty $Property Write-Debug ('[{0}] Median is <{1}>' -f $MyInvocation.MyCommand.Name, $Median) } Add-Member -InputObject $Stats -MemberType NoteProperty -Name 'Median' -Value $Median @@ -50,7 +56,7 @@ #region Calculate variance $Variance = 0 - foreach ($_ in $Data) { + foreach ($_ in $Input) { $Variance += [math]::Pow($_.$Property - $Stats.Average, 2) / $Stats.Count } $Variance /= $Stats.Count @@ -63,14 +69,14 @@ #endregion #region Calculate percentiles - $Percentile10Index = [math]::Ceiling(10 / 100 * $Data.Count) - $Percentile25Index = [math]::Ceiling(25 / 100 * $Data.Count) - $Percentile75Index = [math]::Ceiling(75 / 100 * $Data.Count) - $Percentile90Index = [math]::Ceiling(90 / 100 * $Data.Count) - Add-Member -InputObject $Stats -MemberType NoteProperty -Name 'Percentile10' -Value $Data[$Percentile10Index].$Property - Add-Member -InputObject $Stats -MemberType NoteProperty -Name 'Percentile25' -Value $Data[$Percentile25Index].$Property - Add-Member -InputObject $Stats -MemberType NoteProperty -Name 'Percentile75' -Value $Data[$Percentile75Index].$Property - Add-Member -InputObject $Stats -MemberType NoteProperty -Name 'Percentile90' -Value $Data[$Percentile90Index].$Property + $Percentile10Index = [math]::Ceiling(10 / 100 * $Input.Count) + $Percentile25Index = [math]::Ceiling(25 / 100 * $Input.Count) + $Percentile75Index = [math]::Ceiling(75 / 100 * $Input.Count) + $Percentile90Index = [math]::Ceiling(90 / 100 * $Input.Count) + Add-Member -InputObject $Stats -MemberType NoteProperty -Name 'Percentile10' -Value $Input[$Percentile10Index].$Property + Add-Member -InputObject $Stats -MemberType NoteProperty -Name 'Percentile25' -Value $Input[$Percentile25Index].$Property + Add-Member -InputObject $Stats -MemberType NoteProperty -Name 'Percentile75' -Value $Input[$Percentile75Index].$Property + Add-Member -InputObject $Stats -MemberType NoteProperty -Name 'Percentile90' -Value $Input[$Percentile90Index].$Property #endregion #region Calculate Tukey's range for outliers diff --git a/Statistics/Show-Measurement.ps1 b/Statistics/Show-Measurement.ps1 index 19258b7..c5790e3 100644 --- a/Statistics/Show-Measurement.ps1 +++ b/Statistics/Show-Measurement.ps1 @@ -1,54 +1,54 @@ function Show-Measurement { [CmdletBinding()] Param( - [Parameter(Mandatory)] + [Parameter(Mandatory, ValueFromPipeline)] [ValidateNotNullOrEmpty()] [object] - $InputObject + $Data , [Parameter()] [ValidateNotNullOrEmpty()] [int] - $Width = $( if ($Host.UI.RawUI.MaxWindowSize.Width) { $Host.UI.RawUI.MaxWindowSize.Width - 10 } else { 90 } ) + $Width = $( if ($Host.UI.RawUI.MaxWindowSize.Width) { $Host.UI.RawUI.MaxWindowSize.Width - 25 } else { 90 } ) , [switch] $PassThru ) - Process { + End { #region Generate visualization of measurements - $AvgSubDevIndex = [math]::Round(($InputObject.Average - $InputObject.StandardDeviation) / $InputObject.Maximum * $Width, 0) - $AvgIndex = [math]::Round( $InputObject.Average / $InputObject.Maximum * $Width, 0) - $AvgAddDevIndex = [math]::Round(($InputObject.Average + $InputObject.StandardDeviation) / $InputObject.Maximum * $Width, 0) - $AvgSubConfIndex = [math]::Round(($InputObject.Average - $InputObject.Confidence95) / $InputObject.Maximum * $Width, 0) - $AvgAddConfIndex = [math]::Round(($InputObject.Average + $InputObject.Confidence95) / $InputObject.Maximum * $Width, 0) - $MedIndex = [math]::Round( $InputObject.Median / $InputObject.Maximum * $Width, 0) - $P10Index = [math]::Round( $InputObject.Percentile10 / $InputObject.Maximum * $Width, 0) - $P25Index = [math]::Round( $InputObject.Percentile25 / $InputObject.Maximum * $Width, 0) - $P75Index = [math]::Round( $InputObject.Percentile75 / $InputObject.Maximum * $Width, 0) - $P90Index = [math]::Round( $InputObject.Percentile90 / $InputObject.Maximum * $Width, 0) - $P25SubTukIndex = [math]::Round(($InputObject.Percentile25 - $InputObject.TukeysRange) / $InputObject.Maximum * $Width, 0) - $P75AddTukIndex = [math]::Round(($InputObject.Percentile75 + $InputObject.TukeysRange) / $InputObject.Maximum * $Width, 0) + $AvgSubDevIndex = [math]::Round(($Data.Average - $Data.StandardDeviation) / $Data.Maximum * $Width, 0) + $AvgIndex = [math]::Round( $Data.Average / $Data.Maximum * $Width, 0) + $AvgAddDevIndex = [math]::Round(($Data.Average + $Data.StandardDeviation) / $Data.Maximum * $Width, 0) + $AvgSubConfIndex = [math]::Round(($Data.Average - $Data.Confidence95) / $Data.Maximum * $Width, 0) + $AvgAddConfIndex = [math]::Round(($Data.Average + $Data.Confidence95) / $Data.Maximum * $Width, 0) + $MedIndex = [math]::Round( $Data.Median / $Data.Maximum * $Width, 0) + $P10Index = [math]::Round( $Data.Percentile10 / $Data.Maximum * $Width, 0) + $P25Index = [math]::Round( $Data.Percentile25 / $Data.Maximum * $Width, 0) + $P75Index = [math]::Round( $Data.Percentile75 / $Data.Maximum * $Width, 0) + $P90Index = [math]::Round( $Data.Percentile90 / $Data.Maximum * $Width, 0) + $P25SubTukIndex = [math]::Round(($Data.Percentile25 - $Data.TukeysRange) / $Data.Maximum * $Width, 0) + $P75AddTukIndex = [math]::Round(($Data.Percentile75 + $Data.TukeysRange) / $Data.Maximum * $Width, 0) Write-Debug "P10=$P10Index P25=$P25Index A=$AvgIndex M=$MedIndex sA=$AvgSubDevIndex As=$AvgAddDevIndex cA=$AvgSubConfIndex aC=$AvgAddConfIndex o=$P25SubTukIndex O=$P75AddTukIndex P75=$P75Index P90=$P90Index" $graph = @() $graph += 'Range : ' + '---------|' * ($Width / 10) - $graph += '10% Percentile : ' + ' ' * $P10Index + 'P10' - $graph += '25% Percentile : ' + ' ' * $P25Index + 'P25' - $graph += 'Average : ' + ' ' * $AvgIndex + 'A' + $graph += '10% Percentile : ' + ' ' * $P10Index + 'P10' + $graph += '25% Percentile : ' + ' ' * $P25Index + 'P25' + $graph += 'Average : ' + ' ' * $AvgIndex + 'A' $graph += 'Standard Deviation: ' + (New-RangeString -Width $Width -LeftIndex $AvgSubDevIndex -RightIndex $AvgAddDevIndex -LeftIndicator 's' -RightIndicator 'S') $graph += '95% Confidence : ' + (New-RangeString -Width $Width -LeftIndex $AvgSubConfIndex -RightIndex $AvgAddConfIndex -LeftIndicator 'c' -RightIndicator 'C') $graph += 'Tukeys Range : ' + (New-RangeString -Width $Width -LeftIndex $P25SubTukIndex -RightIndex $P75AddTukIndex -LeftIndicator 'o' -RightIndicator 'O') - $graph += 'Median : ' + ' ' * $MedIndex + 'M' - $graph += '75% Percentile : ' + ' ' * $P75Index + 'P75' - $graph += '90% Percentile : ' + ' ' * $P90Index + 'P90' + $graph += 'Median : ' + ' ' * $MedIndex + 'M' + $graph += '75% Percentile : ' + ' ' * $P75Index + 'P75' + $graph += '90% Percentile : ' + ' ' * $P90Index + 'P90' $graph += 'Range : ' + '---------|' * ($Width / 10) #endregion #region Return graph if ($PassThru) { - $InputObject + $Data } Write-Host ($graph -join "`n") #endregion diff --git a/Statistics/Statistics.psd1 b/Statistics/Statistics.psd1 index 421b94e..598ed07 100644 --- a/Statistics/Statistics.psd1 +++ b/Statistics/Statistics.psd1 @@ -1,17 +1,17 @@ @{ - RootModule = 'Statistics.psm1' - ModuleVersion = '1.2.0' - GUID = 'd5add589-39c5-4f5a-a200-ba8258085bc9' - Author = 'Nicholas Dille' + RootModule = 'Statistics.psm1' + ModuleVersion = '1.2.0' + GUID = 'd5add589-39c5-4f5a-a200-ba8258085bc9' + Author = 'Nicholas Dille' # CompanyName = '' - Copyright = '(c) 2017 Nicholas Dille. All rights reserved.' - Description = 'Statistical analysis of data in the console window. For example this module can generate a histogram (Get-Histogram) and visualize it (Add-Bar). It also provides several statistical properties of the input data (Measure-Object and Show-Measurement). Using Get-SlidingAverage, data can be analyzed in a pipeline in real-time.' + Copyright = '(c) 2017 Nicholas Dille. All rights reserved.' + Description = 'Statistical analysis of data in the console window. For example this module can generate a histogram (Get-Histogram) and visualize it (Add-Bar). It also provides several statistical properties of the input data (Measure-Object and Show-Measurement). Using Get-SlidingAverage, data can be analyzed in a pipeline in real-time.' PowerShellVersion = '5.0' - FunctionsToExport = @('Add-Bar','ConvertFrom-PerformanceCounter','ConvertFrom-PrimitiveType','Expand-DateTime','Get-Histogram','Get-InterarrivalTime','Get-SlidingAverage','Get-WeightedValue','Measure-Group','Measure-Object','Show-Measurement') - CmdletsToExport = '' + FunctionsToExport = @('New-RangeString', 'Get-ExampleTimeSeries', 'Add-Bar', 'ConvertFrom-PerformanceCounter', 'ConvertFrom-PrimitiveType', 'Expand-DateTime', 'Get-Histogram', 'Get-InterarrivalTime', 'Get-SlidingAverage', 'Get-WeightedValue', 'Measure-Group', 'Measure-Object', 'Show-Measurement') + CmdletsToExport = '' VariablesToExport = '' - AliasesToExport = @('ab','cfpc','cfpt','edt','gh','giat','gsa','gwv','mg','mo','sm') - FormatsToProcess = @( + AliasesToExport = @('ab', 'cfpc', 'cfpt', 'edt', 'ghist', 'giat', 'gsa', 'gwv', 'mg', 'mo', 'sm') + FormatsToProcess = @( 'HistogramBucket.Format.ps1xml' 'HistogramBar.Format.ps1xml' ) @@ -31,16 +31,16 @@ } ) #> - PrivateData = @{ + PrivateData = @{ PSData = @{ - Tags = @( + Tags = @( 'Math' 'Mathematics' 'Statistics' 'Histogram' ) - LicenseUri = 'https://github.com/nicholasdille/PowerShell-Statistics/blob/master/LICENSE' - ProjectUri = 'https://github.com/nicholasdille/PowerShell-Statistics' + LicenseUri = 'https://github.com/nicholasdille/PowerShell-Statistics/blob/master/LICENSE' + ProjectUri = 'https://github.com/nicholasdille/PowerShell-Statistics' ReleaseNotes = 'https://github.com/nicholasdille/PowerShell-Statistics/releases' } } diff --git a/Tests/Add-Bar.Tests.ps1 b/Tests/Add-Bar.Tests.ps1 index 75bb9d4..8134187 100644 --- a/Tests/Add-Bar.Tests.ps1 +++ b/Tests/Add-Bar.Tests.ps1 @@ -10,14 +10,14 @@ Import-Module -Name Statistics -Force -ErrorAction 'Stop' Describe 'Add-Bar' { It 'Produces bars from parameter' { - $data = Get-Process | Select-Object -Property Name,Id,WorkingSet64 - $bars = Add-Bar -InputObject $data -Property WorkingSet64 -Width 50 + $data = Get-Process | Select-Object -Property Name, Id, WorkingSet64 + $bars = Add-Bar -Data $data -Property WorkingSet64 -Width 50 $bars | ForEach-Object { $_.PSObject.Properties | Where-Object Name -eq 'Bar' | Select-Object -ExpandProperty Name | Should Be 'Bar' } } It 'Produces bars from pipeline' { - $data = Get-Process | Select-Object -Property Name,Id,WorkingSet64 + $data = Get-Process | Select-Object -Property Name, Id, WorkingSet64 $bars = $data | Add-Bar -Property WorkingSet64 -Width 50 $bars | ForEach-Object { $_.PSObject.Properties | Where-Object Name -eq 'Bar' | Select-Object -ExpandProperty Name | Should Be 'Bar' @@ -27,14 +27,14 @@ Describe 'Add-Bar' { $item = Get-Process | Add-Bar -Property WorkingSet64 -Width 50 | Select-Object -First 1 $item.PSTypeNames -contains 'HistogramBar' | Should Be $true } - It 'Has one bar of maximum width' { - $data = Get-Process | Select-Object -Property Name,Id,WorkingSet64 - $bars = Add-Bar -InputObject $data -Property WorkingSet64 -Width 50 + It 'Has one bar of maximum width bla' { + $data = Get-Process | Select-Object -Property Name, Id, WorkingSet64 + $bars = $data | Add-Bar -Property WorkingSet64 -Width 50 $bars | Where-Object { $_.Bar.Length -eq 50 } | Should Not Be $null } It 'Dies on missing property' { $data = 1..10 - { Add-Bar -InputObject $data -Property Value } | Should Throw + { Add-Bar -Data $data -Property Value } | Should Throw $data = 11..20 { $data | Add-Bar -Property Value } | Should Throw } diff --git a/Tests/ConvertFrom-PerformanceCounter.Tests.ps1 b/Tests/ConvertFrom-PerformanceCounter.Tests.ps1 index 4edc313..127dd33 100644 --- a/Tests/ConvertFrom-PerformanceCounter.Tests.ps1 +++ b/Tests/ConvertFrom-PerformanceCounter.Tests.ps1 @@ -14,7 +14,7 @@ Describe 'ConvertFrom-PerformanceCounter' { 'de-DE' { $Counter = '\Prozessor(_Total)\Prozessorzeit (%)' } - 'en-US' { + {$_ -like 'en-*'} { $Counter = '\Processor(_Total)\% Processor Time' } } diff --git a/Tests/Expand-DateTime.Tests.ps1 b/Tests/Expand-DateTime.Tests.ps1 index 9250c5f..70340fa 100644 --- a/Tests/Expand-DateTime.Tests.ps1 +++ b/Tests/Expand-DateTime.Tests.ps1 @@ -13,7 +13,7 @@ Describe 'Expand-DateTime' { 'de-DE' { $Counter = '\Prozessor(_Total)\Prozessorzeit (%)' } - 'en-US' { + {$_ -like 'en-*'} { $Counter = '\Processor(_Total)\% Processor Time' } } diff --git a/Tests/Get-Histogram.Tests.ps1 b/Tests/Get-Histogram.Tests.ps1 index 29bec7c..7198822 100644 --- a/Tests/Get-Histogram.Tests.ps1 +++ b/Tests/Get-Histogram.Tests.ps1 @@ -24,9 +24,10 @@ Describe 'Get-Histogram' { $histogram | Select-Object -First 1 -ExpandProperty lowerBound | Should Be 2 $histogram | Select-Object -Last 1 -ExpandProperty upperBound | Should Be 5 } + # can not get this working for some reason It 'Warns for large number of buckets' { $data = 1..110 | ConvertFrom-PrimitiveType - Mock Write-Warning {} + Mock Write-Warning { } Get-Histogram -Data $data -Property Value Assert-MockCalled -CommandName Write-Warning -Times 1 -Exactly } diff --git a/Tests/Get-SlidingAverage.Tests.ps1 b/Tests/Get-SlidingAverage.Tests.ps1 index 81b023e..aa31d8e 100644 --- a/Tests/Get-SlidingAverage.Tests.ps1 +++ b/Tests/Get-SlidingAverage.Tests.ps1 @@ -13,7 +13,7 @@ Describe 'Get-SlidingAverage' { 'de-DE' { $Counter = '\Prozessor(_Total)\Prozessorzeit (%)' } - 'en-US' { + {$_ -like 'en-*'} { $Counter = '\Processor(_Total)\% Processor Time' } } diff --git a/Tests/Show-Measurement.Tests.ps1 b/Tests/Show-Measurement.Tests.ps1 index 7639788..a0136ef 100644 --- a/Tests/Show-Measurement.Tests.ps1 +++ b/Tests/Show-Measurement.Tests.ps1 @@ -11,14 +11,15 @@ Import-Module -Name Statistics -Force -ErrorAction 'Stop' Describe 'Show-Measurement' { $data = 0..10 | ConvertFrom-PrimitiveType $stats = Measure-Object -Data $data -Property Value + # Could not get the mock working It 'Produces output' { Mock Write-Host {} - Show-Measurement -InputObject $stats + Show-Measurement -Data $stats Assert-MockCalled Write-Host -Scope It -Times 1 -Exactly } It 'Produces input object' { Mock Write-Host {} - $input = Show-Measurement -InputObject $stats -PassThru + $input = Show-Measurement -Data $stats -PassThru $input | Should Be $stats } } \ No newline at end of file From 80f9dcc3c0b88fd829d64ce5bb6f8dfc7ad57b5a Mon Sep 17 00:00:00 2001 From: Dirk Date: Tue, 10 Sep 2019 21:47:36 +0100 Subject: [PATCH 2/3] Update README.md --- README.md | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7dfc147..f27ee04 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,28 @@ | :------: | :-------: | :------: | | [![Build status](https://ci.appveyor.com/api/projects/status/e56ra8c3q1jtc19o?svg=true)](https://ci.appveyor.com/project/nicholasdille/powershell-statistics) | [![Coverage Status](https://coveralls.io/repos/github/nicholasdille/PowerShell-Statistics/badge.svg?branch=master)](https://coveralls.io/github/nicholasdille/PowerShell-Statistics?branch=master) | [![Download](https://img.shields.io/badge/powershellgallery-Statistics-blue.svg)](https://www.powershellgallery.com/packages/Statistics/) +# Changes as compared to original repository +Get-Histogram +- Added DefaultDisplayPropertySet (Index,Count,lowerBound,upperBound) +- Made function take input from pipeline (not processing by pipeline but just as syntactic sugar) +- Replaced arraylist "pipeline data collector" by automatic $Input variable +- Changed gh alias to ghist (collided with Get-Help for me) +- Cannot get the test "Honors minimum and maximum values" working (mock call to write-warning) + +Add-Bar +- Fixed double selection of Count property +- Changed name of InputObject to Data for consistency +- Replaced arraylist "pipeline data collector" by automatic $Input variable + +Measure-Object +- Made function take input from pipeline (not processing by pipeline but just as syntactic sugar) + +Show-Measurement +- Made function take input from pipeline (not processing by pipeline but just as syntactic sugar) +- Changed name of InputObject to Data for consistency +- Could not get the 'Produces output' test working (mock call to write-host) +- Decreased width to account for text in front of graph + # Introduction Statistical analysis @@ -229,4 +251,4 @@ Timestamp Value DayOfWeek Year Month Hour WeekOfYear # Credits -Build scripts based on [PSDeploy](https://github.com/RamblingCookieMonster/PSDeploy) by [Warren Frame](http://ramblingcookiemonster.github.io/) \ No newline at end of file +Build scripts based on [PSDeploy](https://github.com/RamblingCookieMonster/PSDeploy) by [Warren Frame](http://ramblingcookiemonster.github.io/) From 69e10c70829fa5167e6b68b82afc3238ff59857f Mon Sep 17 00:00:00 2001 From: Dirk Date: Tue, 10 Sep 2019 21:48:24 +0100 Subject: [PATCH 3/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f27ee04..e4db80c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | :------: | :-------: | :------: | | [![Build status](https://ci.appveyor.com/api/projects/status/e56ra8c3q1jtc19o?svg=true)](https://ci.appveyor.com/project/nicholasdille/powershell-statistics) | [![Coverage Status](https://coveralls.io/repos/github/nicholasdille/PowerShell-Statistics/badge.svg?branch=master)](https://coveralls.io/github/nicholasdille/PowerShell-Statistics?branch=master) | [![Download](https://img.shields.io/badge/powershellgallery-Statistics-blue.svg)](https://www.powershellgallery.com/packages/Statistics/) -# Changes as compared to original repository +### Changes as compared to original repository Get-Histogram - Added DefaultDisplayPropertySet (Index,Count,lowerBound,upperBound) - Made function take input from pipeline (not processing by pipeline but just as syntactic sugar)