Skip to content

Commit

Permalink
merge pull request #11 from mukeshmk/ui
Browse files Browse the repository at this point in the history
WIP: restructured the application and added UI
  • Loading branch information
mukeshmk authored Jun 2, 2020
2 parents 2e4a606 + 32ecf89 commit ea7b402
Show file tree
Hide file tree
Showing 25 changed files with 4,801 additions and 119 deletions.
123 changes: 16 additions & 107 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import os
from config import *
from constants import *
from flask import Flask, request, jsonify
from flask import Flask, render_template
from flask_sqlalchemy import SQLAlchemy
from flask_marshmallow import Marshmallow

app = Flask(__name__)
from src.config import *
from src.utils.constants import METRIC

app = Flask(__name__, template_folder='src/templates', static_folder='src/static')

if ENV == 'dev':
app.debug = True
Expand All @@ -21,112 +21,21 @@
# Init ma
ma = Marshmallow(app)

from data_models.Metrics import *
from data_models.Params import *
from data_models.MetaFeatures import *

# Create a Metric
@app.route(METRIC, methods=[POST])
def add_metric():
algorithm_name = request.json['algorithm_name']
dataset_hash = request.json['dataset_hash'].replace("\x00", "")
metric_name = request.json['metric_name']
metric_value = request.json['metric_value']

target_type = request.json['target_type']

new_metric = Metric(algorithm_name, dataset_hash, metric_name, metric_value, target_type)

db.session.add(new_metric)
db.session.commit()

params = request.json['params']
if(params != ""):
for param in params:
new_params = Params(new_metric.id, param['param_name'], param['param_value'])
db.session.add(new_params)
db.session.commit()

data_meta_features = request.json['data_meta_features']
if(data_meta_features != ""):
for feat in data_meta_features:
new_feat = MetaFeature(new_metric.id, feat['feat_name'], feat['feat_value'])
db.session.add(new_feat)
db.session.commit()

return metric_schema.jsonify(new_metric)



# Get All Metrics
@app.route(METRIC, methods=[GET])
def get_metrics():
all_metrics = Metric.query.all()
result = metrics_schema.dump(all_metrics)
if len(result) > 0:
return jsonify(result)
else:
return jsonify('No Metric')


# Get Single Metric
@app.route(METRIC + VAR_ID, methods=[GET])
def get_metric(id):
metric = Metric.query.get(id)
return metric_schema.jsonify(metric)


# Update a Metric
@app.route(METRIC + VAR_ID, methods=[PUT])
def update_metric(id):
metric = Metric.query.get(id)

metric.algorithm_name = request.json['algorithm_name']
metric.dataset_hash = request.json['dataset_hash'].replace("\x00", "")
metric.metric_name = request.json['metric_name']
metric.metric_value = request.json['metric_value']

db.session.commit()

return metric_schema.jsonify(metric)


# Delete Metric
@app.route(METRIC + VAR_ID, methods=[DEL])
def delete_metric(id):
metric = Metric.query.get(id)
db.session.delete(metric)
db.session.commit()

return metric_schema.jsonify(metric)

# Retrieve all metric that matches the dataset_hash
@app.route(METRIC + RETRIEVE + ALL, methods=[POST])
def retrieve_algorithm_list():
dataset_hash = request.json['dataset_hash'].replace("\x00", "")

all_metrics = Metric.query.filter_by(dataset_hash=dataset_hash).all()

return metrics_schema.jsonify(all_metrics)


# Retrieve metric that best matches the dataset_hash
@app.route(METRIC + RETRIEVE + MIN, methods=[POST])
def retrieve_algorithm_best_min():
dataset_hash = request.json['dataset_hash'].replace("\x00", "")

metric = Metric.query.filter_by(dataset_hash=dataset_hash).order_by(Metric.metric_value.asc()).first()
from src.api import metrics_api

return metric_schema.jsonify(metric)
app.register_blueprint(metrics_api, url_prefix=METRIC)

# Retrieve metric that best matches the dataset_hash
@app.route(METRIC + RETRIEVE + MAX, methods=[POST])
def retrieve_algorithm_best_max():
dataset_hash = request.json['dataset_hash'].replace("\x00", "")
# added route for index.html webpage
@app.route('/')
@app.route('/index.html')
def index():
return render_template('index.html')

metric = Metric.query.filter_by(dataset_hash=dataset_hash).order_by(Metric.metric_value.desc()).first()
# added route for api-description webpage
@app.route('/api-description.html')
def apidescription():
return render_template('api-description.html')

return metric_schema.jsonify(metric)

# Run Server
if __name__ == '__main__':
Expand Down
114 changes: 114 additions & 0 deletions src/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
from flask import Blueprint, Flask, request, jsonify

from src.utils.constants import *

metrics_api = Blueprint('metrics_api', __name__)

from src.data_models.Metrics import *
from src.data_models.Params import *
from src.data_models.MetaFeatures import *

from app import db

# Create a Metric
@metrics_api.route('', methods=[POST])
def add_metric():
algorithm_name = request.json['algorithm_name']
dataset_hash = request.json['dataset_hash'].replace("\x00", "")
metric_name = request.json['metric_name']
metric_value = request.json['metric_value']

target_type = request.json['target_type']

new_metric = Metric(algorithm_name, dataset_hash, metric_name, metric_value, target_type)

db.session.add(new_metric)
db.session.commit()

params = request.json['params']
if(params != ""):
for param in params:
new_params = Params(new_metric.id, param['param_name'], param['param_value'])
db.session.add(new_params)
db.session.commit()

data_meta_features = request.json['data_meta_features']
if(data_meta_features != ""):
for feat in data_meta_features:
new_feat = MetaFeature(new_metric.id, feat['feat_name'], feat['feat_value'])
db.session.add(new_feat)
db.session.commit()

return metric_schema.jsonify(new_metric)



# Get All Metrics
@metrics_api.route('', methods=[GET])
def get_metrics():
all_metrics = Metric.query.all()
result = metrics_schema.dump(all_metrics)
if len(result) > 0:
return jsonify(result)
else:
return jsonify('No Metric')


# Get Single Metric
@metrics_api.route(VAR_ID, methods=[GET])
def get_metric(id):
metric = Metric.query.get(id)
return metric_schema.jsonify(metric)


# Update a Metric
@metrics_api.route(VAR_ID, methods=[PUT])
def update_metric(id):
metric = Metric.query.get(id)

metric.algorithm_name = request.json['algorithm_name']
metric.dataset_hash = request.json['dataset_hash'].replace("\x00", "")
metric.metric_name = request.json['metric_name']
metric.metric_value = request.json['metric_value']

db.session.commit()

return metric_schema.jsonify(metric)


# Delete Metric
@metrics_api.route(VAR_ID, methods=[DEL])
def delete_metric(id):
metric = Metric.query.get(id)
db.session.delete(metric)
db.session.commit()

return metric_schema.jsonify(metric)

# Retrieve all metric that matches the dataset_hash
@metrics_api.route(RETRIEVE + ALL, methods=[POST])
def retrieve_algorithm_list():
dataset_hash = request.json['dataset_hash'].replace("\x00", "")

all_metrics = Metric.query.filter_by(dataset_hash=dataset_hash).all()

return metrics_schema.jsonify(all_metrics)


# Retrieve metric that best matches the dataset_hash
@metrics_api.route(RETRIEVE + MIN, methods=[POST])
def retrieve_algorithm_best_min():
dataset_hash = request.json['dataset_hash'].replace("\x00", "")

metric = Metric.query.filter_by(dataset_hash=dataset_hash).order_by(Metric.metric_value.asc()).first()

return metric_schema.jsonify(metric)

# Retrieve metric that best matches the dataset_hash
@metrics_api.route(RETRIEVE + MAX, methods=[POST])
def retrieve_algorithm_best_max():
dataset_hash = request.json['dataset_hash'].replace("\x00", "")

metric = Metric.query.filter_by(dataset_hash=dataset_hash).order_by(Metric.metric_value.desc()).first()

return metric_schema.jsonify(metric)
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from app import db, ma
from constants import TABLE_META_FEATURES
from src.utils.constants import TABLE_META_FEATURES


# Meta Feature Class/Model
Expand Down
6 changes: 3 additions & 3 deletions data_models/Metrics.py → src/data_models/Metrics.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from app import db, ma
from data_models.Params import ParamSchema
from data_models.MetaFeatures import MetaFeatureSchema
from constants import TABLE_METRIC, CLASS_PARAM, CLASS_META_FEATURE
from src.data_models.Params import ParamSchema
from src.data_models.MetaFeatures import MetaFeatureSchema
from src.utils.constants import TABLE_METRIC, CLASS_PARAM, CLASS_META_FEATURE

# Metric Class/Model
class Metric(db.Model):
Expand Down
2 changes: 1 addition & 1 deletion data_models/Params.py → src/data_models/Params.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from app import db, ma
from constants import TABLE_PARAM
from src.utils.constants import TABLE_PARAM


# Param Class/Model
Expand Down
8 changes: 4 additions & 4 deletions fmlearn.py → src/fmlearn.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import pandas as pd
import utils

from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsRegressor

from src.utils import utils

def kmc():
df = utils.get_df_from_db()
df.fillna(0, inplace=True)
Expand All @@ -27,7 +27,7 @@ def kmc():

print(y_test.to_string(header=False))
y_pred = pd.DataFrame(y_pred)
print(y_pred.to_string(header=False))
return y_pred.to_string(header=False)

if __name__ == "__main__":
kmc()
kmc()
4 changes: 4 additions & 0 deletions src/static/assets/css/font-awesome.min.css

Large diffs are not rendered by default.

Loading

0 comments on commit ea7b402

Please sign in to comment.