Removed logger.debugs for proven functions.
This commit is contained in:
@@ -3,7 +3,6 @@ Contains all models for sqlalchemy
|
||||
"""
|
||||
from __future__ import annotations
|
||||
import sys, logging
|
||||
|
||||
from pandas import DataFrame
|
||||
from sqlalchemy import Column, INTEGER, String, JSON
|
||||
from sqlalchemy.orm import DeclarativeMeta, declarative_base, Query, Session
|
||||
@@ -131,7 +130,6 @@ class BaseClass(Base):
|
||||
search = name.title().replace(" ", "")
|
||||
else:
|
||||
search = name
|
||||
logger.debug(f"Searching for subclass: {search}")
|
||||
return next((item for item in cls.__subclasses__() if item.__name__ == search), cls)
|
||||
|
||||
@classmethod
|
||||
@@ -146,9 +144,7 @@ class BaseClass(Base):
|
||||
List[Any]: Results of sqlalchemy query.
|
||||
"""
|
||||
query: Query = cls.__database_session__.query(cls)
|
||||
# logger.debug(f"Queried model. Now running searches in {kwargs}")
|
||||
for k, v in kwargs.items():
|
||||
# logger.debug(f"Running fuzzy search for attribute: {k} with value {v}")
|
||||
# NOTE: Not sure why this is necessary, but it is.
|
||||
search = f"%{v}%"
|
||||
try:
|
||||
@@ -200,9 +196,7 @@ class BaseClass(Base):
|
||||
model = cls
|
||||
if query is None:
|
||||
query: Query = cls.__database_session__.query(model)
|
||||
# logger.debug(f"Grabbing singles using {model.get_default_info}")
|
||||
singles = model.get_default_info('singles')
|
||||
# logger.info(f"Querying: {model}, with kwargs: {kwargs}")
|
||||
for k, v in kwargs.items():
|
||||
logger.info(f"Using key: {k} with value: {v}")
|
||||
try:
|
||||
@@ -227,7 +221,6 @@ class BaseClass(Base):
|
||||
"""
|
||||
Add the object to the database and commit
|
||||
"""
|
||||
# logger.debug(f"Saving object: {pformat(self.__dict__)}")
|
||||
report = Report()
|
||||
try:
|
||||
self.__database_session__.add(self)
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
Contains the audit log class and functions.
|
||||
"""
|
||||
from typing import List
|
||||
|
||||
from dateutil.parser import parse
|
||||
from sqlalchemy.orm import declarative_base, DeclarativeMeta, Query
|
||||
from . import BaseClass
|
||||
@@ -48,32 +47,24 @@ class AuditLog(Base):
|
||||
logger.warning(f"End date with no start date, using Jan 1, 2023")
|
||||
start_date = session.query(cls, func.min(cls.time)).first()[1]
|
||||
if start_date is not None:
|
||||
# logger.debug(f"Querying with start date: {start_date} and end date: {end_date}")
|
||||
match start_date:
|
||||
case date():
|
||||
# logger.debug(f"Lookup BasicSubmission by start_date({start_date})")
|
||||
start_date = start_date.strftime("%Y-%m-%d")
|
||||
case int():
|
||||
# logger.debug(f"Lookup BasicSubmission by ordinal start_date {start_date}")
|
||||
start_date = datetime.fromordinal(
|
||||
datetime(1900, 1, 1).toordinal() + start_date - 2).date().strftime("%Y-%m-%d")
|
||||
case _:
|
||||
# logger.debug(f"Lookup BasicSubmission by parsed str start_date {start_date}")
|
||||
start_date = parse(start_date).strftime("%Y-%m-%d")
|
||||
match end_date:
|
||||
case date() | datetime():
|
||||
# logger.debug(f"Lookup BasicSubmission by end_date({end_date})")
|
||||
end_date = end_date + timedelta(days=1)
|
||||
end_date = end_date.strftime("%Y-%m-%d")
|
||||
case int():
|
||||
# logger.debug(f"Lookup BasicSubmission by ordinal end_date {end_date}")
|
||||
end_date = datetime.fromordinal(datetime(1900, 1, 1).toordinal() + end_date - 2).date() + timedelta(days=1)
|
||||
end_date = end_date.strftime("%Y-%m-%d")
|
||||
case _:
|
||||
# logger.debug(f"Lookup BasicSubmission by parsed str end_date {end_date}")
|
||||
end_date = parse(end_date) + timedelta(days=1)
|
||||
end_date = end_date.strftime("%Y-%m-%d")
|
||||
# logger.debug(f"Compensating for same date by using time")
|
||||
if start_date == end_date:
|
||||
start_date = datetime.strptime(start_date, "%Y-%m-%d").strftime("%Y-%m-%d %H:%M:%S.%f")
|
||||
query = query.filter(cls.time == start_date)
|
||||
|
||||
@@ -171,11 +171,9 @@ class Control(BaseClass):
|
||||
match submission_type:
|
||||
case str():
|
||||
from backend import BasicSubmission, SubmissionType
|
||||
# logger.debug(f"Lookup controls by SubmissionType str: {submission_type}")
|
||||
query = query.join(BasicSubmission).join(SubmissionType).filter(SubmissionType.name == submission_type)
|
||||
case SubmissionType():
|
||||
from backend import BasicSubmission
|
||||
# logger.debug(f"Lookup controls by SubmissionType: {submission_type}")
|
||||
query = query.join(BasicSubmission).filter(BasicSubmission.submission_type_name == submission_type.name)
|
||||
case _:
|
||||
pass
|
||||
@@ -203,31 +201,23 @@ class Control(BaseClass):
|
||||
if start_date is not None:
|
||||
match start_date:
|
||||
case date():
|
||||
# logger.debug(f"Lookup control by start date({start_date})")
|
||||
start_date = start_date.strftime("%Y-%m-%d")
|
||||
case int():
|
||||
# logger.debug(f"Lookup control by ordinal start date {start_date}")
|
||||
start_date = datetime.fromordinal(
|
||||
datetime(1900, 1, 1).toordinal() + start_date - 2).date().strftime("%Y-%m-%d")
|
||||
case _:
|
||||
# logger.debug(f"Lookup control with parsed start date {start_date}")
|
||||
start_date = parse(start_date).strftime("%Y-%m-%d")
|
||||
match end_date:
|
||||
case date():
|
||||
# logger.debug(f"Lookup control by end date({end_date})")
|
||||
end_date = end_date.strftime("%Y-%m-%d")
|
||||
case int():
|
||||
# logger.debug(f"Lookup control by ordinal end date {end_date}")
|
||||
end_date = datetime.fromordinal(datetime(1900, 1, 1).toordinal() + end_date - 2).date().strftime(
|
||||
"%Y-%m-%d")
|
||||
case _:
|
||||
# logger.debug(f"Lookup control with parsed end date {end_date}")
|
||||
end_date = parse(end_date).strftime("%Y-%m-%d")
|
||||
# logger.debug(f"Looking up BasicSubmissions from start date: {start_date} and end date: {end_date}")
|
||||
query = query.filter(cls.submitted_date.between(start_date, end_date))
|
||||
match name:
|
||||
case str():
|
||||
# logger.debug(f"Lookup control by name {control_name}")
|
||||
query = query.filter(cls.name.startswith(name))
|
||||
limit = 1
|
||||
case _:
|
||||
@@ -273,7 +263,6 @@ class Control(BaseClass):
|
||||
except StopIteration as e:
|
||||
raise AttributeError(
|
||||
f"Couldn't find existing class/subclass of {cls} with all attributes:\n{pformat(attrs.keys())}")
|
||||
# logger.info(f"Recruiting model: {model}")
|
||||
return model
|
||||
|
||||
@classmethod
|
||||
@@ -343,7 +332,6 @@ class PCRControl(Control):
|
||||
parent.mode_typer.clear()
|
||||
parent.mode_typer.setEnabled(False)
|
||||
report = Report()
|
||||
# logger.debug(f"Chart settings: {pformat(chart_settings)}")
|
||||
controls = cls.query(submission_type=chart_settings['sub_type'], start_date=chart_settings['start_date'],
|
||||
end_date=chart_settings['end_date'])
|
||||
data = [control.to_sub_dict() for control in controls]
|
||||
@@ -411,21 +399,16 @@ class IridaControl(Control):
|
||||
kraken = self.kraken
|
||||
except TypeError:
|
||||
kraken = {}
|
||||
# logger.debug("calculating kraken count total to use in percentage")
|
||||
kraken_cnt_total = sum([kraken[item]['kraken_count'] for item in kraken])
|
||||
# logger.debug("Creating new kraken.")
|
||||
new_kraken = [dict(name=item, kraken_count=kraken[item]['kraken_count'],
|
||||
kraken_percent="{0:.0%}".format(kraken[item]['kraken_count'] / kraken_cnt_total),
|
||||
target=item in self.controltype.targets)
|
||||
for item in kraken]
|
||||
# logger.debug(f"New kraken before sort: {new_kraken}")
|
||||
new_kraken = sorted(new_kraken, key=itemgetter('kraken_count'), reverse=True)
|
||||
# logger.debug("setting targets")
|
||||
if self.controltype.targets:
|
||||
targets = self.controltype.targets
|
||||
else:
|
||||
targets = ["None"]
|
||||
# logger.debug("constructing output dictionary")
|
||||
output = dict(
|
||||
name=self.name,
|
||||
type=self.controltype.name,
|
||||
@@ -447,7 +430,6 @@ class IridaControl(Control):
|
||||
Returns:
|
||||
List[dict]: list of records
|
||||
"""
|
||||
# logger.debug("load json string for mode (i.e. contains, matches, kraken2)")
|
||||
try:
|
||||
data = self.__getattribute__(mode)
|
||||
except TypeError:
|
||||
@@ -460,12 +442,10 @@ class IridaControl(Control):
|
||||
else:
|
||||
if consolidate:
|
||||
on_tar = {k: v for k, v in data.items() if k.strip("*") in self.controltype.targets[control_sub_type]}
|
||||
# logger.debug(f"Consolidating off-targets to: {self.controltype.targets[control_sub_type]}")
|
||||
off_tar = sum(v[f'{mode}_ratio'] for k, v in data.items() if
|
||||
k.strip("*") not in self.controltype.targets[control_sub_type])
|
||||
on_tar['Off-target'] = {f"{mode}_ratio": off_tar}
|
||||
data = on_tar
|
||||
# logger.debug("dict keys are genera of bacteria, e.g. 'Streptococcus'")
|
||||
for genus in data:
|
||||
_dict = dict(
|
||||
name=self.name,
|
||||
@@ -473,7 +453,6 @@ class IridaControl(Control):
|
||||
genus=genus,
|
||||
target='Target' if genus.strip("*") in self.controltype.targets[control_sub_type] else "Off-target"
|
||||
)
|
||||
# logger.debug("get Target or Off-target of genus")
|
||||
for key in data[genus]:
|
||||
_dict[key] = data[genus][key]
|
||||
yield _dict
|
||||
@@ -487,7 +466,6 @@ class IridaControl(Control):
|
||||
List[str]: List of control mode names.
|
||||
"""
|
||||
try:
|
||||
# logger.debug("Creating a list of JSON columns in _controls table")
|
||||
cols = [item.name for item in list(cls.__table__.columns) if isinstance(item.type, JSON)]
|
||||
except AttributeError as e:
|
||||
logger.error(f"Failed to get available modes from db: {e}")
|
||||
@@ -504,7 +482,6 @@ class IridaControl(Control):
|
||||
"""
|
||||
super().make_parent_buttons(parent=parent)
|
||||
rows = parent.layout.rowCount() - 2
|
||||
# logger.debug(f"Parent rows: {rows}")
|
||||
checker = QCheckBox(parent)
|
||||
checker.setChecked(True)
|
||||
checker.setObjectName("irida_check")
|
||||
@@ -539,10 +516,8 @@ class IridaControl(Control):
|
||||
except AttributeError:
|
||||
consolidate = False
|
||||
report = Report()
|
||||
# logger.debug(f"settings: {pformat(chart_settings)}")
|
||||
controls = cls.query(subtype=chart_settings['sub_type'], start_date=chart_settings['start_date'],
|
||||
end_date=chart_settings['end_date'])
|
||||
# logger.debug(f"Controls found: {controls}")
|
||||
if not controls:
|
||||
report.add_result(Result(status="Critical", msg="No controls found in given date range."))
|
||||
return report, None
|
||||
@@ -552,19 +527,16 @@ class IridaControl(Control):
|
||||
control in controls]
|
||||
# NOTE: flatten data to one dimensional list
|
||||
data = [item for sublist in data for item in sublist]
|
||||
# logger.debug(f"Control objects going into df conversion: {pformat(data)}")
|
||||
if not data:
|
||||
report.add_result(Result(status="Critical", msg="No data found for controls in given date range."))
|
||||
return report, None
|
||||
df = cls.convert_data_list_to_df(input_df=data, sub_mode=chart_settings['sub_mode'])
|
||||
# logger.debug(f"Chart df: \n {df}")
|
||||
if chart_settings['sub_mode'] is None:
|
||||
title = chart_settings['sub_mode']
|
||||
else:
|
||||
title = f"{chart_settings['mode']} - {chart_settings['sub_mode']}"
|
||||
# NOTE: send dataframe to chart maker
|
||||
df, modes = cls.prep_df(ctx=ctx, df=df)
|
||||
# logger.debug(f"prepped df: \n {df}")
|
||||
fig = IridaFigure(df=df, ytitle=title, modes=modes, parent=parent,
|
||||
settings=chart_settings)
|
||||
return report, fig
|
||||
@@ -581,9 +553,7 @@ class IridaControl(Control):
|
||||
Returns:
|
||||
DataFrame: dataframe of controls
|
||||
"""
|
||||
# logger.debug(f"Subtype: {sub_mode}")
|
||||
df = DataFrame.from_records(input_df)
|
||||
# logger.debug(f"DF from records: {df}")
|
||||
safe = ['name', 'submitted_date', 'genus', 'target']
|
||||
for column in df.columns:
|
||||
if column not in safe:
|
||||
@@ -636,7 +606,6 @@ class IridaControl(Control):
|
||||
Returns:
|
||||
DataFrame: output dataframe with dates incremented.
|
||||
"""
|
||||
# logger.debug(f"Unique items: {df['name'].unique()}")
|
||||
# NOTE: get submitted dates for each control
|
||||
dict_list = [dict(name=item, date=df[df.name == item].iloc[0]['submitted_date']) for item in
|
||||
sorted(df['name'].unique())]
|
||||
@@ -664,7 +633,6 @@ class IridaControl(Control):
|
||||
check = False
|
||||
previous_dates.add(item['date'])
|
||||
if check:
|
||||
# logger.debug(f"We found one! Increment date!\n\t{item['date']} to {item['date'] + timedelta(days=1)}")
|
||||
# NOTE: get df locations where name == item name
|
||||
mask = df['name'] == item['name']
|
||||
# NOTE: increment date in dataframe
|
||||
@@ -673,15 +641,12 @@ class IridaControl(Control):
|
||||
passed = False
|
||||
else:
|
||||
passed = True
|
||||
# logger.debug(f"\n\tCurrent date: {item['date']}\n\tPrevious dates:{previous_dates}")
|
||||
# logger.debug(f"DF: {type(df)}, previous_dates: {type(previous_dates)}")
|
||||
# NOTE: if run didn't lead to changed date, return values
|
||||
if passed:
|
||||
# logger.debug(f"Date check passed, returning.")
|
||||
return df, previous_dates
|
||||
# NOTE: if date was changed, rerun with new date
|
||||
else:
|
||||
# logger.warning(f"Date check failed, running recursion")
|
||||
logger.warning(f"Date check failed, running recursion")
|
||||
df, previous_dates = cls.check_date(df, item, previous_dates)
|
||||
return df, previous_dates
|
||||
|
||||
@@ -708,13 +673,10 @@ class IridaControl(Control):
|
||||
# NOTE: sort by and exclude from
|
||||
sorts = ['submitted_date', "target", "genus"]
|
||||
exclude = ['name', 'genera']
|
||||
# logger.debug(df.columns)
|
||||
modes = [item for item in df.columns if item not in sorts and item not in exclude]
|
||||
# logger.debug(f"Modes coming out: {modes}")
|
||||
# NOTE: Set descending for any columns that have "{mode}" in the header.
|
||||
ascending = [False if item == "target" else True for item in sorts]
|
||||
df = df.sort_values(by=sorts, ascending=ascending)
|
||||
# logger.debug(df[df.isna().any(axis=1)])
|
||||
# NOTE: actual chart construction is done by
|
||||
return df, modes
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ from io import BytesIO
|
||||
|
||||
logger = logging.getLogger(f'submissions.{__name__}')
|
||||
|
||||
# logger.debug("Table for ReagentType/Reagent relations")
|
||||
reagentroles_reagents = Table(
|
||||
"_reagentroles_reagents",
|
||||
Base.metadata,
|
||||
@@ -26,7 +25,6 @@ reagentroles_reagents = Table(
|
||||
extend_existing=True
|
||||
)
|
||||
|
||||
# logger.debug("Table for EquipmentRole/Equipment relations")
|
||||
equipmentroles_equipment = Table(
|
||||
"_equipmentroles_equipment",
|
||||
Base.metadata,
|
||||
@@ -35,7 +33,6 @@ equipmentroles_equipment = Table(
|
||||
extend_existing=True
|
||||
)
|
||||
|
||||
# logger.debug("Table for Equipment/Process relations")
|
||||
equipment_processes = Table(
|
||||
"_equipment_processes",
|
||||
Base.metadata,
|
||||
@@ -44,7 +41,6 @@ equipment_processes = Table(
|
||||
extend_existing=True
|
||||
)
|
||||
|
||||
# logger.debug("Table for EquipmentRole/Process relations")
|
||||
equipmentroles_processes = Table(
|
||||
"_equipmentroles_processes",
|
||||
Base.metadata,
|
||||
@@ -53,7 +49,6 @@ equipmentroles_processes = Table(
|
||||
extend_existing=True
|
||||
)
|
||||
|
||||
# logger.debug("Table for SubmissionType/Process relations")
|
||||
submissiontypes_processes = Table(
|
||||
"_submissiontypes_processes",
|
||||
Base.metadata,
|
||||
@@ -62,7 +57,6 @@ submissiontypes_processes = Table(
|
||||
extend_existing=True
|
||||
)
|
||||
|
||||
# logger.debug("Table for KitType/Process relations")
|
||||
kittypes_processes = Table(
|
||||
"_kittypes_processes",
|
||||
Base.metadata,
|
||||
@@ -71,7 +65,6 @@ kittypes_processes = Table(
|
||||
extend_existing=True
|
||||
)
|
||||
|
||||
# logger.debug("Table for TipRole/Tips relations")
|
||||
tiproles_tips = Table(
|
||||
"_tiproles_tips",
|
||||
Base.metadata,
|
||||
@@ -80,7 +73,6 @@ tiproles_tips = Table(
|
||||
extend_existing=True
|
||||
)
|
||||
|
||||
# logger.debug("Table for Process/TipRole relations")
|
||||
process_tiprole = Table(
|
||||
"_process_tiprole",
|
||||
Base.metadata,
|
||||
@@ -89,7 +81,6 @@ process_tiprole = Table(
|
||||
extend_existing=True
|
||||
)
|
||||
|
||||
# logger.debug("Table for Equipment/Tips relations")
|
||||
equipment_tips = Table(
|
||||
"_equipment_tips",
|
||||
Base.metadata,
|
||||
@@ -116,7 +107,7 @@ class KitType(BaseClass):
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
|
||||
# creator function: https://stackoverflow.com/questions/11091491/keyerror-when-adding-objects-to-sqlalchemy-association-object/11116291#11116291
|
||||
# NOTE: creator function: https://stackoverflow.com/questions/11091491/keyerror-when-adding-objects-to-sqlalchemy-association-object/11116291#11116291
|
||||
reagent_roles = association_proxy("kit_reagentrole_associations", "reagent_role",
|
||||
creator=lambda RT: KitTypeReagentRoleAssociation(
|
||||
reagent_role=RT)) #: Association proxy to KitTypeReagentRoleAssociation
|
||||
@@ -152,18 +143,14 @@ class KitType(BaseClass):
|
||||
"""
|
||||
match submission_type:
|
||||
case SubmissionType():
|
||||
# logger.debug(f"Getting reagents by SubmissionType {submission_type}")
|
||||
relevant_associations = [item for item in self.kit_reagentrole_associations if
|
||||
item.submission_type == submission_type]
|
||||
case str():
|
||||
# logger.debug(f"Getting reagents by str {submission_type}")
|
||||
relevant_associations = [item for item in self.kit_reagentrole_associations if
|
||||
item.submission_type.name == submission_type]
|
||||
case _:
|
||||
# logger.debug(f"Getting reagents")
|
||||
relevant_associations = [item for item in self.kit_reagentrole_associations]
|
||||
if required:
|
||||
# logger.debug(f"Filtering by required.")
|
||||
return (item.reagent_role for item in relevant_associations if item.required == 1)
|
||||
else:
|
||||
return (item.reagent_role for item in relevant_associations)
|
||||
@@ -181,18 +168,14 @@ class KitType(BaseClass):
|
||||
# NOTE: Account for submission_type variable type.
|
||||
match submission_type:
|
||||
case str():
|
||||
# logger.debug(f"Constructing xl map with str {submission_type}")
|
||||
assocs = [item for item in self.kit_reagentrole_associations if
|
||||
item.submission_type.name == submission_type]
|
||||
case SubmissionType():
|
||||
# logger.debug(f"Constructing xl map with SubmissionType {submission_type}")
|
||||
assocs = [item for item in self.kit_reagentrole_associations if item.submission_type == submission_type]
|
||||
case _:
|
||||
raise ValueError(f"Wrong variable type: {type(submission_type)} used!")
|
||||
# logger.debug("Get all KitTypeReagentTypeAssociation for SubmissionType")
|
||||
for assoc in assocs:
|
||||
try:
|
||||
# logger.debug(f"Yielding: {assoc.reagent_role.name}, {assoc.uses}")
|
||||
yield assoc.reagent_role.name, assoc.uses
|
||||
except TypeError:
|
||||
continue
|
||||
@@ -220,27 +203,22 @@ class KitType(BaseClass):
|
||||
query: Query = cls.__database_session__.query(cls)
|
||||
match used_for:
|
||||
case str():
|
||||
# logger.debug(f"Looking up kit type by used_for str: {used_for}")
|
||||
query = query.filter(cls.used_for.any(name=used_for))
|
||||
case SubmissionType():
|
||||
# logger.debug(f"Looking up kit type by used_for SubmissionType: {used_for}")
|
||||
query = query.filter(cls.used_for.contains(used_for))
|
||||
case _:
|
||||
pass
|
||||
match name:
|
||||
case str():
|
||||
# logger.debug(f"Looking up kit type by name str: {name}")
|
||||
query = query.filter(cls.name == name)
|
||||
limit = 1
|
||||
case _:
|
||||
pass
|
||||
match id:
|
||||
case int():
|
||||
# logger.debug(f"Looking up kit type by id int: {id}")
|
||||
query = query.filter(cls.id == id)
|
||||
limit = 1
|
||||
case str():
|
||||
# logger.debug(f"Looking up kit type by id str: {id}")
|
||||
query = query.filter(cls.id == int(id))
|
||||
limit = 1
|
||||
case _:
|
||||
@@ -262,10 +240,7 @@ class KitType(BaseClass):
|
||||
dict: Dictionary containing relevant info for SubmissionType construction
|
||||
"""
|
||||
base_dict = dict(name=self.name, reagent_roles=[], equipment_roles=[])
|
||||
# base_dict['reagent roles'] = []
|
||||
# base_dict['equipment roles'] = []
|
||||
for k, v in self.construct_xl_map_for_use(submission_type=submission_type):
|
||||
# logger.debug(f"Value: {v}")
|
||||
try:
|
||||
assoc = next(item for item in self.kit_reagentrole_associations if item.reagent_role.name == k)
|
||||
except StopIteration as e:
|
||||
@@ -280,10 +255,8 @@ class KitType(BaseClass):
|
||||
except StopIteration:
|
||||
continue
|
||||
for kk, vv in assoc.to_export_dict(extraction_kit=self).items():
|
||||
# logger.debug(f"{kk}:{vv}")
|
||||
v[kk] = vv
|
||||
base_dict['equipment_roles'].append(v)
|
||||
# logger.debug(f"KT returning {base_dict}")
|
||||
return base_dict
|
||||
|
||||
|
||||
@@ -347,28 +320,19 @@ class ReagentRole(BaseClass):
|
||||
else:
|
||||
match kit_type:
|
||||
case str():
|
||||
# logger.debug(f"Lookup ReagentType by kittype str {kit_type}")
|
||||
kit_type = KitType.query(name=kit_type)
|
||||
case _:
|
||||
pass
|
||||
match reagent:
|
||||
case str():
|
||||
# logger.debug(f"Lookup ReagentType by reagent str {reagent}")
|
||||
reagent = Reagent.query(lot=reagent)
|
||||
case _:
|
||||
pass
|
||||
assert reagent.role
|
||||
# logger.debug(f"Looking up reagent type for {type(kit_type)} {kit_type} and {type(reagent)} {reagent}")
|
||||
# logger.debug(f"Kit reagent types: {kit_type.reagent_types}")
|
||||
result = set(kit_type.reagent_roles).intersection(reagent.role)
|
||||
# logger.debug(f"Result: {result}")
|
||||
# try:
|
||||
return next((item for item in result), None)
|
||||
# except IndexError:
|
||||
# return None
|
||||
match name:
|
||||
case str():
|
||||
# logger.debug(f"Looking up reagent type by name str: {name}")
|
||||
query = query.filter(cls.name == name)
|
||||
limit = 1
|
||||
case _:
|
||||
@@ -457,7 +421,6 @@ class Reagent(BaseClass, LogMixin):
|
||||
rtype = reagent_role.name.replace("_", " ")
|
||||
except AttributeError:
|
||||
rtype = "Unknown"
|
||||
# logger.debug(f"Role for {self.name}: {rtype}")
|
||||
# NOTE: Calculate expiry with EOL from ReagentType
|
||||
try:
|
||||
place_holder = self.expiry + reagent_role.eol_ext
|
||||
@@ -493,14 +456,11 @@ class Reagent(BaseClass, LogMixin):
|
||||
Report: Result of operation
|
||||
"""
|
||||
report = Report()
|
||||
# logger.debug(f"Attempting update of last used reagent type at intersection of ({self}), ({kit})")
|
||||
rt = ReagentRole.query(kit_type=kit, reagent=self, limit=1)
|
||||
if rt is not None:
|
||||
# logger.debug(f"got reagenttype {rt}")
|
||||
assoc = KitTypeReagentRoleAssociation.query(kit_type=kit, reagent_role=rt)
|
||||
if assoc is not None:
|
||||
if assoc.last_used != self.lot:
|
||||
# logger.debug(f"Updating {assoc} last used to {self.lot}")
|
||||
assoc.last_used = self.lot
|
||||
result = assoc.save()
|
||||
report.add_result(result)
|
||||
@@ -539,23 +499,19 @@ class Reagent(BaseClass, LogMixin):
|
||||
pass
|
||||
match role:
|
||||
case str():
|
||||
# logger.debug(f"Looking up reagents by reagent type str: {reagent_type}")
|
||||
query = query.join(cls.role).filter(ReagentRole.name == role)
|
||||
case ReagentRole():
|
||||
# logger.debug(f"Looking up reagents by reagent type ReagentType: {reagent_type}")
|
||||
query = query.filter(cls.role.contains(role))
|
||||
case _:
|
||||
pass
|
||||
match name:
|
||||
case str():
|
||||
# logger.debug(f"Looking up reagent by name str: {name}")
|
||||
# NOTE: Not limited due to multiple reagents having same name.
|
||||
query = query.filter(cls.name == name)
|
||||
case _:
|
||||
pass
|
||||
match lot:
|
||||
case str():
|
||||
# logger.debug(f"Looking up reagent by lot number str: {lot}")
|
||||
query = query.filter(cls.lot == lot)
|
||||
# NOTE: In this case limit number returned.
|
||||
limit = 1
|
||||
@@ -579,7 +535,6 @@ class Reagent(BaseClass, LogMixin):
|
||||
case "expiry":
|
||||
if isinstance(value, str):
|
||||
field_value = datetime.strptime(value, "%Y-%m-%d")
|
||||
# field_value.replace(tzinfo=timezone)
|
||||
elif isinstance(value, date):
|
||||
field_value = datetime.combine(value, datetime.min.time())
|
||||
else:
|
||||
@@ -589,7 +544,6 @@ class Reagent(BaseClass, LogMixin):
|
||||
continue
|
||||
case _:
|
||||
field_value = value
|
||||
# logger.debug(f"Setting reagent {key} to {field_value}")
|
||||
self.__setattr__(key, field_value)
|
||||
self.save()
|
||||
|
||||
@@ -634,25 +588,19 @@ class Discount(BaseClass):
|
||||
query: Query = cls.__database_session__.query(cls)
|
||||
match organization:
|
||||
case Organization():
|
||||
# logger.debug(f"Looking up discount with organization Organization: {organization}")
|
||||
query = query.filter(cls.client == Organization)
|
||||
case str():
|
||||
# logger.debug(f"Looking up discount with organization str: {organization}")
|
||||
query = query.join(Organization).filter(Organization.name == organization)
|
||||
case int():
|
||||
# logger.debug(f"Looking up discount with organization id: {organization}")
|
||||
query = query.join(Organization).filter(Organization.id == organization)
|
||||
case _:
|
||||
pass
|
||||
match kit_type:
|
||||
case KitType():
|
||||
# logger.debug(f"Looking up discount with kit type KitType: {kit_type}")
|
||||
query = query.filter(cls.kit == kit_type)
|
||||
case str():
|
||||
# logger.debug(f"Looking up discount with kit type str: {kit_type}")
|
||||
query = query.join(KitType).filter(KitType.name == kit_type)
|
||||
case int():
|
||||
# logger.debug(f"Looking up discount with kit type id: {kit_type}")
|
||||
query = query.join(KitType).filter(KitType.id == kit_type)
|
||||
case _:
|
||||
pass
|
||||
@@ -723,7 +671,6 @@ class SubmissionType(BaseClass):
|
||||
return submission_type.template_file
|
||||
|
||||
def get_template_file_sheets(self) -> List[str]:
|
||||
logger.debug(f"Submission type to get sheets for: {self.name}")
|
||||
"""
|
||||
Gets names of sheet in the stored blank form.
|
||||
|
||||
@@ -768,7 +715,6 @@ class SubmissionType(BaseClass):
|
||||
dict: Map of locations
|
||||
"""
|
||||
info = {k: v for k, v in self.info_map.items() if k != "custom"}
|
||||
logger.debug(f"Info map: {info}")
|
||||
match mode:
|
||||
case "read":
|
||||
output = {k: v[mode] for k, v in info.items() if v[mode]}
|
||||
@@ -844,11 +790,9 @@ class SubmissionType(BaseClass):
|
||||
"""
|
||||
match equipment_role:
|
||||
case str():
|
||||
# logger.debug(f"Getting processes for equipmentrole str {equipment_role}")
|
||||
relevant = [item.get_all_processes(kit) for item in self.submissiontype_equipmentrole_associations if
|
||||
item.equipment_role.name == equipment_role]
|
||||
case EquipmentRole():
|
||||
# logger.debug(f"Getting processes for equipmentrole EquipmentRole {equipment_role}")
|
||||
relevant = [item.get_all_processes(kit) for item in self.submissiontype_equipmentrole_associations if
|
||||
item.equipment_role == equipment_role]
|
||||
case _:
|
||||
@@ -886,14 +830,12 @@ class SubmissionType(BaseClass):
|
||||
query: Query = cls.__database_session__.query(cls)
|
||||
match name:
|
||||
case str():
|
||||
# logger.debug(f"Looking up submission type by name str: {name}")
|
||||
query = query.filter(cls.name == name)
|
||||
limit = 1
|
||||
case _:
|
||||
pass
|
||||
match key:
|
||||
case str():
|
||||
# logger.debug(f"Looking up submission type by info-map key str: {key}")
|
||||
query = query.filter(cls.info_map.op('->')(key) is not None)
|
||||
case _:
|
||||
pass
|
||||
@@ -946,7 +888,6 @@ class SubmissionType(BaseClass):
|
||||
import_dict = yaml.load(stream=f, Loader=yaml.Loader)
|
||||
else:
|
||||
raise Exception(f"Filetype {filepath.suffix} not supported.")
|
||||
# logger.debug(pformat(import_dict))
|
||||
try:
|
||||
submission_type = cls.query(name=import_dict['name'])
|
||||
except KeyError:
|
||||
@@ -1076,23 +1017,17 @@ class SubmissionTypeKitTypeAssociation(BaseClass):
|
||||
query: Query = cls.__database_session__.query(cls)
|
||||
match submission_type:
|
||||
case SubmissionType():
|
||||
# logger.debug(f"Looking up {cls.__name__} by SubmissionType {submission_type}")
|
||||
query = query.filter(cls.submission_type == submission_type)
|
||||
case str():
|
||||
# logger.debug(f"Looking up {cls.__name__} by name {submission_type}")
|
||||
query = query.join(SubmissionType).filter(SubmissionType.name == submission_type)
|
||||
case int():
|
||||
# logger.debug(f"Looking up {cls.__name__} by id {submission_type}")
|
||||
query = query.join(SubmissionType).filter(SubmissionType.id == submission_type)
|
||||
match kit_type:
|
||||
case KitType():
|
||||
# logger.debug(f"Looking up {cls.__name__} by KitType {kit_type}")
|
||||
query = query.filter(cls.kit_type == kit_type)
|
||||
case str():
|
||||
# logger.debug(f"Looking up {cls.__name__} by name {kit_type}")
|
||||
query = query.join(KitType).filter(KitType.name == kit_type)
|
||||
case int():
|
||||
# logger.debug(f"Looking up {cls.__name__} by id {kit_type}")
|
||||
query = query.join(KitType).filter(KitType.id == kit_type)
|
||||
limit = query.count()
|
||||
return cls.execute_query(query=query, limit=limit)
|
||||
@@ -1107,7 +1042,6 @@ class SubmissionTypeKitTypeAssociation(BaseClass):
|
||||
exclude = ['_sa_instance_state', 'submission_types_id', 'kits_id', 'submission_type', 'kit_type']
|
||||
base_dict = {k: v for k, v in self.__dict__.items() if k not in exclude}
|
||||
base_dict['kit_type'] = self.kit_type.to_export_dict(submission_type=self.submission_type)
|
||||
# logger.debug(f"STKTA returning: {base_dict}")
|
||||
return base_dict
|
||||
|
||||
|
||||
@@ -1128,10 +1062,11 @@ class KitTypeReagentRoleAssociation(BaseClass):
|
||||
kit_type = relationship(KitType,
|
||||
back_populates="kit_reagentrole_associations") #: relationship to associated KitType
|
||||
|
||||
# reference to the "ReagentType" object
|
||||
# NOTE: reference to the "ReagentType" object
|
||||
reagent_role = relationship(ReagentRole,
|
||||
back_populates="reagentrole_kit_associations") #: relationship to associated ReagentType
|
||||
|
||||
# NOTE: reference to the "SubmissionType" object
|
||||
submission_type = relationship(SubmissionType,
|
||||
back_populates="submissiontype_kit_rt_associations") #: relationship to associated SubmissionType
|
||||
|
||||
@@ -1203,19 +1138,15 @@ class KitTypeReagentRoleAssociation(BaseClass):
|
||||
query: Query = cls.__database_session__.query(cls)
|
||||
match kit_type:
|
||||
case KitType():
|
||||
# logger.debug(f"Lookup KitTypeReagentTypeAssociation by kit_type KitType {kit_type}")
|
||||
query = query.filter(cls.kit_type == kit_type)
|
||||
case str():
|
||||
# logger.debug(f"Lookup KitTypeReagentTypeAssociation by kit_type str {kit_type}")
|
||||
query = query.join(KitType).filter(KitType.name == kit_type)
|
||||
case _:
|
||||
pass
|
||||
match reagent_role:
|
||||
case ReagentRole():
|
||||
# logger.debug(f"Lookup KitTypeReagentTypeAssociation by reagent_type ReagentType {reagent_type}")
|
||||
query = query.filter(cls.reagent_role == reagent_role)
|
||||
case str():
|
||||
# logger.debug(f"Lookup KitTypeReagentTypeAssociation by reagent_type ReagentType {reagent_type}")
|
||||
query = query.join(ReagentRole).filter(ReagentRole.name == reagent_role)
|
||||
case _:
|
||||
pass
|
||||
@@ -1242,7 +1173,6 @@ class KitTypeReagentRoleAssociation(BaseClass):
|
||||
Returns:
|
||||
Generator: Generates of reagents.
|
||||
"""
|
||||
# logger.debug(f"Attempting lookup of reagents by type: {reagent.type}")
|
||||
reagents = self.reagent_role.instances
|
||||
try:
|
||||
regex = self.uses['exclude_regex']
|
||||
@@ -1309,7 +1239,6 @@ class SubmissionReagentAssociation(BaseClass):
|
||||
query: Query = cls.__database_session__.query(cls)
|
||||
match reagent:
|
||||
case Reagent() | str():
|
||||
# logger.debug(f"Lookup SubmissionReagentAssociation by reagent Reagent {reagent}")
|
||||
if isinstance(reagent, str):
|
||||
reagent = Reagent.query(lot=reagent)
|
||||
query = query.filter(cls.reagent == reagent)
|
||||
@@ -1319,10 +1248,8 @@ class SubmissionReagentAssociation(BaseClass):
|
||||
case BasicSubmission() | str():
|
||||
if isinstance(submission, str):
|
||||
submission = BasicSubmission.query(rsl_plate_num=submission)
|
||||
# logger.debug(f"Lookup SubmissionReagentAssociation by submission BasicSubmission {submission}")
|
||||
query = query.filter(cls.submission == submission)
|
||||
case int():
|
||||
# logger.debug(f"Lookup SubmissionReagentAssociation by submission id {submission}")
|
||||
submission = BasicSubmission.query(id=submission)
|
||||
query = query.join(BasicSubmission).filter(BasicSubmission.id == submission)
|
||||
case _:
|
||||
@@ -1439,21 +1366,18 @@ class Equipment(BaseClass, LogMixin):
|
||||
query = cls.__database_session__.query(cls)
|
||||
match name:
|
||||
case str():
|
||||
# logger.debug(f"Lookup Equipment by name str {name}")
|
||||
query = query.filter(cls.name == name)
|
||||
limit = 1
|
||||
case _:
|
||||
pass
|
||||
match nickname:
|
||||
case str():
|
||||
# logger.debug(f"Lookup Equipment by nickname str {nickname}")
|
||||
query = query.filter(cls.nickname == nickname)
|
||||
limit = 1
|
||||
case _:
|
||||
pass
|
||||
match asset_number:
|
||||
case str():
|
||||
# logger.debug(f"Lookup Equipment by asset_number str {asset_number}")
|
||||
query = query.filter(cls.asset_number == asset_number)
|
||||
limit = 1
|
||||
case _:
|
||||
@@ -1569,11 +1493,9 @@ class EquipmentRole(BaseClass):
|
||||
PydEquipmentRole: This EquipmentRole as PydEquipmentRole
|
||||
"""
|
||||
from backend.validators.pydant import PydEquipmentRole
|
||||
# logger.debug("Creating list of PydEquipment in this role")
|
||||
equipment = [item.to_pydantic(submission_type=submission_type, extraction_kit=extraction_kit) for item in
|
||||
self.instances]
|
||||
pyd_dict = self.to_dict()
|
||||
# logger.debug("Creating list of Processes in this role")
|
||||
pyd_dict['processes'] = self.get_processes(submission_type=submission_type, extraction_kit=extraction_kit)
|
||||
return PydEquipmentRole(equipment=equipment, **pyd_dict)
|
||||
|
||||
@@ -1595,14 +1517,12 @@ class EquipmentRole(BaseClass):
|
||||
query = cls.__database_session__.query(cls)
|
||||
match id:
|
||||
case int():
|
||||
# logger.debug(f"Lookup EquipmentRole by id {id}")
|
||||
query = query.filter(cls.id == id)
|
||||
limit = 1
|
||||
case _:
|
||||
pass
|
||||
match name:
|
||||
case str():
|
||||
# logger.debug(f"Lookup EquipmentRole by name str {name}")
|
||||
query = query.filter(cls.name == name)
|
||||
limit = 1
|
||||
case _:
|
||||
@@ -1622,7 +1542,6 @@ class EquipmentRole(BaseClass):
|
||||
List[Process]: List of processes
|
||||
"""
|
||||
if isinstance(submission_type, str):
|
||||
# logger.debug(f"Checking if str {submission_type} exists")
|
||||
submission_type = SubmissionType.query(name=submission_type)
|
||||
if isinstance(extraction_kit, str):
|
||||
extraction_kit = KitType.query(name=extraction_kit)
|
||||
@@ -1808,7 +1727,6 @@ class Process(BaseClass):
|
||||
query = cls.__database_session__.query(cls)
|
||||
match name:
|
||||
case str():
|
||||
# logger.debug(f"Lookup Process with name str {name}")
|
||||
query = query.filter(cls.name == name)
|
||||
limit = 1
|
||||
case _:
|
||||
@@ -1892,13 +1810,11 @@ class Tips(BaseClass, LogMixin):
|
||||
query = cls.__database_session__.query(cls)
|
||||
match name:
|
||||
case str():
|
||||
# logger.debug(f"Lookup Equipment by name str {name}")
|
||||
query = query.filter(cls.name == name)
|
||||
case _:
|
||||
pass
|
||||
match lot:
|
||||
case str():
|
||||
# logger.debug(f"Lookup Equipment by nickname str {nickname}")
|
||||
query = query.filter(cls.lot == lot)
|
||||
limit = 1
|
||||
case _:
|
||||
|
||||
@@ -65,7 +65,6 @@ class Organization(BaseClass):
|
||||
pass
|
||||
match name:
|
||||
case str():
|
||||
# logger.debug(f"Looking up organization with name starting with: {name}")
|
||||
query = query.filter(cls.name.startswith(name))
|
||||
limit = 1
|
||||
case _:
|
||||
@@ -159,21 +158,18 @@ class Contact(BaseClass):
|
||||
query: Query = cls.__database_session__.query(cls)
|
||||
match name:
|
||||
case str():
|
||||
# logger.debug(f"Looking up contact with name: {name}")
|
||||
query = query.filter(cls.name == name.title())
|
||||
limit = 1
|
||||
case _:
|
||||
pass
|
||||
match email:
|
||||
case str():
|
||||
# logger.debug(f"Looking up contact with email: {name}")
|
||||
query = query.filter(cls.email == email)
|
||||
limit = 1
|
||||
case _:
|
||||
pass
|
||||
match phone:
|
||||
case str():
|
||||
# logger.debug(f"Looking up contact with phone: {name}")
|
||||
query = query.filter(cls.phone == phone)
|
||||
limit = 1
|
||||
case _:
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user