#!/usr/bin/python
from plot import *
import sys
if len(sys.argv) != 2:
    print "Usage: %s %s" % (sys.argv[0], 'file-to-parse')
    exit(2)
r = RunStats()
r.read(sys.argv[1])
r.json('slava', '')

with open('stats', 'w') as outf:
    best_mean = None
    best_load = None
    worst_mean = None
    worst_load = None
    for column in r.stats().iteritems():
        print >>outf, "%s:\n\tMean: %d\n\tstdev %d\n" % (column[0], column[1]['mean'], column[1]['stdev'])
	if column[0] != '#0' and (best_mean == None or column[1]['mean'] > best_mean):
	    best_mean = column[1]['mean']
	    best_load = column[0]
        if column[0] != '#0' and (worst_mean == None or column[1]['mean'] < worst_mean):
            worst_mean = column[1]['mean']
            worst_load = column[0]
    print >>outf, "Best load (%d): %s" % (best_mean, best_load)
    print >>outf, "Worst load (%d): %s" % (worst_mean, worst_load)
    print >>outf, "Diff: %.2f%%" % (float(best_mean) / float(worst_mean) * 100.0)

for ts in r.data.iteritems():
    r.data[ts[0]] = ts[1][int(len(ts) * .7) :]

with open('steady_stats', 'w') as outf:
    best_mean = None
    best_load = None
    worst_mean = None
    worst_load = None
    for column in r.stats().iteritems():
        print >>outf, "%s:\n\tMean: %d\n\tstdev %d\n" % (column[0], column[1]['steady_mean'], column[1]['steady_stdev'])
	if column[0] != '#0' and (best_mean == None or column[1]['steady_mean'] > best_mean):
	    best_mean = column[1]['steady_mean']
	    best_load = column[0]
        if column[0] != '#0' and (worst_mean == None or column[1]['steady_mean'] < worst_mean):
            worst_mean = column[1]['steady_mean']
            worst_load = column[0]
    print >>outf, "Best load (%d): %s" % (best_mean, best_load)
    print >>outf, "Worst load (%d): %s" % (worst_mean, worst_load)
    print >>outf, "Diff: %.2f%%" % (float(best_mean) / float(worst_mean) * 100.0)
