import time
import logging


def fit(clf, x_train, y_train):
    """
    Wrapper for sklearn.<Claasificator>.fit() method.

    Args:
        clf: Classifier instance
        X_train: features
        y_train: targets
    Returns:
        model, name_of_classifier, model_fit_time
    """
    _clr_name_map = {
        "adaboostclassifier": "AdaBoost",
        "decisiontreeclassifier": "CART",
        "gaussiannb": "GaussianNB",
        "linearsvc": "LinearSVC",
        "randomforestclassifier": "RandomForest"
    }

    _clr_name = clf.__str__().split("(")[0].lower()
    clr_name = _clr_name_map[_clr_name]

    starttime = time.time()
    logging.info("Start fitting {0}. Training set size is {1}".format(
        clr_name, len(y_train)))
    model = clf.fit(x_train, y_train)
    stoptime = time.time()

    return model, clr_name, round(stoptime - starttime, 4)