# /* vim: set filetype=awk : */ -*- awk -*- BEGIN { FS = OFS = ","; Shrink = 5; Left = -100; Right = 100; Off = "."; Median = "|"; On = "*"; F = "5.1f" } { N[$1]++; Sum[$1] += $3; SumSq[$1] += $3*$3; push(Data,$1,$3) } END { print "#rx,mean,sd,n,min,q1,median,q3,max,"quart0(Right,Shrink) for(I in N) report(I) } function report(k, mu,sigma,s,n,min,q1,median,q3,max) { mu = mean(N[k],Sum[k]); sigma = sd(N[k],Sum[k],SumSq[k]); n = sort(Data,k,s); min = s[1]; q1 = s[round(n/4)]; median= s[round(2*n/4)]; q3 = s[round(3*n/4)]; max = s[n]; printf("%s,%"F",%"F",%d,%"F",%"F",%"F",%"F",%"F",%s\n", k,mu,sigma,n,min,q1,median,q3,max, quart(min,q1,median,q3,max,Right,Shrink)) | "sort -t, -r -n +1" } function quart0(width,scale, i,l,str) { width /= scale; for(i= -1*width;i<=width;i++) l[round(i)] = Off; l[0] = "0"; for(i= -1*width;i<=width;i++) str = str l[round(i)]; return str } function quart(min,q1,median,q3,max,width, scale, i,l,str) { width /= scale min /= scale q1 /= scale median /= scale q3 /= scale max /= scale for(i= -1*width; i<=width; i++) l[round(i)]= Off; for(i= min; i<=q1; i++) l[round(i)]= On; for(i= q3; i<=max; i++) l[round(i)]= On; l[round(median)] = Median for(i= -1*width; i<=width; i++) str = str l[round(i)]; return str } function round(x) { return int(x<0 ? x-0.5 : x+0.5) } function mean(n,sum) { return sum/n } function sd( n,sum,sumSq) { return sqrt((sumSq-((sum*sum)/n))/(n-1))} function push(a,k,v, i) { i= ++a[k,0]; a[k,i]=v; return v } function sort(a,k,s, i,m,n) { m = a[k,0]; for(i=1; i<=m; i++) s[i] = a[k,i]; n=asort(s); return n; }