From 40d20b2fa9034c1efa7feda907f73146fd0eaf5d Mon Sep 17 00:00:00 2001 From: marcsello Date: Tue, 14 Apr 2020 19:42:43 +0200 Subject: [PATCH] Did done --- model_service/views/model_view.py | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/model_service/views/model_view.py b/model_service/views/model_view.py index 4cfbff9..e84a23e 100644 --- a/model_service/views/model_view.py +++ b/model_service/views/model_view.py @@ -13,6 +13,9 @@ from pyAudioAnalysis.audioTrainTest import load_model, load_model_knn class ModelView(FlaskView): aimodel_schema = AIModelSchema(many=False) + aimodels_schema = AIModelSchema(many=True, + exclude=['timestamp', 'mid_window', 'mid_step', 'short_window', 'short_step', + 'compute_beat']) default_schema = DefaultSchema(many=False) info_schema = InfoSchema(many=False) @@ -28,6 +31,10 @@ class ModelView(FlaskView): pass # Everything else should be raised + def index(self): + models = AIModel.query.all() + return jsonify(self.aimodels_schema.dump(models)), 200 + def post(self): # get important data from the request @@ -88,8 +95,8 @@ class ModelView(FlaskView): os.remove(temp_model_filename) os.remove(temp_means_filename) - m = AIModel(mid_window=mid_window, mid_step=mid_step, short_window=short_window, short_step=short_step, - compute_beat=compute_beat, type=info['type']) + m = AIModel(id=info['id'], mid_window=mid_window, mid_step=mid_step, short_window=short_window, + short_step=short_step, compute_beat=compute_beat, type=info['type']) db.session.add(m) db.session.commit() @@ -100,11 +107,21 @@ class ModelView(FlaskView): if _id == "$default": default = Default.query.first_or_404() # TODO: Kitalálni, hogy inkább a latestestest-el térjen-e vissza - m = default.default + m = default.aimodel else: - m = AIModel.query.fiter_by(id=_id).first_or_404() + m = AIModel.query.filter_by(id=_id).first_or_404() - return "asd" + if "means" in request.args: + bucket = current_app.config['MINIO_MEANS_BUCKET_NAME'] + else: + bucket = current_app.config['MINIO_MODEL_BUCKET_NAME'] + + try: + data = storage.connection.get_object(bucket, str(m.id)) + except NoSuchKey: + abort(500, "The ID is stored in the database but not int the Object Store") + + return Response(data.stream(), mimetype=data.headers['Content-type']) @route('<_id>/details') def get_details(self, _id: str): @@ -123,7 +140,7 @@ class ModelView(FlaskView): default = Default.query.first_or_404() m = default.aimodel else: - m = AIModel.query.fiter_by(id=_id).first_or_404() + m = AIModel.query.filter_by(id=_id).first_or_404() storage.connection.remove_object(current_app.config['MINIO_MODEL_BUCKET_NAME'], str(m.id)) storage.connection.remove_object(current_app.config['MINIO_MEANS_BUCKET_NAME'], str(m.id))