Created
July 29, 2022 20:29
-
-
Save bwbroersma/7ae3c6d2211a14220bb12343dc2529ab to your computer and use it in GitHub Desktop.
De 'is het electoraal logisch dat er ontbindingsverkiezingen komen'-AWK script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BEGIN { | |
FS=";"; | |
} | |
function abs(v) { | |
return v < 0 ? -v : v; | |
} | |
function cp(i1, v1, i2, v2) { | |
if (v1 > v2) | |
return -1; | |
else if (v1 == v2) | |
return 0; | |
else | |
return 1; | |
} | |
FNR != NR { | |
if (FNR == 1) next; | |
projected[toupper($1)] = $6; | |
next; | |
} | |
{ | |
name[toupper($1)] = $1; | |
seats[toupper($1)] = $2; | |
} | |
END { | |
for (j in projected) { | |
if (!(j in seats)) { | |
seats[j] = 0; | |
name[j] = j; | |
} | |
} | |
n = asorti(seats, dest, "cp"); | |
for (ii in dest) { | |
i = dest[ii]; | |
diff = projected[i] - seats[i]; | |
printf "%16s %#2i ⇒ %#2i ", name[i], seats[i], projected[i]; | |
if (diff == 0) { | |
print ""; | |
} else { | |
if (diff > 0) { | |
c = "\033[1;42m▲\033[0m"; | |
} else { | |
c = "\033[1;41m▼\033[0m"; | |
}; | |
printf "%-*s [%s%]\n", (16 + abs(diff) * 11), | |
gensub(/ /, c, "g", sprintf("%*s", abs(diff), "")), | |
seats[i] == 0 ? " + ∞ " : sprintf("%+#5i", diff * 100 / seats[i]); | |
}; | |
if (seats[i] < projected[i]) { | |
gt += seats[i]; | |
shift += diff; | |
} | |
if (seats[i] == projected[i]) eq += seats[i]; | |
if (seats[i] > projected[i]) lt += seats[i]; | |
} | |
printf "%#16s %#2i winnen %+#2i zetels, %#2i blijven gelijk, %#2i verliezen zetels.\n", | |
"Peilingwijzer:", gt, shift, eq, lt, loss; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See my twitter 🧵 thread.
Usable with: