This repository has been archived by the owner on Jun 1, 2021. It is now read-only.
/
erroneous-votes.sh
executable file
·93 lines (83 loc) · 1.95 KB
/
erroneous-votes.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
#set -e
# Extract votings with corrections, normalize the names of those with correctins, and list the worst "offenders".
now=$(date -u +%FT%TZ)
infile="${1:-"$PWD/ep_votes.json"}"
outdir="${2:-"$PWD/$now"}"
mkdir -p "$outdir"
echo "Current date: $now"
echo "Input ep_votes.json file: $infile"
echo "Output directory: $outdir"
# http://parltrack.euwiki.org/dumps/schema.html
# Select votings with at least one correction.
# Then select the relevant values, including all correction objects.
read -d '' getVotingsWithCorrectionals <<"EOF"
.
| map(select(
(
(
.Abstain.correctional | length
)
+ (
.Against.correctional | length
)
+ (
.For.correctional | length
)
) > 0
))
| map({
dossierid,
title,
ts,
abstain: {
total: .Abstain.total | tonumber,
correctional: .Abstain.correctional
},
against: {
total: .Against.total | tonumber,
correctional: .Against.correctional
},
for: {
total: .For.total | tonumber,
correctional: .For.correctional
}
})
EOF
# Normalize correction arrays of name strings or person objects, to only name strings.
# names(n) checks for null arrays, arrays that are person objects, or just name strings.
read -d '' cleanCorrectionalNameObjectArrays <<"EOF"
def names(n):
[
(
if n then
(
n[].orig // n[] // empty
)
else
empty
end
)
];
.
| map({
dossierid,
title,
ts,
abstain: {
total: .abstain.total,
names: names(.abstain.correctional)
},
against: {
total: .against.total,
names: names(.against.correctional)
},
for: {
total: .for.total,
names: names(.for.correctional)
}
})
EOF
<"$infile" jq "$getVotingsWithCorrectionals" > "$outdir/correctionals.json"
<"$outdir/correctionals.json" jq "$cleanCorrectionalNameObjectArrays" > "$outdir/correctionals.name-strings.json"
<"$outdir/correctionals.name-strings.json" jq '.[] | .abstain.names + .against.names + .for.names | .[]' | grep --invert-match '\[\]' | sort | uniq -c | sort -n > "$outdir/worst-offenders.json"