Skip to content

Commit

Permalink
fixes #18 : prediction result of an algorithm when no model/dataset e…
Browse files Browse the repository at this point in the history
…xists
  • Loading branch information
mukeshmk committed Jul 20, 2020
1 parent 8f3e2b9 commit 4933378
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/api.py
Original file line number Diff line number Diff line change
@@ -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 *

Expand Down Expand Up @@ -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)


Expand All @@ -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)


Expand All @@ -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)


Expand All @@ -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
Expand Down

0 comments on commit 4933378

Please sign in to comment.