# Path: msaf/exceptions.py
# class NoReferencesError(MSAFError):
#     '''Exception class for trying evaluations without references'''
#     pass
# 
# Path: msaf/utils.py
# def lognormalize(F, floor=0.1, min_db=-80):
# def min_max_normalize(F, floor=0.001):
# def normalize(X, norm_type, floor=0.0, min_db=-80):
# def ensure_dir(directory):
# def times_to_intervals(times):
# def intervals_to_times(inters):
# def get_num_frames(dur, anal):
# def get_time_frames(dur, anal):
# def remove_empty_segments(times, labels):
# def sonify_clicks(audio, clicks, out_file, fs, offset=0):
# def synchronize_labels(new_bound_idxs, old_bound_idxs, old_labels, N):
# def process_segmentation_level(est_idxs, est_labels, N, frame_times, dur):
# def align_end_hierarchies(hier1, hier2, thres=0.5):
#     F = min_max_normalize(F, floor=floor)
#     F = np.abs(min_db) * np.log10(F)  # Normalize from min_db to 0
#     F = F / F.max(axis=0)


import jams
import logging
import mir_eval
import numpy as np
import os
import pandas as pd
import six
import msaf
import msaf.input_output as io
from joblib import Parallel, delayed
from msaf.exceptions import NoReferencesError
from msaf import utils
    # Convert to file_struct if string is passed
    if isinstance(file_struct, six.string_types):
        file_struct = io.FileStruct(file_struct)

    est_file = file_struct.est_file
    ref_file = file_struct.ref_file

    # Sanity check
    assert os.path.basename(est_file)[:-4] == \
        os.path.basename(ref_file)[:-4], "File names are different %s --- %s" \
        % (os.path.basename(est_file)[:-4], os.path.basename(ref_file)[:-4])

    if not os.path.isfile(ref_file):
        raise NoReferencesError("Reference file %s does not exist. You must "
                                "have annotated references to run "
                                "evaluations." % ref_file)

    one_res = compute_gt_results(est_file, ref_file, boundaries_id, labels_id,
                                 config, annotator_id=annotator_id)

    return one_res


def get_results_file_name(boundaries_id, labels_id, config,
                          annotator_id):
    """Based on the config and the dataset, get the file name to store the
    results."""
    utils.ensure_dir(msaf.config.results_dir)
    file_name = os.path.join(msaf.config.results_dir, "results")
    file_name += "_boundsE%s_labelsE%s" % (boundaries_id, labels_id)

# Path: msaf/exceptions.py
# class NoReferencesError(MSAFError):
#     '''Exception class for trying evaluations without references'''
#     pass
# 
# Path: msaf/utils.py
# def lognormalize(F, floor=0.1, min_db=-80):
# def min_max_normalize(F, floor=0.001):
# def normalize(X, norm_type, floor=0.0, min_db=-80):
# def ensure_dir(directory):
# def times_to_intervals(times):
# def intervals_to_times(inters):
# def get_num_frames(dur, anal):
# def get_time_frames(dur, anal):
# def remove_empty_segments(times, labels):
# def sonify_clicks(audio, clicks, out_file, fs, offset=0):
# def synchronize_labels(new_bound_idxs, old_bound_idxs, old_labels, N):
# def process_segmentation_level(est_idxs, est_labels, N, frame_times, dur):
# def align_end_hierarchies(hier1, hier2, thres=0.5):
#     F = min_max_normalize(F, floor=floor)
#     F = np.abs(min_db) * np.log10(F)  # Normalize from min_db to 0
#     F = F / F.max(axis=0)


# Path: msaf/eval.py
import jams
import logging
import mir_eval
import numpy as np
import os
import pandas as pd
import six
import msaf
import msaf.input_output as io
from joblib import Parallel, delayed
from msaf.exceptions import NoReferencesError
from msaf import utils

    # Convert to file_struct if string is passed
    if isinstance(file_struct, six.string_types):
        file_struct = io.FileStruct(file_struct)

    est_file = file_struct.est_file
    ref_file = file_struct.ref_file

    # Sanity check
    assert os.path.basename(est_file)[:-4] == \
        os.path.basename(ref_file)[:-4], "File names are different %s --- %s" \
        % (os.path.basename(est_file)[:-4], os.path.basename(ref_file)[:-4])

    if not os.path.isfile(ref_file):
        raise NoReferencesError("Reference file %s does not exist. You must "
                                "have annotated references to run "
                                "evaluations." % ref_file)

    one_res = compute_gt_results(est_file, ref_file, boundaries_id, labels_id,
                                 config, annotator_id=annotator_id)

    return one_res


def get_results_file_name(boundaries_id, labels_id, config,
                          annotator_id):
    """Based on the config and the dataset, get the file name to store the
    results."""
    utils.ensure_dir(msaf.config.results_dir)
    file_name = os.path.join(msaf.config.results_dir, "results")
    file_name += "_boundsE%s_labelsE%s" % (boundaries_id, labels_id)

    file_name += "_annotatorE%d" % (annotator_id)