import pickle


def _read_python_plot_info(filename):
    """
    Read the information required for a python plot for the given filename. The data for this are assumed to be in:
    ./data/results/filename_mse.p, ./data/results/filename_mse_test.p, ./data/results/filename_correct_results.p and
     ./data/results/filename_weights.p
    Afterwards, one can call _create_python_plot(mse, mse_test, weights, correct_weights)
    :param filename: The filename from which to obtain the mse, mse_test, correct weights and found weights.
    :type filename: str
    :return: The mse for each epoch, the mse of the test set for each epoch, the correct weights and the weights found
    in each epoch.
    :rtype: list[float], list[float], dict[Term,float], list[dict[Term, float]]
    """
    mse_filename = './data/results/' + filename.replace('.pl', '') + '_mse.p'
    mse_test_filename = './data/results/' + filename.replace('.pl', '') + '_mse_test.p'
    correct_weights_filename = './data/results/' + filename.replace('.pl', '') + '_correct_results.p'
    found_weights_filename = './data/results/' + filename.replace('.pl', '') + '_weights.p'

    with open(mse_filename, 'rb') as f:
        mse = pickle.load(f)

    with open(mse_test_filename, 'rb') as f:
        mse_test = pickle.load(f)

    with open(correct_weights_filename, 'rb') as f:
        correct_weights = pickle.load(f)

    with open(found_weights_filename, 'rb') as f:
        found_weights = pickle.load(f)

    return mse, mse_test, correct_weights, found_weights