From: Siraaj Khandkar Date: Mon, 21 Sep 2020 14:14:41 +0000 (-0400) Subject: Implement seq2dot X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=5ddd0980d506e9bb6ce1fe19932deeb52a17a079;p=khome.git Implement seq2dot graphing a sequence as pairs of prev->next relationships --- diff --git a/home/bin/seq2dot b/home/bin/seq2dot new file mode 100755 index 0000000..b79c8e4 --- /dev/null +++ b/home/bin/seq2dot @@ -0,0 +1,44 @@ +#! /usr/bin/awk -f +# +# Graph a sequence of lines as prev->next relationships, +# highlighting frequencies of pairings. +# + +BEGIN {print "digraph {"} + +{ + prev = prev ? prev : "--" + curr = $1 + ++nlinks[prev] + ++nlinks_to[prev, curr] + prev = curr +} + +END { + for (src_dst in nlinks_to) { + split(src_dst, sd, SUBSEP); + src = sd[1] + dst = sd[2] + m = nlinks[src] + n = nlinks_to[src, dst] + penwidth = num_scale(n, m, 1, 9) + color = sprintf("/orrd9/%d", num_scale(n, m, 2, 9)) + label = sprintf("%s %.2f%%", src, (n / m) * 100) + printf \ + "\"%s\" -> \"%s\" \ + [ label=\"%s\"\ + , fontname=monospace \ + , fontsize=8 \ + , penwidth=%d \ + , color=\"%s\" \ + , dir=both \ + , arrowtail=odot \ + ];\n", \ + src, dst, label, penwidth, color; + } + print "}" +} + +function num_scale(src_cur, src_max, dst_min, dst_max) { + return dst_min + ((src_cur * (dst_max - dst_min)) / src_max) +}