Remove .txt extension from TODO
[khome.git] / home / bin / seq2dot
CommitLineData
5ddd0980
SK
1#! /usr/bin/awk -f
2#
3# Graph a sequence of lines as prev->next relationships,
4# highlighting frequencies of pairings.
5#
6
5ddd0980 7{
ddc68162 8 curr = $0
4f4a0353
SK
9}
10
11NR == 1 {
12 init = curr
13}
14
15NR > 1 {
5ddd0980
SK
16 ++nlinks[prev]
17 ++nlinks_to[prev, curr]
4f4a0353
SK
18}
19
20{
5ddd0980
SK
21 prev = curr
22}
23
24END {
4f4a0353
SK
25 final = curr
26 print "digraph {"
27 if (init == final) {
28 printf \
29 "\"%s\" [penwidth=10, style=filled, fillcolor=tomato , fontcolor=white, color=yellowgreen];\n", \
30 init
31 } else {
32 printf \
33 "\"%s\" [penwidth=0, style=filled, fillcolor=yellowgreen, fontcolor=white];\n", \
34 init
35 printf \
36 "\"%s\" [penwidth=0, style=filled, fillcolor=tomato , fontcolor=white];\n", \
37 final
38 }
39
5ddd0980
SK
40 for (src_dst in nlinks_to) {
41 split(src_dst, sd, SUBSEP);
42 src = sd[1]
43 dst = sd[2]
44 m = nlinks[src]
45 n = nlinks_to[src, dst]
281ad07d 46 penwidth = num_scale(n, m, 1, 5)
5ddd0980
SK
47 color = sprintf("/orrd9/%d", num_scale(n, m, 2, 9))
48 label = sprintf("%s %.2f%%", src, (n / m) * 100)
49 printf \
50 "\"%s\" -> \"%s\" \
51 [ label=\"%s\"\
52 , fontname=monospace \
53 , fontsize=8 \
54 , penwidth=%d \
55 , color=\"%s\" \
56 , dir=both \
57 , arrowtail=odot \
58 ];\n", \
59 src, dst, label, penwidth, color;
60 }
61 print "}"
62}
63
64function num_scale(src_cur, src_max, dst_min, dst_max) {
65 return dst_min + ((src_cur * (dst_max - dst_min)) / src_max)
66}
This page took 0.076506 seconds and 4 git commands to generate.