Source code for orm.compartment

from typing import List
from decimal import Decimal

import sqlalchemy as sql
from sqlalchemy.orm import (
    mapped_column,
    relationship,
    Mapped,
)

from app.model.orm.orm_base import OrmBase


[docs] class Compartment(OrmBase):
[docs] __tablename__ = "Compartments"
[docs] id: Mapped[int] = mapped_column(primary_key=True)
[docs] name: Mapped[str] = mapped_column(sql.String(100), nullable=False)
# Note: convert to studyUniqueID or delete
[docs] studyId: Mapped[str] = mapped_column(sql.ForeignKey('Studies.studyId'), nullable=False)
[docs] study: Mapped['Study'] = relationship(back_populates='compartments')
[docs] volume: Mapped[Decimal] = mapped_column(sql.Numeric(7, 2), nullable=True)
[docs] pressure: Mapped[Decimal] = mapped_column(sql.Numeric(7, 2), nullable=True)
[docs] stirringSpeed: Mapped[Decimal] = mapped_column(sql.Numeric(7, 2), nullable=True)
[docs] stirringMode: Mapped[str] = mapped_column(sql.String(50), nullable=True)
[docs] O2: Mapped[Decimal] = mapped_column(sql.Numeric(7, 2), nullable=True)
[docs] CO2: Mapped[Decimal] = mapped_column(sql.Numeric(7, 2), nullable=True)
[docs] H2: Mapped[Decimal] = mapped_column(sql.Numeric(7, 2), nullable=True)
[docs] N2: Mapped[Decimal] = mapped_column(sql.Numeric(7, 2), nullable=True)
[docs] inoculumConcentration: Mapped[Decimal] = mapped_column(sql.Numeric(20, 3), nullable=True)
[docs] inoculumVolume: Mapped[Decimal] = mapped_column(sql.Numeric(7, 2), nullable=True)
[docs] initialPh: Mapped[Decimal] = mapped_column(sql.Numeric(7, 2), nullable=True)
[docs] initialTemperature: Mapped[Decimal] = mapped_column(sql.Numeric(7, 2), nullable=True)
[docs] mediumName: Mapped[str] = mapped_column(sql.String(100), nullable=True)
[docs] mediumUrl: Mapped[str] = mapped_column(sql.String(100), nullable=True)
[docs] experimentCompartments: Mapped[List['ExperimentCompartment']] = relationship(back_populates='compartment')
[docs] experiments: Mapped[List['Experiment']] = relationship( secondary="ExperimentCompartments", viewonly=True )
[docs] measurementContexts: Mapped[List['MeasurementContext']] = relationship(back_populates='compartment')
[docs] measurements: Mapped[List['Measurement']] = relationship( order_by='Measurement.timeInSeconds', secondary='MeasurementContexts', viewonly=True, )
@property
[docs] def properties_description(self): properties = { "volume": (self.volume, 'mL'), "pressure": (self.pressure, 'atm'), "stirring mode": (self.stirringMode, ''), "stirring speed": (self.stirringSpeed, 'rpm'), "O<sub>2</sub>": (self.O2, '%'), "CO<sub>2</sub>": (self.CO2, '%'), "H<sub>2</sub>": (self.H2, '%'), "N<sub>2</sub>": (self.N2, '%'), "inoculum concentration": (self.inoculumConcentration, ' Cells/mL'), "inoculum volume": (self.inoculumVolume, ' mL'), "initial pH": (self.initialPh, ''), "initial temperature": (self.initialTemperature, '°C'), } formatted_properties = [ f"<strong>{v}{units}</strong> {k}" for (k, (v, units)) in properties.items() if v is not None and v != '' ] return ', '.join(formatted_properties)