#!/sw/bin/gawk -f # /* vim: set filetype=awk : */ -*- awk -*- BEGIN { OFMT = "%.3f"; Got = 1 Want = 2; Prefix = ""; True = "true"; ## define symbol 1 False = "false"; ## define symbol 2 A=B=C=D=0 ; FS=OFS="," GoalPd = 1; GoalPf = 0; } function yes(s) {return s ~ True || s == "yes" } function no(s) {return s ~ False || s== "no"} { sub(/#.*/,"") } /^[ \t]*$/ { next } NF==2 { N++; Predicted=$Got; Actual=$Want; if (Predicted == Actual) Good++; if (no( Actual) && no( Predicted)) A++; if (yes(Actual) && no( Predicted)) B++; if (no( Actual) && yes(Predicted)) C++; if (yes(Actual) && yes(Predicted)) D++; } END { G=Precision=Accuracy=Pf=NotPf=Pd=0; if (C+D > 0 ) Precision = D/(C+D); if (N > 0 ) Accuracy = Good/N; if (A+C > 0 ) {Pf = C/(A+C)} if (B+D > 0 ) Pd = D/(B+D); Balance = sqrt((GoalPd - Pd)^2 + (GoalPf - Pf)^2)/sqrt(2); if(Prefix) printf Txt=Prefix OFS; print A,B,C,D, sprintf(OFMT,100*Accuracy), sprintf(OFMT,100*Pd), sprintf(OFMT,100*Pf), sprintf(OFMT,100*Precision), sprintf(OFMT,100*Balance); }