<commit_before>import os
import json
import numpy as np
from future.utils import iteritems


class AhenkIdentifier(object):
    CENTS_IN_OCTAVE = 1200  # cents

    @classmethod
    def identify(cls, tonic_freq, symbol_in):
        tonic_dict = cls._get_dict('tonic')
        ahenks = cls._get_dict('ahenk')

        # get the tonic symbol and frequency
        tonic_symbol, tonic_bolahenk_freq, makam = cls._get_tonic_symbol(
            symbol_in, tonic_dict)

        # get the transposition in cents, rounded to the closest semitone
        cent_dist = cls._hz_to_cent(tonic_freq, tonic_bolahenk_freq)
        mod_cent_dist = np.mod(cent_dist, cls.CENTS_IN_OCTAVE)

        # if the distance is more than 1150 cents wrap it to minus
        # so it will be mapped to 0 cents
        mod_cent_dist = (mod_cent_dist if mod_cent_dist < 1150
                         else mod_cent_dist - 1200)

        mod_cent_approx = int(np.round(mod_cent_dist * 0.01) * 100)
        mod_cent_dev = mod_cent_approx - mod_cent_dist
        abs_mod_cent_dev = abs(mod_cent_dev)

        # create the stats dictionary
        distance_to_bolahenk = {
            'performed': {'value': mod_cent_dist.tolist()[0], 'unit': 'cent'},
            'theoretical': {'value': mod_cent_approx, 'unit': 'cent'}}
        ahenk_dict = {'name': '', 'slug': '', 'makam': makam,
                      'tonic_symbol': tonic_symbol,
                      'distance_to_bolahenk': distance_to_bolahenk,
                      'deviation': {'value': mod_cent_dev.tolist()[0],
                                    'unit': 'cent'},
                      'abs_deviation': {'value': abs_mod_cent_dev.tolist()[0],
                                        'unit': 'cent'}}

        # get the ahenk
        for ahenk_slug, val in iteritems(ahenks):
            if val['cent_transposition'] == mod_cent_approx:
                ahenk_dict['name'] = val['name']
                ahenk_dict['slug'] = ahenk_slug
                return ahenk_dict

    @classmethod
    def _get_tonic_symbol(cls, symbol_in, tonic_dict):
        if symbol_in in tonic_dict.keys():  # tonic symbol given
            tonic_symbol = symbol_in
            makam = None
            tonic_bolahenk_freq = tonic_dict[symbol_in]['bolahenk_freq']
        else:  # check if the makam name is given
            makam = symbol_in
            tonic_symbol, tonic_bolahenk_freq = \
                cls._get_tonic_symbol_from_makam(symbol_in,
                                                             tonic_dict)
            if not tonic_bolahenk_freq:
                raise IOError("The second input has to be a tonic " +<commit_msg>Fixed minor PEP8 violation<commit_after>import os
import json
import numpy as np
from future.utils import iteritems


class AhenkIdentifier(object):
    CENTS_IN_OCTAVE = 1200  # cents

    @classmethod
    def identify(cls, tonic_freq, symbol_in):
        tonic_dict = cls._get_dict('tonic')
        ahenks = cls._get_dict('ahenk')

        # get the tonic symbol and frequency
        tonic_symbol, tonic_bolahenk_freq, makam = cls._get_tonic_symbol(
            symbol_in, tonic_dict)

        # get the transposition in cents, rounded to the closest semitone
        cent_dist = cls._hz_to_cent(tonic_freq, tonic_bolahenk_freq)
        mod_cent_dist = np.mod(cent_dist, cls.CENTS_IN_OCTAVE)

        # if the distance is more than 1150 cents wrap it to minus
        # so it will be mapped to 0 cents
        mod_cent_dist = (mod_cent_dist if mod_cent_dist < 1150
                         else mod_cent_dist - 1200)

        mod_cent_approx = int(np.round(mod_cent_dist * 0.01) * 100)
        mod_cent_dev = mod_cent_approx - mod_cent_dist
        abs_mod_cent_dev = abs(mod_cent_dev)

        # create the stats dictionary
        distance_to_bolahenk = {
            'performed': {'value': mod_cent_dist.tolist()[0], 'unit': 'cent'},
            'theoretical': {'value': mod_cent_approx, 'unit': 'cent'}}
        ahenk_dict = {'name': '', 'slug': '', 'makam': makam,
                      'tonic_symbol': tonic_symbol,
                      'distance_to_bolahenk': distance_to_bolahenk,
                      'deviation': {'value': mod_cent_dev.tolist()[0],
                                    'unit': 'cent'},
                      'abs_deviation': {'value': abs_mod_cent_dev.tolist()[0],
                                        'unit': 'cent'}}

        # get the ahenk
        for ahenk_slug, val in iteritems(ahenks):
            if val['cent_transposition'] == mod_cent_approx:
                ahenk_dict['name'] = val['name']
                ahenk_dict['slug'] = ahenk_slug
                return ahenk_dict

    @classmethod
    def _get_tonic_symbol(cls, symbol_in, tonic_dict):
        if symbol_in in tonic_dict.keys():  # tonic symbol given
            tonic_symbol = symbol_in
            makam = None
            tonic_bolahenk_freq = tonic_dict[symbol_in]['bolahenk_freq']
        else:  # check if the makam name is given
            makam = symbol_in
            tonic_symbol, tonic_bolahenk_freq = \
                cls._get_tonic_symbol_from_makam(symbol_in, tonic_dict)
            if not tonic_bolahenk_freq:
                raise IOError("The second input has to be a tonic " +
{'fraction_non_alphanumeric': 0.08904109589041095, 'fraction_numerical': 0.010083713850837138, 'mean_word_length': 2.068884997081144, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1666854', 'n_tokens_mistral': 1727, 'n_tokens_neox': 1630, 'n_words': 375}