Source code for app.model.orm.custom_model

from datetime import datetime

import sqlalchemy as sql
from sqlalchemy.orm import (
    Mapped,
    mapped_column,
    relationship,
    validates,
)
from sqlalchemy_utc.sqltypes import UtcDateTime

from app.model.orm.orm_base import OrmBase
from app.model.lib.modeling import (
    ALL_COEFFICIENTS,
    FIT_PARAMETERS,
)


[docs] class CustomModel(OrmBase): """ The description of a user-created model type. """
[docs] __tablename__ = "CustomModels"
[docs] id: Mapped[int] = mapped_column(primary_key=True)
[docs] studyId: Mapped[int] = mapped_column(sql.ForeignKey('Studies.publicId'), nullable=False)
[docs] study: Mapped['Study'] = relationship(back_populates='customModels')
[docs] name: Mapped[str] = mapped_column(sql.String(255), nullable=False)
[docs] shortName: Mapped[str] = mapped_column(sql.String(5))
[docs] url: Mapped[str] = mapped_column(sql.String(255))
[docs] description: Mapped[str] = mapped_column(sql.String)
[docs] coefficientNames: Mapped[sql.JSON] = mapped_column(sql.JSON, nullable=False)
[docs] fitNames: Mapped[sql.JSON] = mapped_column(sql.JSON, nullable=False)
[docs] createdAt: Mapped[datetime] = mapped_column(UtcDateTime, server_default=sql.FetchedValue())
[docs] updatedAt: Mapped[datetime] = mapped_column(UtcDateTime, server_default=sql.FetchedValue())
@property
[docs] def coefficientInfo(self): return [ {'name': name, **ALL_COEFFICIENTS[name]} for name in self.coefficientNames ]
@property
[docs] def fitInfo(self): return [ {'name': name, **FIT_PARAMETERS[name]} for name in self.fitNames ]