/
disconnect.categories.sh
executable file
·93 lines (79 loc) · 2.29 KB
/
disconnect.categories.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
#!/usr/bin/env bash
set -e
setThesisBaseDirs(){
# TODO: share this function between scripts.
local projectRoot="$(cd -- "${BASH_SOURCE%/*}"; cd -- "$(git rev-parse --git-dir)/../"; echo "$PWD")"
# TODO: use http://gitslave.sourceforge.net/ instead?
local thesisBaseDir="$projectRoot/../"
local thesisBaseDirAbsolute=$(cd -- "$thesisBaseDir"; echo "$PWD")
heedlessBaseDir="$thesisBaseDirAbsolute/har-heedless/src"
dulcifyBaseDir="$thesisBaseDirAbsolute/har-dulcify/src"
}
setThesisBaseDirs
read -d '' mapData <<-'EOF' || true
def lookupMap(from; to):
(from | explode) as $from
| (to | explode) as $to
| ($from | length) as $length
| reduce range(0; $length) as $index (
{};
($from[$index:$index + 1] | implode) as $fromChar
| ($to[$index:$index + 1] | implode) as $toChar
| .[$fromChar] = $toChar
);
def mapOrSameCharacter(lookupMap):
. as $char
| lookupMap as $lookupMap
| if ($lookupMap | has($char)) then
$lookupMap[$char]
else
$char
end;
def stringToChars:
explode
| map([ . ] | implode);
def charsToString:
join("");
def mapOrSame(lookupMap):
lookupMap as $lookupMap
| stringToChars
| map(mapOrSameCharacter($lookupMap))
| charsToString;
def toUppercase:
lookupMap("abcdefghijklmnopqrstuvwxyz"; "ABCDEFGHIJKLMNOPQRSTUVWXYZ") as $alphabetLookupMap
| mapOrSame($alphabetLookupMap);
def toLowercase:
lookupMap("ABCDEFGHIJKLMNOPQRSTUVWXYZ"; "abcdefghijklmnopqrstuvwxyz") as $alphabetLookupMap
| mapOrSame($alphabetLookupMap);
def sort_by_string_caseinsensitive(property):
# Caches the converted { sortable: (property | toLowercase), value: . } for speedups?
sort_by(property | toLowercase);
. as $root
| $root."domains-per-category"
| with_entries(
.value |= {
"domains-per-category": .
}
)
| . * (
$root."organizations-per-category".count
| with_entries(
.value |= {
"organizations-per-category": .
}
)
)
| to_entries
| sort_by_string_caseinsensitive(.key)
EOF
read -d '' renameForTsvColumnOrdering <<-'EOF' || true
map(
{
"01--Category": .key,
"02--Domains": .value."domains-per-category",
"03--Organizations": .value."organizations-per-category",
}
)
EOF
# "prepared.disconnect.services.analysis.json"
cat | jq "$mapData" | jq "$renameForTsvColumnOrdering" | "$dulcifyBaseDir/util/array-of-objects-to-tsv.sh" | "$dulcifyBaseDir/util/clean-tsv-sorted-header.sh"