def get_recipe_service(recipe_id):
    if recipe_id in recipes:
        data = recipes[recipe_id]
        return generic_response(status_code=200,
                                success=True,
                                message="Recipe found successfully",
                                data=data)
    else:
        return generic_response(status_code=404,
                                success=False,
                                message="Recipe doesn't exist")
Esempio n. 2
0
def run_code_service(incoming):
    model_name = incoming[MODEL_NAME]
    file_path = CODE_GENERATION_LOCATION + model_name + CODE_GENERATION_TYPE
    if os.path.isfile(file_path):
        run_command("python " + file_path)
        return generic_response(status_code=200,
                                success=True,
                                message="Model executed successfully.")
    else:
        return generic_response(status_code=400,
                                success=False,
                                message="Model file not found.")
Esempio n. 3
0
def add_target_service(incoming):
    file_id = incoming[FILE_ID]
    target = incoming[FILE_TARGET_FIELD]

    if DataFile.query.filter_by(id=file_id).count() > 0:
        data_process = DataProcess(
            file_id=file_id,
            file=DataFile.query.filter_by(id=file_id).first(),
            target=target)
        save_one_record(record=data_process)
        return generic_response(status_code=201,
                                success=True,
                                message="Target field added successfully")
    else:
        return generic_response(status_code=400,
                                success=False,
                                message="File doesn't exist in DB")
Esempio n. 4
0
def delete_one_target_by_id_service(file_id):
    if DataFile.query.filter_by(id=file_id).count() > 0:
        if DataProcess.query.filter_by(file_id=file_id).count() > 0:
            target_record = DataProcess.query.filter_by(
                file_id=file_id).first()
            delete_one_record(record=target_record)
            return generic_response(
                status_code=200,
                success=True,
                message="Target field deleted successfully")
        else:
            return generic_response(status_code=400,
                                    success=False,
                                    message="Target field doesn't exist")
    else:
        return generic_response(status_code=400,
                                success=False,
                                message="File doesn't exist in DB")
Esempio n. 5
0
def get_available_model_list():
    model_list = ModelBasic.query.all()
    data = []
    for model in model_list:
        data.append(model.model_name)
    return generic_response(status_code=200,
                            success=True,
                            message="Model list generated successfully.",
                            data=data)
def add_recipe_service(incoming):
    recipe = Recipe(name=incoming["name"],
                    ingredient=incoming["ingredient"],
                    unit=incoming["unit"],
                    qty=incoming["qty"])
    save_one_record(record=recipe)
    return generic_response(status_code=201,
                            success=True,
                            message="Recipe added successfully",
                            data=incoming)
Esempio n. 7
0
def delete_one_file_by_id_service(file_id):
    # Check file exists in DB and check the file in ./data directory if exist, file deleted
    if DataFile.query.filter_by(id=file_id).count() > 0:
        file = DataFile.query.filter_by(id=file_id).first()
        if os.path.isfile(upload_folder + "/" + file.file_name + "." +
                          file.file_type):
            os.remove(upload_folder + "/" + file.file_name + "." +
                      file.file_type)
            delete_one_record(record=file)
            return generic_response(status_code=200,
                                    success=True,
                                    message="Files deleted successfully")
        else:
            return generic_response(status_code=400,
                                    success=False,
                                    message="File not found")
    else:
        return generic_response(status_code=400,
                                success=False,
                                message="File not in the DB")
Esempio n. 8
0
def get_code_service(incoming):
    model_name = incoming[MODEL_NAME]
    file_path = CODE_GENERATION_LOCATION + model_name + CODE_GENERATION_TYPE
    if os.path.isfile(file_path):
        # file = open(file_path, FILE_OPEN_MODE_READ)
        # data = file.read()
        # file.close()
        return send_file(path_or_file=file_path, as_attachment=True)
        # return generic_response(status_code=200, success=True, message="Code retrieved successfully.", data=data)
    else:
        return generic_response(status_code=400,
                                success=False,
                                message="Code retrieve failed.")
Esempio n. 9
0
def model_validate_service(incoming):
    # Generate basic model and config records
    model = ModelBasic(model_name=incoming[MODEL][MODEL_NAME],
                       model_dataset=incoming[CODE][DATASET][FILE_ID],
                       model_type=incoming[CODE][PROBLEM_TYPE],
                       target_class=incoming[CODE][DATASET][FILE_TARGET])

    configs = []
    params = flatten(incoming, separator=".")
    for param in params:
        configs.append(
            ModelConfigs(model_id=model.id,
                         parameter=param,
                         value=params[param]))

    save_one_record(record=model)
    save_multiple_records(records=configs)

    # Model validation and code generation
    model_generated = model_generation(model_params=incoming[MODEL])

    if model_generated:
        code_generated = code_generation(code_params=incoming[CODE])
        if not code_generated:
            return generic_response(
                status_code=400,
                success=False,
                message=
                "Model validated successfully but code generation unsuccessful."
            )
        else:
            return generic_response(
                status_code=200,
                success=True,
                message="Model successfully validated and code generated.")
    else:
        return generic_response(status_code=400,
                                success=False,
                                message="Whole validation process failed")
Esempio n. 10
0
def add_file_service():
    # Extract the file and save it in the ./data folder
    file = request.files["data"]
    filename = secure_filename(file.filename)
    file.save(os.path.join(upload_folder, filename))

    # Extract the file name and type and save details in the database
    file_name_db = file.filename.rsplit('.', 1)[0].lower()
    file_type_db = file.filename.rsplit('.', 1)[1].lower()
    data = DataFile(file_name=file_name_db, file_type=file_type_db)
    save_one_record(record=data)

    return generic_response(status_code=201,
                            success=True,
                            message="File saved successfully")
Esempio n. 11
0
def get_one_target_by_id_service(file_id):
    if DataFile.query.filter_by(id=file_id).count() > 0:
        if DataProcess.query.filter_by(file_id=file_id).count() > 0:
            target_record = DataProcess.query.filter_by(
                file_id=file_id).first()
            data = {
                FILE_NAME: target_record.file.file_name,
                FILE_TYPE: target_record.file.file_type,
                FILE_TARGET: target_record.target
            }
            return generic_response(
                status_code=200,
                success=True,
                message="Target fields of all files received successfully",
                data=data)
        else:
            return generic_response(status_code=400,
                                    success=False,
                                    message="Target field doesn't exist")

    else:
        return generic_response(status_code=400,
                                success=False,
                                message="File doesn't exist in DB")
Esempio n. 12
0
def get_all_targets_service():
    process_files = DataProcess.query.all()
    data = []
    for file in process_files:
        data.append({
            FILE_ID: file.file_id,
            FILE_NAME: file.file.file_name,
            FILE_TYPE: file.file.file_type,
            FILE_TARGET: file.target
        })
    return generic_response(
        status_code=200,
        success=True,
        message="Target fields of all files received successfully",
        data=data)
Esempio n. 13
0
def get_all_files_service():
    data = []
    files = DataFile.query.all()
    for file in files:
        df = pd.read_csv(upload_folder + "/" + file.file_name + "." +
                         file.file_type)
        fields = list(df.columns)
        data.append({
            FILE_NAME: file.file_name,
            FILE_TYPE: file.file_type,
            FILE_ID: file.id,
            FILE_FIELDS: fields
        })
    return generic_response(status_code=200,
                            success=True,
                            message="Saved files found successfully",
                            data=data)