Groovy Very Basic Statistics Tool

[ This Blog Was Moved To : http://www.diknows.com ]


I am in a project where I am in charge of watching and reporting performance of a JEE Application on JBoss Application Server. Due to my usual need to caculate Average, Max, Min values of the data I observe. I made this little code to help me out ( Which for me it did help out ).

Here it is:

pagesLoad = [ 5.767,9.296, 3.814, 1.826, 2.889,8.000,6.797,2.926,5.992,2.430,16.191,14.294,2.778,7.037,4.745,5.004,4.601,6.930,2.275,2.896,14.319,3.836,11.059,2.295,2.845,7.078,6.194,1.812,14.811,4.105,3.013,16.358,4.368,3.314,21.828,6.188,8.137 ]
bitsRecieved = [ 27764, 253033, 921870, 142091, 307, 214406, 890962, 307, 307, 1259790, 553839, 749870, 143216, 146175, 179923, 517335, 572690, 180094, 801059, 143218, 215843, 215407, 146973, 572912, 801120, 587021, 239474, 518619, 307, 2409085, 908437, 16453, 143218, 215847, 218320, 1121673, 215163, 119930, 578828, 135629, 23098, 384, 143422, 215847, 215040, 254052, 578110, 216877, 921819 ]

def showStatistics(data,over=1,append=''){
    float min = 100000000
    float max = 0
    int count = data.size()
    float total = 0;
    data.each {
        it= it/over
        if(it>max){
            max = it;
        }
        if(it<min){
            min = it;
        }
        total+= it
    }
    println "MAX IS : $max $append"
    println "MIN IS : $min $append"
    println "Total is : $total $append"
    println "Count is : $count"
    println "Average IS: ${total/count} $append"
    println '-'*100
}

//showStatistics(pagesLoad,1,'Seconds')
showStatistics(bitsRecieved,1024,'KB')
Advertisements
Posted in GROOVY. Tags: . Leave a Comment »

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: