diff --git a/src/api.py b/src/api.py index aeb9f9c..45ae8ac 100644 --- a/src/api.py +++ b/src/api.py @@ -1,5 +1,7 @@ -from flask import Blueprint, Flask, request, jsonify +import math +import json import pandas as pd +from flask import Blueprint, Flask, request, jsonify from src.utils.constants import * @@ -65,6 +67,11 @@ def retrieve_algorithm_list(): all_metrics = Metric.query.filter_by(dataset_hash=dataset_hash).all() + if all_metrics == []: + data = {} + data['response'] = 'Information about the requested dataset is unavailable in the Server!' + return json.dumps(data) + return metrics_schema.jsonify(all_metrics) @@ -75,6 +82,11 @@ def retrieve_algorithm_best_min(): metric = Metric.query.filter_by(dataset_hash=dataset_hash).order_by(Metric.metric_value.asc()).first() + if metric is None: + data = {} + data['response'] = 'Information about the requested dataset is unavailable in the Server!' + return json.dumps(data) + return metric_schema.jsonify(metric) @@ -85,6 +97,11 @@ def retrieve_algorithm_best_max(): metric = Metric.query.filter_by(dataset_hash=dataset_hash).order_by(Metric.metric_value.desc()).first() + if metric is None: + data = {} + data['response'] = 'Information about the requested dataset is unavailable in the Server!' + return json.dumps(data) + return metric_schema.jsonify(metric) @@ -98,6 +115,10 @@ def predict_fmlearn(): data = {} + if fml._new_recs == math.inf: + data['response'] = 'Model not trained!' + return json.dumps(data) + # fetching the encoder for target type for encoding the input data tt_encoder = fml.get_encoders()[utils.TARGET_TYPE] # fetching the columns used in the dataframe for the said encoder