import re


def load_log(log_file):
  """ Parses data from a log file instead of the JSON dump.
  Args:
    log_file: The file to load data from.
  Returns:
    List of the testing_loss, training loss, testing accuracy, and
                training accuracy. """
  testing_loss = []
  training_loss = []
  testing_acc = []
  training_acc = []

  lines = log_file.read().split("\n")
  for line in lines:
    if "Training loss" in line:
      # This line contains the training loss and accuracy.
      numbers = re.findall("\d\.\d+", line)
      loss, acc = [float(num) for num in numbers]

      training_loss.append(loss)
      training_acc.append(acc)

    if "Testing loss" in line:
      # This line contains the testing loss and accuracy.
      numbers = re.findall("\d\.\d+", line)
      loss, acc = [float(num) for num in numbers]

      testing_loss.append(loss)
      testing_acc.append(acc)

  return testing_loss, training_loss, testing_acc, training_acc