import matplotlib.pyplot as plt

def plot_learning_curves(file_name):
    file = open(file_name, 'r').read().split('\n')

    times = []
    train_accuracies = []
    test_accuracies = []

    train_losses = []
    test_losses = []

    for f in file:
        try:
            stopwatch, cycle, loss, test_loss, accuracy, test_accuracy = f.split(';')
        except ValueError:
            pass

        times.append(float(stopwatch)/60)
        train_losses.append(float(loss))
        test_losses.append(float(test_loss))
        train_accuracies.append(float(accuracy))
        test_accuracies.append(float(test_accuracy))

    figure = plt.figure()

    ax1 = plt.subplot2grid((2,1), (0,0), title=r'$\it{f(t) = Accuracy}$')
    ax1.set_xlabel(r"$\it{t}[min]$")
    ax1.set_ylabel(r"$\it{accurancy}$ [%]")
    ax1.grid()
    ax2 = plt.subplot2grid((2,1), (1,0), sharex=ax1, title=r'$\it{f(t) = Loss}$')
    ax2.set_xlabel(r"$\it{t} [min]$")
    ax2.set_ylabel(r"$\it{loss} [-]$")
    ax2.grid()

    ax1.plot(times, test_accuracies, label="Test accuracies")
    ax1.plot(times, train_accuracies, label='Train accurancies')
    ax1.legend(loc=4)

    ax2.plot(times, test_losses, label='Test losses')
    ax2.plot(times, train_losses, label='Train losses')
    ax2.legend(loc=1)
    
    plt.xlim([0, 60])
    plt.show()
    
if __name__ == '__main__':
    plot_learning_curves('plot_data\data_kitti.csv')
    