Skip to content

Commit e961889

Browse files
committed
[delta_q] add jq scripts for reading Haskell JSON output
1 parent a90fd72 commit e961889

File tree

4 files changed

+92
-0
lines changed

4 files changed

+92
-0
lines changed

delta_q/docs/cluster_coeff.jq

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# attempt to find triangles in the network graph produced by the Haskell simulation of Praos
2+
3+
[.[]|.[0]] as $links |
4+
range(1000) |
5+
. as $i |
6+
[$i,
7+
(
8+
[$links[]|select(contains([$i]))|.[]|select(. != $i)] | unique |
9+
. as $peers |
10+
length as $l |
11+
# count the number of pairs of peers that are connected
12+
reduce range($l) as $j (0; . + (reduce range($j + 1;$l) as $k (0; . + (if ($links[]|contains([[$peers[$j],$peers[$k]]])) then 0 else 1 end)))) |
13+
[$l, .]
14+
)
15+
]

delta_q/docs/convert_arrivals.jq

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
def format: . * 10000 | round / 10000 | tostring;
2+
3+
.stable_chain_hashes as $stable |
4+
.entries[] |
5+
.created as $t0 | .hash as $hash |
6+
.arrivals | length as $l |
7+
select($l == 1000 and ($stable|contains([$hash]))) |
8+
sort |
9+
[
10+
foreach .[]
11+
as $p
12+
(
13+
0;
14+
.+1;
15+
[(($p-$t0)|format), (./$l|format)]
16+
)
17+
] |
18+
reverse |
19+
[
20+
# keep only the last value for each time
21+
foreach .[] as $p ([0]; [$p[0], .[0]]; if .[0] != .[1] then "("+$p[0]+", "+$p[1]+")" else null end) |
22+
select(type == "string")
23+
] |
24+
reverse
25+
|
26+
"CDF[" + join(", ") + "]"

delta_q/docs/latencies.jq

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# This script reads a JSON file from the Haskell simulation of Praos
2+
# and extracts the inter-node latencies from the network graph definition.
3+
4+
# usage: jq -srf latencies.jq <json_file>
5+
6+
# half of the latencies are "near" (and thus quick) the other half are "far" (and thus slower)
7+
[.[]|.[1]] | sort |
8+
["near", [.[range(0;length/2)]]], ["far", [.[range(length/2;length)]]] |
9+
.[0] as $name |
10+
.[1] |
11+
length as $l | . as $v |
12+
range(1;10) | . as $mult |
13+
[
14+
foreach $v[] as $i (0;
15+
.+1;
16+
if .%100==0 or .==$l then [$i*$mult, ./$l] else null end) |
17+
select(.)
18+
] |
19+
reverse |
20+
[
21+
# keep only the last value for each time
22+
foreach .[] as $p ([0]; [$p[0], .[0]]; if .[0] != .[1] then "("+($p[0]|tostring)+", "+($p[1]|tostring)+")" else null end) |
23+
select(type == "string")
24+
] |
25+
reverse |
26+
"send" + ($mult|tostring) + $name + " := CDF[" + join(", ") + "]"

delta_q/docs/praos_diffusion.sh

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
# usage: praos_diffusion.sh <json_file>
4+
5+
# Reads a JSON output file from the Haskell simulation of Praos,
6+
# converts the arrival times of each block into a CDF,
7+
# and outputs the CDFs in a format suitable for the web app.
8+
9+
# The individual traces are considered as representations of
10+
# different possible diffusion patterns and are thus combined
11+
# using the probabilistic choice operator.
12+
13+
jq -rf convert_arrivals.jq < "$1" |
14+
(
15+
while read CDF; do
16+
if [ -z "$RET" ]; then
17+
RET="$CDF"
18+
N=1
19+
else
20+
RET="$CDF\n1<>$N\n$RET"
21+
let N++
22+
fi
23+
done
24+
echo -e "$RET"
25+
)

0 commit comments

Comments
 (0)