implement municipal election results

main
lub 10 months ago
parent 8ab8de132a
commit 903ab73788

@ -1,8 +1,15 @@
$partyMapping = @{
ARD = 'Blue'
ZDF = 'Orange'
'C&A' = 'Red'
}
[CmdletBinding()]
param (
[string]
$DataSource = './Gesamtergebnis-Gemeinderatswahl-2019_stripped.csv'
)
$data = Import-Csv $DataSource
$greenParty = ($data[0].PSObject.Properties.Name -like '*Grüne*')[0]
$partyMapping = $data | Where-Object Description -eq 'Color'
# nested array instead of hashtable, because hashtable keys are case-insensitive
$replacementList = @(
@ -16,13 +23,53 @@ $replacementList = @(
,('Elstarweg ','Elstarweg')
)
$featureList = Import-Csv ./data.csv
$featureList = Import-Csv ./polling_stations.csv
| Sort-Object -Unique Strassenname
| Group-Object {$_.Wahllokal1,$_.Wahllokal2,$_.Wahllokal3 -join ' '}
| Group-Object Concat
| ForEach-Object {
$pollingStation = $_
$party = ('ARD','ZDF','C&A' | Get-Random)
$electionResultObject = $data | Where-Object Description -eq $pollingStation.Name
if ($electionResultObject) {
# form into an array for easier handling and to preserve sorting
$electionResultArray = $electionResultObject.PSObject.Properties | ForEach-Object {
if ($_.Name -ne 'Description') {
[pscustomobject]@{
Party = $_.Name
ResultValue = [decimal](($_.Value -eq '-' ? 0 : $_.Value) -replace '%$')
Formatted = $_.Value
}
}
} | Sort-Object -Descending ResultValue
Write-Host $pollingStation.Name
$electionResultString = ($electionResultArray | ForEach-Object {
$_.Formatted + "`t" + $_.Party
}) -join "`n"
$greenResult = ($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
$weight = ($greenResult - 20) / 5 * 10 + 5
$weight = $weight -gt 15 ? 15 : $weight
$weight = $weight -lt 5 ? 5 : $weight
$party = $electionResultArray[0].Party
} else {
$electionResultString = 'no data available'
$opacity = 0.5
$party = $null
}
$umapOptiones = [PSCustomObject]@{
#color = ($using:partyMapping).$party
color = $partyMapping.$party ?? '#ff00ff'
weight = $weight
opacity = $opacity
}
$pollingStation.Group | ForEach-Object {
$street = $_.Strassenname
@ -30,7 +77,11 @@ $featureList = Import-Csv ./data.csv
$street = $street.Replace($replacement[0], $replacement[1])
}
$query = '
$description = $street
$description += "`n`n"
$description += $electionResultString
$query = @'
<osm-script>
<query into="_" type="area">
<has-kv k="name" modv="" v="Öhringen"/>
@ -44,7 +95,8 @@ $featureList = Import-Csv ./data.csv
<recurse type="way-node"/>
</union>
<print e="" from="_" geometry="skeleton" ids="yes" limit="" mode="body" n="" order="id" s="" w=""/>
</osm-script>' -f $street
</osm-script>
'@ -f $street
$overpassSplat = @{
Method = 'Post'
@ -70,13 +122,9 @@ $featureList = Import-Csv ./data.csv
[PSCustomObject]@{
type = 'Feature'
properties = [PSCustomObject]@{
_umap_options = [PSCustomObject]@{
#color = ($using:partyMapping).$party
color = $partyMapping.$party
weight = 10
}
_umap_options = $umapOptiones
name = $pollingStation.Name
description = $street
description = $description
}
geometry = [PSCustomObject]@{
type = 'LineString'

Loading…
Cancel
Save