From 1eb674e5327d2308f2e38ea82e414a22597286e9 Mon Sep 17 00:00:00 2001 From: lub Date: Sun, 14 Jan 2024 21:14:17 +0100 Subject: [PATCH] display results as color and opacity gradient party colors were not really useful, when there are only two winning parties --- streets.ps1 | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/streets.ps1 b/streets.ps1 index 6934121..26e5856 100644 --- a/streets.ps1 +++ b/streets.ps1 @@ -50,7 +50,12 @@ $data = Import-Csv $DataSource $greenParty = ($data[0].PSObject.Properties.Name -like '*GrĂ¼ne*')[0] -$partyMapping = $data | Where-Object Description -eq 'Color' +$dataMeasure = $data.$greenParty +| Where-Object {$_ -match '%$'} +| ForEach-Object {$_ -replace '%$'} +| Measure-Object -Minimum -Maximum +$minimumResultValue = $dataMeasure.Minimum +$maximumResultValue = $dataMeasure.Maximum # nested array instead of hashtable, because hashtable keys are case-insensitive $replacementList = @( @@ -88,27 +93,21 @@ $featureList = Import-Csv ./polling_stations.csv $_.Formatted + "`t" + $_.Party }) -join "`n" - $greenResult = ($electionResultArray | Where-Object Party -eq $greenParty).ResultValue + $greenResultValue = ($electionResultArray | Where-Object Party -eq $greenParty).ResultValue - $opacity = ($greenResult - 20) / 5 * 0.6 + 0.4 - $opacity = $opacity -gt 1.0 ? 1.0 : $opacity - $opacity = $opacity -lt 0.4 ? 0.4 : $opacity + $colorGreen = (($greenResultValue - $minimumResultValue) * (100 - 220)) / ($maximumResultValue - $minimumResultValue) + 220 + $color = "rgb(0, $colorGreen, 0)" - $weight = ($greenResult - 20) / 5 * 10 + 5 - $weight = $weight -gt 15 ? 15 : $weight - $weight = $weight -lt 5 ? 5 : $weight - - $party = $electionResultArray[0].Party + $opacity = (($greenResultValue - $minimumResultValue) * (1.0 - 0.4)) / ($maximumResultValue - $minimumResultValue) + 0.4 } else { $electionResultString = 'no data available' $opacity = 0.5 - $party = $null + $color = '#ff00ff' } $umapOptiones = [PSCustomObject]@{ - #color = ($using:partyMapping).$party - color = $partyMapping.$party ?? '#ff00ff' - weight = $weight + color = $color + weight = 10 opacity = $opacity }