#!/usr/bin/env python
from pylab import *
import json

files = '''
measure_v1.1.0.txt
measure_master_283df90_normal.txt
measure_master_283df90_openmp.txt
'''.split()

all_tests = []
all_runs = []
ax = subplot(111)
refs = {}
legend_lines = []
for file_number, filename in enumerate(files):
    s = open(filename).read().split('=== DETAILS ===')[-1].split('===')[0]
    exec s
    first = True
    for test, result in zip(tests, results):
        if test not in all_tests:
            all_tests.append(test)
            refs[test] = min(result)
        test_number = all_tests.index(test)
        x = test_number + float(file_number) / (len(files)+2)
        for duration in result:
            y = duration / refs[test]
            c = ['b','g','r','c','m','y','k'][file_number]
            lines = ax.plot(x, y, 'o', color=c)

    label = filename.replace('.txt', '').replace('measure_', '')
    lines[0].set_label(label)

for test_number, test_name in enumerate(all_tests):
    x_shift = 1.0/(len(files)+2)
    line_x = test_number - x_shift
    ax.plot((line_x, line_x), (0, 5), color='gray')
    ax.plot((line_x+1, line_x+1), (0, 5), color='gray')

    text_x = test_number+0.5 - x_shift
    text_y = -20.5-(len(all_tests)-test_number)*12.0
    ax.annotate(test_name, xy=(text_x, 0.0),  xycoords='data',
                xytext=(text_x, text_y), textcoords='offset points',
                arrowprops=dict(arrowstyle="->",
                                connectionstyle="angle,angleA=0,angleB=90,rad=10"),
                )

    #ax.text(test_number+0.5 - x_shift, 0.5, test_name,
    #        rotation = 90, horizontalalignment='center')

ylabel("duration (higher is worse)")
ylim([-1,3])
#ax.set_ylim(bottom=-8)
legend()
show()
