def source_is_ready(self, source): """Checks whether a source' status is FINISHED. """ check_resource_type(source, SOURCE_PATH, message="A source id is needed.") source = self.get_source(source) return resource_is_ready(source)
def dataset_is_ready(self, dataset): """Check whether a dataset' status is FINISHED. """ check_resource_type(dataset, DATASET_PATH, message="A dataset id is needed.") resource = self.get_dataset(dataset) return resource_is_ready(resource)
def error_counts(self, dataset, raise_on_error=True): """Returns the ids of the fields that contain errors and their number. The dataset argument can be either a dataset resource structure or a dataset id (that will be used to retrieve the associated remote resource). """ errors_dict = {} if not isinstance(dataset, dict) or 'object' not in dataset: check_resource_type(dataset, DATASET_PATH, message="A dataset id is needed.") dataset_id = get_dataset_id(dataset) dataset = check_resource(dataset_id, self.get_dataset, raise_on_error=raise_on_error) if not raise_on_error and dataset['error'] is not None: dataset_id = None else: dataset_id = get_dataset_id(dataset) if dataset_id: errors = dataset.get('object', {}).get( 'status', {}).get('field_errors', {}) for field_id in errors: errors_dict[field_id] = errors[field_id]['total'] return errors_dict
def get_logistic_regression(self, logistic_regression, query_string="", shared_username=None, shared_api_key=None): """Retrieves a logistic regression. The model parameter should be a string containing the logistic regression id or the dict returned by create_logistic_regression. As a logistic regression is an evolving object that is processed until it reaches the FINISHED or FAULTY state, the function will return a dict that encloses the logistic regression values and state info available at the time it is called. If this is a shared logistic regression, the username and sharing api key must also be provided. """ check_resource_type( logistic_regression, LOGISTIC_REGRESSION_PATH, message="A logistic regression id is needed." ) logistic_regression_id = get_logistic_regression_id(logistic_regression) if logistic_regression_id: return self._get( "%s%s" % (self.url, logistic_regression_id), query_string=query_string, shared_username=shared_username, shared_api_key=shared_api_key, )
def pca_is_ready(self, pca, **kwargs): """Checks whether a pca's status is FINISHED. """ check_resource_type(pca, PCA_PATH, message="A PCA id is needed.") resource = self.get_pca(pca, **kwargs) return resource_is_ready(resource)
def deepnet_is_ready(self, deepnet, **kwargs): """Checks whether a deepnet's status is FINISHED. """ check_resource_type(deepnet, DEEPNET_PATH, message="A deepnet id is needed.") resource = self.get_deepnet(deepnet, **kwargs) return resource_is_ready(resource)
def model_is_ready(self, model, **kwargs): """Checks whether a model's status is FINISHED. """ check_resource_type(model, MODEL_PATH, message="A model id is needed.") resource = self.get_model(model, **kwargs) return resource_is_ready(resource)
def download_dataset(self, dataset, filename=None, retries=10): """Donwloads dataset contents to a csv file or file object """ check_resource_type(dataset, DATASET_PATH, message="A dataset id is needed.") dataset_id = get_dataset_id(dataset) if dataset_id: return self._download("%s%s%s" % (self.url, dataset_id, DOWNLOAD_DIR), filename=filename, retries=retries)
def topic_model_is_ready(self, topic_model, **kwargs): """Checks whether a topic model's status is FINISHED. """ check_resource_type(topic_model, TOPIC_MODEL_PATH, message="A topic model id is needed.") resource = self.get_topic_model(topic_model, **kwargs) return resource_is_ready(resource)
def delete_project(self, project): """Deletes a project. """ check_resource_type(project, PROJECT_PATH, message="A project id is needed.") project_id = get_project_id(project) if project_id: return self._delete("%s%s" % (self.url, project_id))
def delete_prediction(self, prediction): """Deletes a prediction. """ check_resource_type(prediction, PREDICTION_PATH, message="A prediction id is needed.") prediction_id = get_prediction_id(prediction) if prediction_id: return self._delete("%s%s" % (self.url, prediction_id))
def linear_regression_is_ready(self, linear_regression, **kwargs): """Checks whether a linear regressioin's status is FINISHED. """ check_resource_type(linear_regression, LINEAR_REGRESSION_PATH, message="A linear regression id is needed.") resource = self.get_linear_regression(linear_regression, **kwargs) return resource_is_ready(resource)
def delete_source(self, source): """Deletes a remote source permanently. """ check_resource_type(source, SOURCE_PATH, message="A source id is needed.") source_id = get_source_id(source) if source_id: return self._delete("%s%s" % (self.url, source_id))
def fusion_is_ready(self, fusion, **kwargs): """Checks whether a fusion's status is FINISHED. """ check_resource_type(fusion, FUSION_PATH, message="A fusion id is needed.") resource = self.get_fusion(fusion, **kwargs) return resource_is_ready(resource)
def cluster_is_ready(self, cluster, **kwargs): """Checks whether a cluster's status is FINISHED. """ check_resource_type(cluster, CLUSTER_PATH, message="A cluster id is needed.") resource = self.get_cluster(cluster, **kwargs) return resource_is_ready(resource)
def delete_association(self, association): """Deletes an association. """ check_resource_type(association, ASSOCIATION_PATH, message="An association id is needed.") association_id = get_association_id(association) if association_id: return self._delete("%s%s" % (self.url, association_id))
def anomaly_is_ready(self, anomaly, **kwargs): """Checks whether an anomaly detector's status is FINISHED. """ check_resource_type(anomaly, ANOMALY_PATH, message="An anomaly id is needed.") resource = self.get_anomaly(anomaly, **kwargs) return resource_is_ready(resource)
def get_anomaly_score(self, anomaly_score): """Retrieves an anomaly score. """ check_resource_type(anomaly_score, ANOMALY_SCORE_PATH, message="An anomaly score id is needed.") anomaly_score_id = get_anomaly_score_id(anomaly_score) if anomaly_score_id: return self._get("%s%s" % (self.url, anomaly_score_id))
def logistic_regression_is_ready(self, logistic_regression, **kwargs): """Checks whether a logistic regressioin's status is FINISHED. """ check_resource_type(logistic_regression, LOGISTIC_REGRESSION_PATH, message="A logistic regression id is needed.") resource = self.get_logistic_regression(logistic_regression, **kwargs) return resource_is_ready(resource)
def time_series_is_ready(self, time_series, **kwargs): """Checks whether a time series's status is FINISHED. """ check_resource_type(time_series, TIME_SERIES_PATH, message="A time series id is needed.") resource = self.get_time_series(time_series, **kwargs) return resource_is_ready(resource)
def ensemble_is_ready(self, ensemble): """Checks whether a ensemble's status is FINISHED. """ check_resource_type(ensemble, ENSEMBLE_PATH, message="An ensemble id is needed.") resource = self.get_ensemble(ensemble) return resource_is_ready(resource)
def delete_script(self, script): """Deletes a script. """ check_resource_type(script, SCRIPT_PATH, message="A script id is needed.") script_id = get_script_id(script) if script_id: return self._delete("%s%s" % (self.url, script_id))
def delete_dataset(self, dataset): """Deletes a dataset. """ check_resource_type(dataset, DATASET_PATH, message="A dataset id is needed.") dataset_id = get_dataset_id(dataset) if dataset_id: return self._delete("%s%s" % (self.url, dataset_id))
def delete_batch_prediction(self, batch_prediction): """Deletes a batch prediction. """ check_resource_type(batch_prediction, BATCH_PREDICTION_PATH, message="A batch prediction id is needed.") batch_prediction_id = get_batch_prediction_id(batch_prediction) if batch_prediction_id: return self._delete("%s%s" % (self.url, batch_prediction_id))
def delete_library(self, library): """Deletes a library. """ check_resource_type(library, LIBRARY_PATH, message="A library id is needed.") library_id = get_library_id(library) if library_id: return self._delete("%s%s" % (self.url, library_id))
def delete_topic_distribution(self, topic_distribution): """Deletes a topic distribution. """ check_resource_type(topic_distribution, TOPIC_DISTRIBUTION_PATH, message="A topic distribution id is needed.") topic_distribution_id = get_topic_distribution_id(topic_distribution) if topic_distribution_id: return self._delete("%s%s" % (self.url, topic_distribution_id))
def delete_ensemble(self, ensemble): """Deletes a ensemble. """ check_resource_type(ensemble, ENSEMBLE_PATH, message="An ensemble id is needed.") ensemble_id = get_ensemble_id(ensemble) if ensemble_id: return self._delete("%s%s" % (self.url, ensemble_id))
def delete_batch_centroid(self, batch_centroid): """Deletes a batch centroid. """ check_resource_type(batch_centroid, BATCH_CENTROID_PATH, message="A batch centroid id is needed.") batch_centroid_id = get_batch_centroid_id(batch_centroid) if batch_centroid_id: return self._delete("%s%s" % (self.url, batch_centroid_id))
def delete_model(self, model): """Deletes a model. """ check_resource_type(model, MODEL_PATH, message="A model id is needed.") model_id = get_model_id(model) if model_id: return self._delete("%s%s" % (self.url, model_id))
def delete_centroid(self, centroid): """Deletes a centroid. """ check_resource_type(centroid, CENTROID_PATH, message="A centroid id is needed.") centroid_id = get_centroid_id(centroid) if centroid_id: return self._delete("%s%s" % (self.url, centroid_id))
def delete_deepnet(self, deepnet): """Deletes a deepnet. """ check_resource_type(deepnet, DEEPNET_PATH, message="A deepnet id is needed.") deepnet_id = get_deepnet_id(deepnet) if deepnet_id: return self._delete("%s%s" % (self.url, deepnet_id))
def delete_fusion(self, fusion): """Deletes a fusion. """ check_resource_type(fusion, FUSION_PATH, message="A fusion id is needed.") fusion_id = get_fusion_id(fusion) if fusion_id: return self._delete("%s%s" % (self.url, fusion_id))
def update_script(self, script, changes): """Updates a script. """ check_resource_type(script, SCRIPT_PATH, message="A script id is needed.") script_id = get_script_id(script) if script_id: body = json.dumps(changes) return self._update("%s%s" % (self.url, script_id), body)
def update_prediction(self, prediction, changes): """Updates a prediction. """ check_resource_type(prediction, PREDICTION_PATH, message="A prediction id is needed.") prediction_id = get_prediction_id(prediction) if prediction_id: body = json.dumps(changes) return self._update("%s%s" % (self.url, prediction_id), body)
def delete_source(self, source): """Deletes a remote source permanently. """ check_resource_type(source, SOURCE_PATH, message="A source id is needed.") source_id = get_source_id(source) if source_id: return self._delete("%s%s" % (self.url, source_id))
def delete_evaluation(self, evaluation): """Deletes an evaluation. """ check_resource_type(evaluation, EVALUATION_PATH, message="An evaluation id is needed.") evaluation_id = get_evaluation_id(evaluation) if evaluation_id: return self._delete("%s%s" % (self.url, evaluation_id))
def get_association_set(self, association_set, query_string=''): """Retrieves an association set. """ check_resource_type(association_set, ASSOCIATION_SET_PATH, message="An association set id is needed.") association_set_id = get_association_set_id(association_set) if association_set_id: return self._get("%s%s" % (self.url, association_set_id), query_string)
def delete_project(self, project): """Deletes a project. """ check_resource_type(project, PROJECT_PATH, message="A project id is needed.") project_id = get_project_id(project) if project_id: return self._delete("%s%s" % (self.url, project_id), organization=True)
def delete_linear_regression(self, linear_regression): """Deletes a linear regression. """ check_resource_type(linear_regression, LINEAR_REGRESSION_PATH, message="A linear regression id is needed.") linear_regression_id = get_linear_regression_id(linear_regression) if linear_regression_id: return self._delete("%s%s" % (self.url, linear_regression_id))
def delete_cluster(self, cluster): """Deletes a cluster. """ check_resource_type(cluster, CLUSTER_PATH, message="A cluster id is needed.") cluster_id = get_cluster_id(cluster) if cluster_id: return self._delete("%s%s" % (self.url, cluster_id))
def delete_batch_prediction(self, batch_prediction): """Deletes a batch prediction. """ check_resource_type(batch_prediction, BATCH_PREDICTION_PATH, message="A batch prediction id is needed.") batch_prediction_id = get_batch_prediction_id(batch_prediction) if batch_prediction_id: return self._delete("%s%s" % (self.url, batch_prediction_id))
def delete_sample(self, sample): """Deletes a sample. """ check_resource_type(sample, SAMPLE_PATH, message="A sample id is needed.") sample_id = get_sample_id(sample) if sample_id: return self._delete("%s%s" % (self.url, sample_id))
def delete_batch_centroid(self, batch_centroid): """Deletes a batch centroid. """ check_resource_type(batch_centroid, BATCH_CENTROID_PATH, message="A batch centroid id is needed.") batch_centroid_id = get_batch_centroid_id(batch_centroid) if batch_centroid_id: return self._delete("%s%s" % (self.url, batch_centroid_id))
def delete_anomaly_score(self, anomaly_score): """Deletes an anomaly_score. """ check_resource_type(anomaly_score, ANOMALY_SCORE_PATH, message="An anomaly_score id is needed.") anomaly_score_id = get_anomaly_score_id(anomaly_score) if anomaly_score_id: return self._delete("%s%s" % (self.url, anomaly_score_id))
def delete_anomaly(self, anomaly): """Deletes an anomaly detector. """ check_resource_type(anomaly, ANOMALY_PATH, message="An anomaly detector id is needed.") anomaly_id = get_anomaly_id(anomaly) if anomaly_id: return self._delete("%s%s" % (self.url, anomaly_id))
def delete_dataset(self, dataset): """Deletes a dataset. """ check_resource_type(dataset, DATASET_PATH, message="A dataset id is needed.") dataset_id = get_dataset_id(dataset) if dataset_id: return self._delete("%s%s" % (self.url, dataset_id))
def delete_association_set(self, association_set): """Deletes an association set. """ check_resource_type(association_set, ASSOCIATION_SET_PATH, message="An association set id is needed.") association_set_id = get_association_set_id(association_set) if association_set_id: return self._delete("%s%s" % (self.url, association_set_id))
def delete_projection(self, projection): """Deletes a projection. """ check_resource_type(projection, PROJECTION_PATH, message="A projection id is needed.") projection_id = get_projection_id(projection) if projection_id: return self._delete("%s%s" % (self.url, projection_id))
def update_evaluation(self, evaluation, changes): """Updates an evaluation. """ check_resource_type(evaluation, EVALUATION_PATH, message="An evaluation id is needed.") evaluation_id = get_evaluation_id(evaluation) if evaluation_id: body = json.dumps(changes) return self._update("%s%s" % (self.url, evaluation_id), body)
def update_project(self, project, changes): """Updates a project. """ check_resource_type(project, PROJECT_PATH, message="A project id is needed.") project_id = get_project_id(project) if project_id: body = json.dumps(changes) return self._update("%s%s" % (self.url, project_id), body)
def delete_topic_model(self, topic_model): """Deletes a Topic Model. """ check_resource_type(topic_model, TOPIC_MODEL_PATH, message="A topic model id is needed.") topic_model_id = get_topic_model_id(topic_model) if topic_model_id: return self._delete("%s%s" % (self.url, topic_model_id))
def delete_ensemble(self, ensemble): """Deletes a ensemble. """ check_resource_type(ensemble, ENSEMBLE_PATH, message="An ensemble id is needed.") ensemble_id = get_ensemble_id(ensemble) if ensemble_id: return self._delete("%s%s" % (self.url, ensemble_id))
def delete_correlation(self, correlation): """Deletes a correlation. """ check_resource_type(correlation, CORRELATION_PATH, message="A correlation id is needed.") correlation_id = get_correlation_id(correlation) if correlation_id: return self._delete("%s%s" % (self.url, correlation_id))
def delete_time_series(self, time_series): """Deletes a time series. """ check_resource_type(time_series, TIME_SERIES_PATH, message="A time series id is needed.") time_series_id = get_time_series_id(time_series) if time_series_id: return self._delete("%s%s" % (self.url, time_series_id))
def update_topic_model(self, topic_model, changes): """Updates a Topic Model. """ check_resource_type(topic_model, TOPIC_MODEL_PATH, message="A topic model id is needed.") topic_model_id = get_topic_model_id(topic_model) if topic_model_id: body = json.dumps(changes) return self._update("%s%s" % (self.url, topic_model_id), body)
def update_anomaly(self, anomaly, changes): """Updates an anomaly detector. """ check_resource_type(anomaly, ANOMALY_PATH, message="An anomaly detector id is needed.") anomaly_id = get_anomaly_id(anomaly) if anomaly_id: body = json.dumps(changes) return self._update("%s%s" % (self.url, anomaly_id), body)
def delete_forecast(self, forecast): """Deletes a forecast. """ check_resource_type(forecast, FORECAST_PATH, message="A forecast id is needed.") forecast_id = get_forecast_id(forecast) if forecast_id: return self._delete("%s%s" % (self.url, forecast_id))
def update_association_set(self, association_set, changes): """Updates a association set. """ check_resource_type(association_set, ASSOCIATION_SET_PATH, message="An association set id is needed.") association_set_id = get_association_set_id(association_set) if association_set_id: body = json.dumps(changes) return self._update("%s%s" % (self.url, association_set_id), body)
def delete_logistic_regression(self, logistic_regression): """Deletes a logistic regression. """ check_resource_type(logistic_regression, LOGISTIC_REGRESSION_PATH, message="A logistic regression id is needed.") logistic_regression_id = get_logistic_regression_id( logistic_regression) if logistic_regression_id: return self._delete("%s%s" % (self.url, logistic_regression_id))
def update_deepnet(self, deepnet, changes): """Updates a deepnet. """ check_resource_type(deepnet, DEEPNET_PATH, message="A deepnet id is needed.") deepnet_id = get_deepnet_id(deepnet) if deepnet_id: body = json.dumps(changes) return self._update("%s%s" % (self.url, deepnet_id), body)