Skip to content

Commit

Permalink
handled storing NUL char as a string in db
Browse files Browse the repository at this point in the history
  • Loading branch information
mukeshmk committed Feb 15, 2020
1 parent 625be5b commit 1ca241d
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@app.route('/metric', methods=['POST'])
def add_metric():
algorithm_name = request.json['algorithm_name']
dataset_hash = request.json['dataset_hash']
dataset_hash = request.json['dataset_hash'].replace("\x00", "")
metric_name = request.json['metric_name']
metric_value = request.json['metric_value']

Expand Down Expand Up @@ -64,15 +64,10 @@ def get_metric(id):
def update_metric(id):
metric = Metric.query.get(id)

algorithm_name = request.json['algorithm_name']
dataset_hash = request.json['dataset_hash']
metric_name = request.json['metric_name']
metric_value = request.json['metric_value']

metric.algorithm_name = algorithm_name
metric.dataset_hash = dataset_hash
metric.metric_name = metric_name
metric.metric_value = metric_value
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()

Expand All @@ -91,7 +86,8 @@ def delete_metric(id):
# 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']
dataset_hash = request.json['dataset_hash'].replace("\x00", "")

all_metrics = Metric.query.filter_by(dataset_hash=dataset_hash).all()
result = metrics_schema.dump(all_metrics)
return jsonify(result)
Expand All @@ -100,7 +96,7 @@ def retrieve_algorithm_list():
# 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']
dataset_hash = request.json['dataset_hash'].replace("\x00", "")

metric = db.Table('metrics', db.metadata, autoload=True, autoload_with=db.engine)

Expand All @@ -114,7 +110,7 @@ def retrieve_algorithm_best_min():
# 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']
dataset_hash = request.json['dataset_hash'].replace("\x00", "")

metric = db.Table('metrics', db.metadata, autoload=True, autoload_with=db.engine)

Expand All @@ -124,6 +120,7 @@ def retrieve_algorithm_best_max():
.where(metric.columns.dataset_hash.in_([dataset_hash]))
).first()
return metric_schema.jsonify(all_metrics)

# Run Server
if __name__ == '__main__':
app.run()

0 comments on commit 1ca241d

Please sign in to comment.