From 4933378638095319133aab0f812e893180cff89c Mon Sep 17 00:00:00 2001 From: Mukesh A Date: Mon, 20 Jul 2020 12:05:43 +0100 Subject: [PATCH] fixes #18 : prediction result of an algorithm when no model/dataset exists --- src/api.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) 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