more robust sql scripts adding IF EXISTS to DROP TABLE statementes
[brisk.git] / bin / girones.sh
1 #!/bin/bash
2 # set -x
3 NL="
4 "
5 #
6 #  functions
7 usage () {
8     echo
9     echo "USAGE:"
10     echo "  $0 <conf-file>"
11     echo
12     exit $1
13 }
14
15
16 if [ $# -lt 1 ]; then
17     usage 1
18 fi
19
20 finname="$1"
21
22 if [ ! -f "$finname" ]; then
23     exit 2
24 fi
25 source "$finname"
26
27 tai=""
28 cat <<EOF
29 // <graphviz center dpi=52>
30 digraph G {
31 fillcolor="#f0f0f0";
32 // bgcolor="transparent";
33 bgcolor="#fafafa";
34 newrank=true;
35 rankdir="LR";
36 ranksep=1.5;
37 compound=true;
38 EOF
39 for gen_id in $(seq 0 $((${#gens_prefix[@]} - 1))); do
40     echo "// GENERATION ${gens_prefix[$gen_id]}" 
41     names_n="$(echo "${gens_names[$gen_id]}" | sed 's/|/\n/g' | wc -l)" 
42     for name_id in $(seq 0 $((names_n - 1))); do
43         hue="$(echo "($name_id * 255 ) / $names_n" | bc -l)"
44         # hue=180.0
45         col100="$(./rgb_hsv.php -toxrgb 255 $hue 255.0 255.0)"
46         col33="$(./rgb_hsv.php -toxrgb 255 $hue 85.0 255.0)"
47         col17="$(./rgb_hsv.php -toxrgb 255 $hue 42.0 255.0)"
48
49         name="$(echo "${gens_names[$gen_id]}" | cut -d '|' -f $((name_id + 1)))" 
50         if [ $names_n -gt 1 ]; then
51             name="${gens_prefix[$gen_id]}_${name}" 
52         else
53             name="${gens_prefix[$gen_id]}"
54         fi
55         echo "// [${name}][$col100][$col33][$col17]"
56         cat <<EOF
57   subgraph cluster_${name} {
58     fontsize=18;
59     label="${name}";
60     fillcolor="#${col33}";
61     color="#${col100}";
62     style="rounded,filled";
63    node [shape=record, color="#${col100}", style=filled, fillcolor="#${col17}"];
64     ${name} [label="<1>aaa aaa|<2>bbb bbb|<3>ccc ccc|<4>ddd ddd|<5>eee eee"];
65   }
66 EOF
67         tai="${tai}${NL}subgraph cluster_${name} { label=\"new name\";${NL}    ${name} [label=\"<1>aaa|<2>bbb|<3>ccc|<4>ddd|<5>eee\"];}${NL}"
68     done
69 done
70
71 for gen_id in $(seq 0 $((${#gens_prefix[@]} - 1))); do
72     echo "// GENERATION ${gens_prefix[$gen_id]}"
73     names_n="$(echo "${gens_names[$gen_id]}" | sed 's/|/\n/g' | wc -l)" 
74     for name_id in $(seq 0 $((names_n - 1))); do
75         hue="$(echo "($name_id * 255 ) / $names_n" | bc -l)"
76         col100="$(./rgb_hsv.php -toxrgb 255 $hue 255.0 255.0)"
77
78         gnxt_id=$((gen_id + 1))
79         if [ "${gens_prefix[$gnxt_id]}" = "" ]; then
80             break
81         fi
82         gnxt_names_n="$(echo "${gens_names[$gnxt_id]}" | sed 's/|/\n/g' | wc -l)" 
83
84         start=$((name_id % gnxt_names_n))
85         startp1=$(( ( name_id + 1) % gnxt_names_n))
86
87         ct=1
88         col="#$col100"
89         for gnxt_name_id in $start $startp1; do
90
91
92             name="$(echo "${gens_names[$gen_id]}" | cut -d '|' -f $((name_id + 1)))" 
93             if [ $names_n -gt 1 ]; then
94                 name="${gens_prefix[$gen_id]}_${name}" 
95             else
96                 name="${gens_prefix[$gen_id]}"
97             fi
98             gnxt_name="$(echo "${gens_names[$gnxt_id]}" | cut -d '|' -f $((gnxt_name_id + 1)))" 
99             if [ $gnxt_names_n -gt 1 ]; then
100                 gnxt_name="${gens_prefix[$gnxt_id]}_${gnxt_name}" 
101             else
102                 gnxt_name="${gens_prefix[$gnxt_id]}"
103             fi
104             echo "${name}:${ct} -> ${gnxt_name}:2 [lhead=\"cluster_${gnxt_name}\", color=\"${col}\"];" 
105
106             ct=$((ct + 1))
107             col="black"
108         done
109     done
110 done
111
112 cat <<EOF
113 $tai
114 }
115 // </graphviz>
116 EOF
117 exit 0
118