#!/usr/bin/awk -f
# lap : 1--overlap 0--non-overlap
# comp: 1--access  0--origin
# code:
#   non-blank -- specify status code
#   blank     -- not specify status code
# index = 1 if time duration < 1
# index = 2 if time duration < 2
# index = 3 if time duration < 3
# index = 4 if time duration < 4
# index = 5 if time duration < 5
# index = 6 if time duration < 6
# index = 7 if time duration < 11
# index = 8 if time duration < 16
# index = 9 if time duration < 21

function timeproc(dur, trans) {
    if((dur / trans)<1)
        res[1]++
    else if((dur / trans)<2)
        res[2]++
    else if((dur / trans)<3)
        res[3]++
    else if((dur / trans)<4)
        res[4]++
    else if((dur / trans)<5)
        res[5]++
    else if((dur / trans)<6)
        res[6]++
    else if((dur / trans)<11)
        res[7]++
    else if((dur / trans)<16)
        res[8]++
    else if((dur / trans)<21)
        res[9]++
    else if((dur / trans)>=21)
        res[10]++
}

BEGIN {
    if(code!="" && comp==1) { sc=4 }    
    if(code!="" && comp==0) { sc=11 }    
    if(code=="") { sc=1000 }    
    if(comp==1) { ac=56; trans=1; }    
    if(comp==0) { ac=50; trans=1000; }    
}

{
    if(acc==$ac && code==$sc)
        timeproc($pos, trans)
        
}
END {
    for(i in res)
        if(i==1||i==2||i==3||i==4||i==5||i==6)
            printf "%-15s%-8s%-s\n", "time < "i"s", res[i], res[i]/NR*100"%"
        else if(i==7)
            printf "%-15s%-8s%-s\n", "time < 11s", res[i], res[i]/NR*100"%"
        else if(i==8)
            printf "%-15s%-8s%-s\n", "time < 16s", res[i], res[i]/NR*100"%"
        else if(i==9)
            printf "%-15s%-8s%-s\n", "time < 21s", res[i], res[i]/NR*100"%"
        else if(i==10)
        printf "%-15s%-8s%-s\n", "time >= 21s", res[i], res[i]/NR*100"%"
}

