Index: pcb-rnd-poll.cgi =================================================================== --- pcb-rnd-poll.cgi (revision 1641) +++ pcb-rnd-poll.cgi (revision 1642) @@ -38,6 +38,15 @@ I do not need this feature at all ' +# the same table with shorter tests +choices_short='production-user +tester +user +lurker +mainliner +no-need +' + # someone is a tester if choice is < $tester_thrs tester_thrs=2 @@ -177,7 +186,7 @@ fi short=`cat $name/short` long=`cat $name/long` - echo " $score " + echo " $score
stats" echo "[$bn]
$short$long" echo "

" if test -z "$QS_SID" @@ -469,6 +478,137 @@ error "You are not logged in." } +cmd_stats() +{ + local old_ifs n not_found votes tmp + + case "$QS_fmt" + in + html|pie) ;; + "") export QS_fmt="html";; + *) error "Invalid format." + esac + + old_ifs=$IFS + IFS="+" + for n in $QS_features + do + if test -f $root/$n/long + then + tmp="`cat $db/votes/$n`" + votes="$votes +@|$n +$tmp +" + else + not_found="$not_found $n" + echo "|$n|" >&2 + fi + done + IFS=$old_ifs + + if test ! -z "$not_found" + then + error "Features not found: $not_found" + fi + + + case "$QS_fmt" + in + html) + render_html < $root/head.html ;; + pie) + echo "Content-Type: image/png" + echo "";; + esac + + echo "$votes" | awk -F "[|]" -v "choices=$choices" -v "choices_short=$choices_short" -v "qs_features=$QS_features" -v "cgi=$CGI" -v "fmt=$QS_fmt" ' + BEGIN { + HTML=1 + PIE=2 + if (fmt == "pie") + fmt = PIE + else if (fmt == "html") + fmt = HTML + else + exit + levels = split(choices, CHOICES, "[\n]")-1 + split(choices_short, CHOICES_SHORT, "[\n]") + COLOR[0]="#FF0000" + COLOR[1]="#AA0000" + COLOR[2]="#AA5500" + COLOR[3]="#55AA00" + COLOR[4]="#777777" + COLOR[5]="#FFFFFF" + } + + function html_tbl(TBL, divisor, feat ,n,img) + { + print "" + img=cgi "?cmd=stats&features=" feat "&fmt=pie" + for(n=0; n < levels; n++) { + print "
" CHOICES_SHORT[n+1] "" int(TBL[n])/divisor + if (n == 0) + print " " + } + print "
" + } + + function pie_append(key, val) + { + pie = pie "\n" key "\n" val + } + + function pie_draw(TBL) + { + pie="" + for(n=0; n < levels; n++) { + if (TBL[n] == 0) + continue + pie_append("@slice", TBL[n]) + pie_append("@label", CHOICES_SHORT[n+1]) + pie_append("@color", COLOR[n]) + } + print pie | "(animpie; echo screenshot \\\"/dev/stdout\\\") | animator -H -x 300 -y 200" + } + + + function out( u) + { + if (feature == "") + return + delete VLOCAL + for(u in USER) { + VLOCAL[USER[u]]++ + VGLOBAL[USER[u]]++ + } + delete USER + + if (fmt == HTML) { + print "

" feature "

" + html_tbl(VLOCAL, 1, feature) + } + features++ + } + + function out_end() + { + if ((fmt == HTML) && (features > 1)) { + print "

Average of " features " features

" + html_tbl(VGLOBAL, features, qs_features) + } + else if (fmt == PIE) + pie_draw(VGLOBAL) + } + + ($1 == "@") { out(); feature=$2 } + (NF == 2) { USER[$2]=$1 } + + END { out(); out_end() } + ' + +} + ########## main ############ @@ -499,6 +639,7 @@ try_enter) cmd_try_enter ;; logout) cmd_logout ;; captcha) cmd_captcha_jpg;; + stats) cmd_stats ;; *) cmd_list ;; esac