Fixed details attribute
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
0755d8453e
commit
7650ae2369
@ -5,7 +5,7 @@ from sqlalchemy.dialects.postgresql import UUID
|
|||||||
|
|
||||||
class SVMDetails(db.Model):
|
class SVMDetails(db.Model):
|
||||||
aimodel_id = db.Column(UUID(as_uuid=True), db.ForeignKey("ai_model.id"), nullable=False, primary_key=True)
|
aimodel_id = db.Column(UUID(as_uuid=True), db.ForeignKey("ai_model.id"), nullable=False, primary_key=True)
|
||||||
aimodel = db.relationship("AIModel", backref=db.backref("details", lazy=True, cascade="save-update, merge, delete, delete-orphan"))
|
aimodel = db.relationship("AIModel", backref=db.backref("details", lazy=True, cascade="save-update, merge, delete, delete-orphan"))
|
||||||
|
|
||||||
# details
|
# details
|
||||||
mid_window = db.Column(db.Float)
|
mid_window = db.Column(db.Float)
|
||||||
|
@ -1,18 +1,31 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
from typing import Optional
|
||||||
from marshmallow import fields
|
from marshmallow import fields
|
||||||
from marshmallow_sqlalchemy import ModelSchema
|
from marshmallow_sqlalchemy import ModelSchema
|
||||||
from marshmallow_enum import EnumField
|
from marshmallow_enum import EnumField
|
||||||
from model import AIModel, AIModelType
|
from model import AIModel, AIModelType
|
||||||
|
|
||||||
|
from .svmdetails_schema import SVMDetailsSchema
|
||||||
|
|
||||||
|
|
||||||
class AIModelSchema(ModelSchema):
|
class AIModelSchema(ModelSchema):
|
||||||
|
|
||||||
|
_svm_details_schema = SVMDetailsSchema(many=False, exclude=["aimodel"])
|
||||||
|
|
||||||
default = fields.Method("boolize_default", dump_only=True)
|
default = fields.Method("boolize_default", dump_only=True)
|
||||||
|
|
||||||
|
details = fields.Method("pluck_details", dump_only=True)
|
||||||
|
|
||||||
type = EnumField(AIModelType)
|
type = EnumField(AIModelType)
|
||||||
|
|
||||||
def boolize_default(self, ai_model) -> bool:
|
def boolize_default(self, ai_model) -> bool:
|
||||||
return bool(ai_model.default)
|
return bool(ai_model.default)
|
||||||
|
|
||||||
|
def pluck_details(self, ai_model) -> Optional[dict]:
|
||||||
|
if ai_model.details:
|
||||||
|
return self._svm_details_schema.dump(ai_model.details[0])
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = AIModel
|
model = AIModel
|
||||||
|
10
model_service/schemas/svmdetails_schema.py
Normal file
10
model_service/schemas/svmdetails_schema.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
from marshmallow import fields
|
||||||
|
from marshmallow_sqlalchemy import ModelSchema
|
||||||
|
from model import SVMDetails
|
||||||
|
|
||||||
|
|
||||||
|
class SVMDetailsSchema(ModelSchema):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = SVMDetails
|
Loading…
Reference in New Issue
Block a user