예제 #1
0
def main(req: func.HttpRequest) -> func.HttpResponse:
    url_text = "None"
    config_setting = ConfigSetting()
    log = config_setting.set_logger("[ azure_function ]", os.path.join("tmp/", "logs"))
    log.info('Python HTTP trigger function processed a request.')

    function_http_request = FunctionHttpRequest(req)
    query_text = function_http_request.get_request_value('query_text')
    blob_store = function_http_request.get_request_value('blob_store')

    cassandra_dao = CassandraDao()
    cassandra_dao.connection_setting()
    
    df = cassandra_dao.get_query_data(query_text)
    
    log.info(blob_store)
    if blob_store == "True":
        log.info("存到azure blob中")
        output_csv_file = df.to_csv(index_label="idx", encoding = "utf-8")
        azure_blob_service = AzureBlobService()
        azure_blob_service.connection_setting()
        azure_blob_service.create_file_on_blob(output_csv_file)
        url_text = azure_blob_service.url_download_generate()
    df_json = df.to_json(orient='records',default_handler=str)

            
    json_text = json.dumps({"url":url_text, "data":df_json})
    if query_text:
        return func.HttpResponse(json_text)
    else:
        return func.HttpResponse(
             "Please pass a name on the query string or in the request body",
             status_code=400
        )
 def __init__(self):
     """Initial variable and module"""
     config_setting = ConfigSetting()
     self.log = config_setting.set_logger(
         "[Confusion_matrix_calculation_app]")
     self.config = config_setting.yaml_parser()
     self.confusion_matrix_calculation_service = ConfusionMatrixCalculationService()
 def __init__(self):
     """Initial variable and module"""
     config_setting = ConfigSetting()
     self.log = config_setting.set_logger(
         "[Confusion_matrix_calculation_service]")
     self.config = config_setting.yaml_parser()
     self.confusion_matrix_record_dao = ConfusionMatrixRecordDao()
     self.confusion_matrix_record_dao.setting_confusion_matrix_database()
예제 #4
0
 def __init__(self):
     config_setting = ConfigSetting()
     self.config = config_setting.yaml_parser()
     self.log = config_setting.set_logger(["training_service"])
     self.df = {}
     self.label = []
     self.data = {}
     self.model = None
예제 #5
0
 def __init__(self):
     config_setting = ConfigSetting()
     self.config = config_setting.yaml_parser()
     self.log = config_setting.set_logger(["data_etl_service"])
     self.df = {}
     self.train_label = []
     self.one_hot_encoder = None
     self.label_encoder = LabelEncoder()
예제 #6
0
def create_confusion_matrix_router():
    """The function to creates the fastapi api router service."""5
    config_setting = ConfigSetting()
    log = config_setting.set_logger("[create_confusion_matrix_router]")
    config = config_setting.yaml_parser()

    user_router = APIRouter()
    confusion_matrix_calculation_app = ConfusionMatrixCalculationApp()

    @user_router.post("/json/confusion_matrix")
    def calculate_confusion_matrix(y_true: list, y_pred: list):
        if len(y_true) > 0 and len(y_pred) > 0 and len(y_true) == len(y_pred):
            payload = confusion_matrix_calculation_app.get_confusion_matrix(y_true, y_pred)
        else:
            payload = {"message": "Length error."}
        return payload
    
    @user_router.post("/html/confusion_matrix", response_class=HTMLResponse)
    def calculate_confusion_matrix_html(y_true: list, y_pred: list):
        if len(y_true) > 0 and len(y_pred) > 0 and len(y_true) == len(y_pred):
            confusion_matrix_calculation_app.get_confusion_matrix(y_true, y_pred)
            html = confusion_matrix_calculation_app.get_confusion_matrix_html(y_true, y_pred)
        else:
            html = {"message": "Length error."}
        return html

    @user_router.post("/json/accuracy_score")
    def calculate_accuracy_score(confusion_matrix: ConfusionMatrixBaseModel):
        payload = confusion_matrix_calculation_app.confusion_matrix_to_accuracy_value(confusion_matrix.dict())
        return payload
    
    @user_router.post("/json/prediction_accuracy")
    def calculate_prediction_accuracy(y_true: list, y_pred: list):
        if len(y_true) > 0 and len(y_pred) > 0 and len(y_true) == len(y_pred):
            payload = confusion_matrix_calculation_app.prediction_to_accuracy_value(y_true, y_pred)
        else:
            payload = {"message": "Length error."}
        return payload
    
    @user_router.post("/json/precision_recall_score")
    def calculate_precision_recall_value(confusion_matrix: ConfusionMatrixBaseModel):
        payload = confusion_matrix_calculation_app.confusion_matrix_to_precision_recall_value(confusion_matrix.dict())
        return payload
    
    @user_router.post("/json/prediction_precision_recall")
    def calculate_prediction_precision_recall(y_true: list, y_pred: list):
        if len(y_true) > 0 and len(y_pred) > 0 and len(y_true) == len(y_pred):
            payload = confusion_matrix_calculation_app.prediction_to_precision_recall_value(y_true, y_pred)
        else:
            payload = {"message": "Length error."}
        return payload

    log.info("Successfully setting the api router.")
    return user_router
def create_app(unittest=False):
    """The function to creates the fastapi service."""
    # Initial config and log
    config_setting = ConfigSetting()
    log = config_setting.set_logger("[create_app]")
    config = config_setting.yaml_parser()
    
    app = FastAPI()

    api_router = create_api_router()
    app.include_router(api_router, prefix="/api", tags=["api"])

    confusion_matrix_router = create_confusion_matrix_router()
    app.include_router(confusion_matrix_router, prefix="/confusion_matrix", tags=["confusion_matrix"])

    log.info("Start the fastapi service.")
    return app
def create_api_router():
    """The function to creates the fastapi api router service."""
    config_setting = ConfigSetting()
    log = config_setting.set_logger("[create_api_router]")
    config = config_setting.yaml_parser()

    user_router = APIRouter()
    health_check_information = HealthCheckInformation()

    @user_router.get("/health_check", response_model=HealthCheckBaseModel)
    def health_check():
        """health_check: Check the service is working.
        Returns:
            json format: the health check content.
        """
        return health_check_information.get_health_check_content()
    
    log.info("Successfully setting the api router.")
    return user_router
예제 #9
0
def create_app():
    """Create flask app service."""
    config_setting = ConfigSetting()
    log = config_setting.set_logger("[flask_app]")
    config = config_setting.yaml_parser()
    fast_api_app = FastApiApp()
    app = FastAPI()

    @app.get("/health_check")
    def health_check():
        with open('setup.py', 'r') as f:
            setup_str = f.read()
        # Get version string
        version_str = _pos_string(setup_str, 'project_version=')
        # Get project string
        project_str = _pos_string(setup_str, 'project_name=')
        return {
            'service': project_str,
            'status': '200',
            'version': version_str
        }

    @app.post("/prediction", response_model=Result)
    def prediction(prediction: Prediction):
        data = prediction.dict()
        for index, value in zip(data.keys(), data.values()):
            data[index] = [value]
        result = fast_api_app.prediction(data)
        return {"class_num": result[0]}

    def _pos_string(setup_str, pos_string):
        start_project_pos = setup_str.find(pos_string) + len(pos_string)
        end_project_pos = setup_str.find(',', start_project_pos)
        return setup_str[start_project_pos:end_project_pos].replace("'", '')

    return app
예제 #10
0
 def __init__(self):
     config_setting = ConfigSetting()
     self.config = config_setting.yaml_parser()
     self.log = config_setting.set_logger(["data_etl_app"])
     self.train_eval_service = TrainEvalService()
예제 #11
0
 def __init__(self):
     config_setting = ConfigSetting()
     self.config = config_setting.yaml_parser()
     self.log = config_setting.set_logger(["data_etl_app"])
     self.data_etl_service = DataEtlService()
 def __init__(self, req):
     config_setting = ConfigSetting()
     self.log = config_setting.set_logger("[ azure_function ]",
                                          os.path.join("tmp/", "logs"))
     self.config = config_setting.yaml_parser()
     self.req = req
예제 #13
0
 def __init__(self):
     config_setting = ConfigSetting()
     self.log = config_setting.set_logger("[ azure_function ]", os.path.join("tmp/", "logs"))
     self.config = config_setting.yaml_parser()
     self.blob_service_client = None
     self.file_name = None
예제 #14
0
 def __init__(self):
     config_setting = ConfigSetting()
     self.config = config_setting.yaml_parser()
     self.log = config_setting.set_logger(["data_etl_app"])
     self.fast_api_service = FastApiService()
예제 #15
0
 def __init__(self):
     """Initial variable and module"""
     config_setting = ConfigSetting()
     self.log = config_setting.set_logger("[Confusion_matrix_record_dao]")
     self.config = config_setting.yaml_parser()
     self.sqlite_engine = None