Implemeted getters

This commit is contained in:
Pünkösd Marcell 2020-04-14 13:48:11 +02:00
parent 43a0fe0ca2
commit f97228b61c
9 changed files with 65 additions and 31 deletions

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python3
from .db import db
from .default import Default
from .details import Details
from .aimodel import AIModel

View File

@ -1,16 +1,18 @@
#!/usr/bin/env python3
from .db import db
from sqlalchemy.sql import func
from sqlalchemy.dialects.postgresql import UUID
import uuid
class Details(db.Model):
id = db.Column(db.Integer, primary_key=True, auto_increment=True)
name = db.Column(db.String(30), key=True)
class AIModel(db.Model):
id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4, unique=True, nullable=False)
timestamp = db.Column(db.TIMESTAMP, nullable=False, server_default=func.now())
# details
mid_window = db.Column(db.Float)
mid_step = db.Column(db.Float)
short_window = db.Column(db.Float)
short_step = db.Column(db.Float)
compute_beat = db.Column(db.Float)
type = db.Column(db.String(15))
type = db.Column(db.String(15))

View File

@ -1,7 +1,8 @@
#!/usr/bin/env python3
from .db import db
from sqlalchemy.dialects.postgresql import UUID
class Default(db.Model):
default_id = db.Column(db.Integer, db.ForeignKey("details.id"), nullable=False)
default = db.relationship("Details")
class Default(db.AIModel):
default_id = db.Column(UUID(as_uuid=True), db.ForeignKey("aimodel.id"), nullable=False)
default = db.relationship("AIModel")

View File

@ -1,3 +1,3 @@
#!/usr/bin/env python3
from .default_schema import DefaultSchema
from .details_schema import DetailsSchema
from .aimodel_schema import AIModelSchema

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python3
from marshmallow import fields
from marshmallow_sqlalchemy import ModelSchema
from model import Details
from model import AIModel
class DetailsSchema(ModelSchema):
class AIModelSchema(ModelSchema):
class Meta:
model = Details
model = AIModel

View File

@ -1,3 +1,4 @@
#!/usr/bin/env python3
from .require_decorators import json_required
from .error_handlers import register_all_error_handlers
from .storage import storage

View File

@ -0,0 +1,3 @@
from flask_minio import Minio
storage = Minio()

View File

@ -1,14 +1,15 @@
#!/usr/bin/env python3
from flask import request, jsonify
import tempfile
from flask import request, jsonify, current_app, abort, Response
from flask_classful import FlaskView, route
from model import db, Default, Details
from schema import DetailsSchema, DefaultSchema
from utils import json_required
from model import db, Default, AIModel
from minio.error import BucketAlreadyExists, BucketAlreadyOwnedByYou, ResponseError, NoSuchKey
from schemas import AIModelSchema, DefaultSchema
from utils import json_required, storage
class ModelView(FlaskView):
details_schema = DetailsSchema(many=False)
aimodel_schema = AIModelSchema(many=False)
default_schema = DefaultSchema(many=False)
@json_required
@ -16,24 +17,43 @@ class ModelView(FlaskView):
return jsonify({})
def get(self, _id: str):
return jsonify({"id": _id})
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
else:
m = AIModel.query.fiter_by(id=_id).first_or_404()
try:
data = storage.connection.get_object(current_app.config['MINIO_BUCKET_NAME'], 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):
return jsonify({"id": _id})
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
else:
m = AIModel.query.fiter_by(id=_id).first_or_404()
return jsonify(self.aimodel_schema.dump(m))
def delete(self, _id: str):
return jsonify({"id": _id})
m = AIModel.query.fiter_by(id=_id).first_or_404()
storage.connection.remove_object(current_app.config['MINIO_BUCKET_NAME'], m.id)
db.session.delete(m)
db.session.commit()
return '', 204
@json_required
@route('$default', methods=['PUT'])
def put_default(self):
Default.query.delete()
#new_default = Default()
db.session.add(new_default)
db.session.commit()
return jsonify(self.default_schema.dump(new_default))
return jsonify({})

View File

@ -9,4 +9,11 @@ SQLAlchemy
marshmallow-sqlalchemy
psycopg2-binary
flask_minio
sentry-sdk
sentry-sdk
pyAudioanalysis
numpy
eyed3
pydub
scipy
matplotlib