import json


def extract(paths, avg_inc=False):
    """Extract accuracy logged in the various log files.

    :param paths: A path or a list of paths to a json file.
    :param avg_inc: Boolean specifying whether to use the accuracy or the average
                    incremental accuracy as defined in iCaRL.
    :return: A list of runs. Each runs is a list of (average incremental) accuracies.
    """
    if not isinstance(paths, list):
        paths = [paths]

    runs_accs = []
    for path in paths:
        with open(path) as f:
            data = json.load(f)

        if isinstance(data["results"][0], dict):
            accs = [100 * task["total"] for task in data["results"]]
        elif isinstance(data["results"][0], float):
            accs = [100 * task_acc for task_acc in data["results"]]
        else:
            raise NotImplementedError(type(data["results"][0]))

        if avg_inc:
            raise NotImplementedError("Deprecated")

        runs_accs.append(accs)

    return runs_accs