def create_model(): database_url = os.environ[DATABASE_URL] database_replica_set = os.environ[DATABASE_REPLICA_SET] database_name = os.environ[DATABASE_NAME] train_filename = request.json[TRAINING_FILENAME] test_filename = request.json[TEST_FILENAME] classifiers_name = request.json[CLASSIFIERS_NAME] database = Database( database_url, database_replica_set, os.environ[DATABASE_PORT], database_name, ) request_validator = UserRequest(database) request_errors = analyse_request_errors( request_validator, train_filename, test_filename, classifiers_name) if request_errors is not None: return request_errors database_url_training = Database.collection_database_url( database_url, database_name, train_filename, database_replica_set, ) database_url_test = Database.collection_database_url( database_url, database_name, test_filename, database_replica_set, ) metadata_creator = Metadata(database, train_filename, test_filename) model_builder = Model(database, metadata_creator, database_url_training, database_url_test) model_builder.build( request.json[MODELING_CODE_NAME], classifiers_name ) return ( jsonify({ MESSAGE_RESULT: create_prediction_files_uri( classifiers_name, test_filename)}), HTTP_STATUS_CODE_SUCCESS_CREATED, )
def predictions_filename_validator(self, test_filename, classifier_list): filenames = self.database.get_filenames() for classifier_name in classifier_list: prediction_filename = Model.create_prediction_filename( test_filename, classifier_name) if prediction_filename in filenames: raise Exception(self.MESSAGE_INVALID_PREDICTION_NAME)
def create_prediction_files_uri(classifiers_list, test_filename): classifiers_uri = [] for classifier in classifiers_list: classifiers_uri.append( MICROSERVICE_URI_GET + Model.create_prediction_filename(test_filename, classifier) + MICROSERVICE_URI_GET_PARAMS) return classifiers_uri
def create_file(self, classifier_name): metadata = self.metadata_document.copy() metadata["classifier"] = classifier_name metadata["datasetName"] = \ Model.create_prediction_filename( self.test_filename, classifier_name) self.database_connector.delete_file(metadata["datasetName"]) self.database_connector.insert_one_in_file(metadata["datasetName"], metadata) return metadata