Switch experiment README to .md
[khome.git] / home / bin / seq2dot
1 #! /usr/bin/awk -f
2 #
3 # Graph a sequence of lines as prev->next relationships,
4 # highlighting frequencies of pairings.
5 #
6
7 {
8 curr = $0
9 }
10
11 NR == 1 {
12 init = curr
13 }
14
15 NR > 1 {
16 ++nlinks[prev]
17 ++nlinks_to[prev, curr]
18 }
19
20 {
21 prev = curr
22 }
23
24 END {
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
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]
46 penwidth = num_scale(n, m, 1, 5)
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
64 function 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.085546 seconds and 4 git commands to generate.