#!/usr/bin/env python
from sys import argv
from pylab import plot, xlabel, ylabel, show, savefig, ylim, legend

# Collect data
x = []
seq = []
par = []
lines = open('compare.txt').readlines()[1:]

for i in range(len(lines))[::3]:
    n = int(lines[i][:-1])
    s = float(lines[i + 1][:-1])
    p = float(lines[i + 2][:-1])

    # Use the minimum of all measurements
    if len(x) and x[-1] == n:
        if seq[-1] > s:
            seq[-1] = s
        if par[-1] > p:
            par[-1] = p
    else:
        x.append(n)
        seq.append(s)
        par.append(p)

# Plot and optionally save data
plot(x, seq, 'o-', label='Sequentieel')
plot(x, par, 'o-', label='Parallel (9 processen)')
ylim(ymin=0)
legend()
xlabel('Aantal afstandsstappen')
ylabel('Tijd (s)')
if len(argv) > 1:
    savefig(argv[1])
show()
