2024-01-25 13:37:12 +01:00
|
|
|
Script: *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
|
|
|
|
|
2024-03-27 17:36:59 +01:00
|
|
|
BOWLING RESULTS 2024
|
2023-09-01 17:53:03 +02:00
|
|
|
████████████████▏ 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-27 17:36:59 +01:00
|
|
|
Write-Host "`nBOWLING RESULTS 2024" -foregroundColor green
|
2023-09-01 17:53:03 +02:00
|
|
|
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
|
|
|
|
2024-08-15 09:51:46 +02:00
|
|
|
*(generated by convert-ps2md.ps1 using the comment-based help of write-chart.ps1 as of 08/15/2024 09:50:55)*
|