2023-07-29 10:34:04 +02:00
|
|
|
*write-chart.ps1*
|
|
|
|
================
|
2022-11-17 20:02:26 +01:00
|
|
|
|
|
|
|
write-chart.ps1
|
2021-10-17 14:33:27 +02:00
|
|
|
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Parameters
|
|
|
|
----------
|
2021-10-17 14:33:27 +02:00
|
|
|
```powershell
|
|
|
|
|
|
|
|
|
|
|
|
[<CommonParameters>]
|
|
|
|
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
|
|
|
|
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
|
|
|
|
```
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Script Content
|
|
|
|
--------------
|
2022-11-17 20:05:34 +01:00
|
|
|
```powershell
|
2022-11-17 20:02:26 +01:00
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Writes a chart
|
|
|
|
.DESCRIPTION
|
2023-09-01 17:53:03 +02:00
|
|
|
This PowerShell script writes an horizontal chart to the console.
|
2022-11-17 20:02:26 +01:00
|
|
|
.EXAMPLE
|
2023-09-01 17:53:03 +02:00
|
|
|
PS> ./write-chart.ps1
|
|
|
|
|
|
|
|
2023 BOWLING RESULTS
|
|
|
|
████████████████▏ 40.5% Joe
|
|
|
|
████████████▎ 30.9% Tom
|
2022-11-17 20:02:26 +01:00
|
|
|
.LINK
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
.NOTES
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
#>
|
|
|
|
|
|
|
|
function WriteChartLine { param([string]$Text, [float]$Value, [float]$Max)
|
|
|
|
$Num = ($Value * 40.0) / $Max
|
|
|
|
while ($Num -ge 1.0) {
|
2023-09-01 17:53:03 +02:00
|
|
|
Write-Host -noNewLine "█"
|
2022-11-17 20:02:26 +01:00
|
|
|
$Num -= 1.0
|
|
|
|
}
|
|
|
|
if ($Num -ge 0.875) {
|
2023-09-01 17:53:03 +02:00
|
|
|
Write-Host -noNewLine "▉"
|
2022-11-17 20:02:26 +01:00
|
|
|
} elseif ($Num -ge 0.75) {
|
2023-09-01 17:53:03 +02:00
|
|
|
Write-Host -noNewLine "▊"
|
2022-11-17 20:02:26 +01:00
|
|
|
} elseif ($Num -ge 0.625) {
|
2023-09-01 17:53:03 +02:00
|
|
|
Write-Host -noNewLine "▋"
|
2022-11-17 20:02:26 +01:00
|
|
|
} elseif ($Num -ge 0.5) {
|
2023-09-01 17:53:03 +02:00
|
|
|
Write-Host -noNewLine "▌"
|
2022-11-17 20:02:26 +01:00
|
|
|
} elseif ($Num -ge 0.375) {
|
2023-09-01 17:53:03 +02:00
|
|
|
Write-Host -noNewLine "▍"
|
2022-11-17 20:02:26 +01:00
|
|
|
} elseif ($Num -ge 0.25) {
|
2023-09-01 17:53:03 +02:00
|
|
|
Write-Host -noNewLine "▎"
|
2022-11-17 20:02:26 +01:00
|
|
|
} elseif ($Num -ge 0.125) {
|
2023-09-01 17:53:03 +02:00
|
|
|
Write-Host -noNewLine "▏"
|
2022-11-17 20:02:26 +01:00
|
|
|
}
|
|
|
|
if ($Max -eq 100.0) {
|
2023-09-01 17:53:03 +02:00
|
|
|
Write-Host " $($Value)% $Text"
|
2022-11-17 20:02:26 +01:00
|
|
|
} else {
|
2023-09-01 17:53:03 +02:00
|
|
|
Write-Host " $Value / $Max $Text"
|
2022-11-17 20:02:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-01 17:53:03 +02:00
|
|
|
Write-Host "`n2023 BOWLING RESULTS" -foregroundColor green
|
|
|
|
WriteChartLine "Joe" 40.5 100.0
|
|
|
|
WriteChartLine "Tom" 30.9 100.0
|
2022-11-17 20:02:26 +01:00
|
|
|
exit 0 # success
|
2022-11-17 20:05:34 +01:00
|
|
|
```
|
2022-11-17 20:02:26 +01:00
|
|
|
|
2023-09-13 09:49:05 +02:00
|
|
|
*(generated by convert-ps2md.ps1 using the comment-based help of write-chart.ps1 as of 09/13/2023 09:48:45)*
|