def get_contour_frequency(contour_list, size, normalize=False):

    def make_csegs(size):
        base = list(range(size)) * size
        permutations = map(list, itertools.permutations(base, size))
        csegs_set = set([tuple(contour.translate(cseg)) for cseg in permutations])
        return sorted(list(csegs_set))

    def aux(composition_contour, csegs_map, size):
        splitted = contour.split_and_translate(composition_contour, size)
        csegs = [csegs_map.index(tuple(c)) for c in splitted]
        counted = Counter(csegs)
        seq = []
        for i in range(len(csegs_map)):
            if i in counted:
                seq.append(counted[i])
            else:
                seq.append(0)
        return seq

    csegs_map = make_csegs(size)

    array = numpy.array([aux(comp_cseg, csegs_map, size) for comp_cseg in contour_list])

    if normalize:
        for i in range(len(csegs_map)):
            array = utils.normalize_array(array, i)

    return array
def get_interval_frequency(compositions, normalize=False):
    def aux(composition):
        intervals = composition.music_data.intervals_midi
        counted = utils.special_counter(intervals, True)
        seq = []
        for i in range(-48, 49):
            if i in counted:
                seq.append(counted[i])
            else:
                seq.append(0)
        return seq

    array = numpy.array([aux(composition) for composition in compositions])

    if normalize:
        for i in range(-48, 49):
            array = utils.normalize_array(array, i)

    return array
def get_duration_ambitus(compositions, normalize=True, labelize=False):
    pairs = [(c.music_data.total_duration, c.music_data.ambitus) for c in compositions]
    if normalize:
        arr = numpy.array(pairs)
        for i in 0, 1:
            arr = utils.normalize_array(arr, i)
        pairs = arr.tolist()

    if labelize:
        seq = []
        for i in range(len(pairs)):
            imslp = compositions[i].collection.imslp_id
            row = []
            x, y = pairs[i]
            row.append({'v': x, 'f':'{}. {}'.format(imslp, x)})
            row.append(y)

            seq.append(row)

        pairs = seq

    pairs.insert(0, ['', 'Piece'])
    return pairs