2024-10-01 15:24:16 +02:00
|
|
|
|
<#
|
2021-08-03 15:53:57 +02:00
|
|
|
|
.SYNOPSIS
|
2021-09-25 19:43:22 +02:00
|
|
|
|
Writes a chart
|
2021-10-04 21:29:23 +02:00
|
|
|
|
.DESCRIPTION
|
2023-08-24 13:40:28 +02:00
|
|
|
|
This PowerShell script writes an horizontal chart to the console.
|
2021-08-03 15:53:57 +02:00
|
|
|
|
.EXAMPLE
|
2023-08-24 13:40:28 +02:00
|
|
|
|
PS> ./write-chart.ps1
|
|
|
|
|
|
2024-03-23 10:58:14 +01:00
|
|
|
|
BOWLING RESULTS 2024
|
2023-08-24 13:40:28 +02:00
|
|
|
|
████████████████▏ 40.5% Joe
|
|
|
|
|
████████████▎ 30.9% Tom
|
2021-08-03 15:53:57 +02:00
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/fleschutz/PowerShell
|
2022-09-06 21:42:04 +02:00
|
|
|
|
.NOTES
|
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
2021-08-03 15:53:57 +02:00
|
|
|
|
#>
|
2021-06-01 16:44:28 +02:00
|
|
|
|
|
2021-06-01 17:55:00 +02:00
|
|
|
|
function WriteChartLine { param([string]$Text, [float]$Value, [float]$Max)
|
|
|
|
|
$Num = ($Value * 40.0) / $Max
|
2021-06-01 16:44:28 +02:00
|
|
|
|
while ($Num -ge 1.0) {
|
2023-08-24 13:40:28 +02:00
|
|
|
|
Write-Host -noNewLine "█"
|
2021-06-01 16:44:28 +02:00
|
|
|
|
$Num -= 1.0
|
|
|
|
|
}
|
|
|
|
|
if ($Num -ge 0.875) {
|
2023-08-24 13:40:28 +02:00
|
|
|
|
Write-Host -noNewLine "▉"
|
2021-06-01 16:44:28 +02:00
|
|
|
|
} elseif ($Num -ge 0.75) {
|
2023-08-24 13:40:28 +02:00
|
|
|
|
Write-Host -noNewLine "▊"
|
2021-06-01 16:44:28 +02:00
|
|
|
|
} elseif ($Num -ge 0.625) {
|
2023-08-24 13:40:28 +02:00
|
|
|
|
Write-Host -noNewLine "▋"
|
2021-06-01 16:44:28 +02:00
|
|
|
|
} elseif ($Num -ge 0.5) {
|
2023-08-24 13:40:28 +02:00
|
|
|
|
Write-Host -noNewLine "▌"
|
2021-06-01 16:44:28 +02:00
|
|
|
|
} elseif ($Num -ge 0.375) {
|
2023-08-24 13:40:28 +02:00
|
|
|
|
Write-Host -noNewLine "▍"
|
2021-06-01 16:44:28 +02:00
|
|
|
|
} elseif ($Num -ge 0.25) {
|
2023-08-24 13:40:28 +02:00
|
|
|
|
Write-Host -noNewLine "▎"
|
2021-06-01 16:44:28 +02:00
|
|
|
|
} elseif ($Num -ge 0.125) {
|
2023-08-24 13:40:28 +02:00
|
|
|
|
Write-Host -noNewLine "▏"
|
2021-06-01 16:44:28 +02:00
|
|
|
|
}
|
2021-06-01 17:55:00 +02:00
|
|
|
|
if ($Max -eq 100.0) {
|
2023-08-24 13:40:28 +02:00
|
|
|
|
Write-Host " $($Value)% $Text"
|
2021-06-01 17:55:00 +02:00
|
|
|
|
} else {
|
2023-08-24 13:40:28 +02:00
|
|
|
|
Write-Host " $Value / $Max $Text"
|
2021-06-01 17:55:00 +02:00
|
|
|
|
}
|
2021-06-01 16:44:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-23 10:58:14 +01:00
|
|
|
|
Write-Host "`nBOWLING RESULTS 2024" -foregroundColor green
|
2023-08-24 13:40:28 +02:00
|
|
|
|
WriteChartLine "Joe" 40.5 100.0
|
|
|
|
|
WriteChartLine "Tom" 30.9 100.0
|
2021-09-27 10:09:45 +02:00
|
|
|
|
exit 0 # success
|