Use full line as element of sequence
[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 BEGIN {print "digraph {"}
8
9 {
10 prev = prev ? prev : "--"
11 curr = $0
12 ++nlinks[prev]
13 ++nlinks_to[prev, curr]
14 prev = curr
15 }
16
17 END {
18 for (src_dst in nlinks_to) {
19 split(src_dst, sd, SUBSEP);
20 src = sd[1]
21 dst = sd[2]
22 m = nlinks[src]
23 n = nlinks_to[src, dst]
24 penwidth = num_scale(n, m, 1, 9)
25 color = sprintf("/orrd9/%d", num_scale(n, m, 2, 9))
26 label = sprintf("%s %.2f%%", src, (n / m) * 100)
27 printf \
28 "\"%s\" -> \"%s\" \
29 [ label=\"%s\"\
30 , fontname=monospace \
31 , fontsize=8 \
32 , penwidth=%d \
33 , color=\"%s\" \
34 , dir=both \
35 , arrowtail=odot \
36 ];\n", \
37 src, dst, label, penwidth, color;
38 }
39 print "}"
40 }
41
42 function num_scale(src_cur, src_max, dst_min, dst_max) {
43 return dst_min + ((src_cur * (dst_max - dst_min)) / src_max)
44 }
This page took 0.069368 seconds and 4 git commands to generate.