Second round of code cleanup.
This commit is contained in:
@@ -28,6 +28,8 @@ class BaseClass(Base):
|
||||
|
||||
__table_args__ = {'extend_existing': True} #: Will only add new columns
|
||||
|
||||
singles = ['id']
|
||||
|
||||
@classmethod
|
||||
@declared_attr
|
||||
def __tablename__(cls) -> str:
|
||||
@@ -92,17 +94,21 @@ class BaseClass(Base):
|
||||
Returns:
|
||||
dict | list | str: Output of key:value dict or single (list, str) desired variable
|
||||
"""
|
||||
dicto = dict(singles=['id'])
|
||||
output = {}
|
||||
for k, v in dicto.items():
|
||||
if len(args) > 0 and k not in args:
|
||||
# logger.debug(f"{k} not selected as being of interest.")
|
||||
continue
|
||||
else:
|
||||
output[k] = v
|
||||
if len(args) == 1:
|
||||
return output[args[0]]
|
||||
return output
|
||||
# if issubclass(cls, BaseClass) and cls.__name__ != "BaseClass":
|
||||
singles = list(set(cls.singles + BaseClass.singles))
|
||||
# else:
|
||||
# singles = cls.singles
|
||||
# output = dict(singles=singles)
|
||||
# output = {}
|
||||
# for k, v in dicto.items():
|
||||
# if len(args) > 0 and k not in args:
|
||||
# # logger.debug(f"{k} not selected as being of interest.")
|
||||
# continue
|
||||
# else:
|
||||
# output[k] = v
|
||||
# if len(args) == 1:
|
||||
# return output[args[0]]
|
||||
return dict(singles=singles)
|
||||
|
||||
@classmethod
|
||||
def query(cls, **kwargs) -> Any | List[Any]:
|
||||
@@ -190,10 +196,15 @@ class ConfigItem(BaseClass):
|
||||
Returns:
|
||||
ConfigItem|List[ConfigItem]: Config item(s)
|
||||
"""
|
||||
config_items = cls.__database_session__.query(cls).all()
|
||||
config_items = [item for item in config_items if item.key in args]
|
||||
if len(args) == 1:
|
||||
config_items = config_items[0]
|
||||
query = cls.__database_session__.query(cls)
|
||||
# config_items = [item for item in config_items if item.key in args]
|
||||
match len(args):
|
||||
case 0:
|
||||
config_items = query.all()
|
||||
case 1:
|
||||
config_items = query.filter(cls.key == args[0]).first()
|
||||
case _:
|
||||
config_items = query.filter(cls.key.in_(args)).all()
|
||||
return config_items
|
||||
|
||||
|
||||
|
||||
@@ -131,10 +131,8 @@ class Control(BaseClass):
|
||||
__mapper_args__ = {
|
||||
"polymorphic_identity": "Basic Control",
|
||||
"polymorphic_on": case(
|
||||
|
||||
(controltype_name == "PCR Control", "PCR Control"),
|
||||
(controltype_name == "Irida Control", "Irida Control"),
|
||||
|
||||
else_="Basic Control"
|
||||
),
|
||||
"with_polymorphic": "*",
|
||||
@@ -147,15 +145,15 @@ class Control(BaseClass):
|
||||
def find_polymorphic_subclass(cls, polymorphic_identity: str | ControlType | None = None,
|
||||
attrs: dict | None = None) -> Control:
|
||||
"""
|
||||
Find subclass based on polymorphic identity or relevant attributes.
|
||||
Find subclass based on polymorphic identity or relevant attributes.
|
||||
|
||||
Args:
|
||||
polymorphic_identity (str | None, optional): String representing polymorphic identity. Defaults to None.
|
||||
attrs (str | SubmissionType | None, optional): Attributes of the relevant class. Defaults to None.
|
||||
Args:
|
||||
polymorphic_identity (str | None, optional): String representing polymorphic identity. Defaults to None.
|
||||
attrs (str | SubmissionType | None, optional): Attributes of the relevant class. Defaults to None.
|
||||
|
||||
Returns:
|
||||
Control: Subclass of interest.
|
||||
"""
|
||||
Returns:
|
||||
Control: Subclass of interest.
|
||||
"""
|
||||
if isinstance(polymorphic_identity, dict):
|
||||
# logger.debug(f"Controlling for dict value")
|
||||
polymorphic_identity = polymorphic_identity['value']
|
||||
@@ -189,14 +187,11 @@ class Control(BaseClass):
|
||||
|
||||
Args:
|
||||
parent (QWidget): chart holding widget to add buttons to.
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
pass
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def make_chart(cls, parent, chart_settings: dict, ctx):
|
||||
def make_chart(cls, parent, chart_settings: dict, ctx) -> Tuple[Report, "CustomFigure" | None]:
|
||||
"""
|
||||
Dummy operation to be overridden by child classes.
|
||||
|
||||
@@ -307,6 +302,7 @@ class PCRControl(Control):
|
||||
return cls.execute_query(query=query, limit=limit)
|
||||
|
||||
@classmethod
|
||||
@report_result
|
||||
def make_chart(cls, parent, chart_settings: dict, ctx: Settings) -> Tuple[Report, "PCRFigure"]:
|
||||
"""
|
||||
Creates a PCRFigure. Overrides parent
|
||||
|
||||
@@ -4,6 +4,7 @@ All kit and reagent related models
|
||||
from __future__ import annotations
|
||||
import datetime
|
||||
import json
|
||||
import sys
|
||||
from pprint import pformat
|
||||
import yaml
|
||||
from sqlalchemy import Column, String, TIMESTAMP, JSON, INTEGER, ForeignKey, Interval, Table, FLOAT, BLOB
|
||||
@@ -693,6 +694,9 @@ class SubmissionType(BaseClass):
|
||||
Returns:
|
||||
List[str]: List of sheet names
|
||||
"""
|
||||
# print(f"Getting template file from {self.__database_session__.get_bind()}")
|
||||
if "pytest" in sys.modules:
|
||||
return ExcelFile("C:\\Users\lwark\Documents\python\submissions\mytests\\test_assets\RSL-AR-20240513-1.xlsx").sheet_names
|
||||
return ExcelFile(BytesIO(self.template_file), engine="openpyxl").sheet_names
|
||||
|
||||
def set_template_file(self, filepath: Path | str):
|
||||
|
||||
@@ -6,7 +6,7 @@ import sys
|
||||
import types
|
||||
from copy import deepcopy
|
||||
from getpass import getuser
|
||||
import logging, uuid, tempfile, re, yaml, base64
|
||||
import logging, uuid, tempfile, re, base64
|
||||
from zipfile import ZipFile
|
||||
from tempfile import TemporaryDirectory, TemporaryFile
|
||||
from operator import itemgetter
|
||||
@@ -167,28 +167,24 @@ class BasicSubmission(BaseClass):
|
||||
|
||||
"""
|
||||
# NOTE: Create defaults for all submission_types
|
||||
parent_defs = super().get_default_info()
|
||||
# NOTE: Singles tells the query which fields to set limit to 1
|
||||
dicto = super().get_default_info()
|
||||
recover = ['filepath', 'samples', 'csv', 'comment', 'equipment']
|
||||
dicto = dict(
|
||||
dicto.update(dict(
|
||||
details_ignore=['excluded', 'reagents', 'samples',
|
||||
'extraction_info', 'comment', 'barcode',
|
||||
'platemap', 'export_map', 'equipment', 'tips', 'custom'],
|
||||
# NOTE: Fields not placed in ui form
|
||||
form_ignore=['reagents', 'ctx', 'id', 'cost', 'extraction_info', 'signed_by', 'comment', 'namer',
|
||||
'submission_object', "tips", 'contact_phone', 'custom'] + recover,
|
||||
'submission_object', "tips", 'contact_phone', 'custom', 'cost_centre'] + recover,
|
||||
# NOTE: Fields not placed in ui form to be moved to pydantic
|
||||
form_recover=recover
|
||||
)
|
||||
# NOTE: Singles tells the query which fields to set limit to 1
|
||||
dicto['singles'] = parent_defs['singles']
|
||||
))
|
||||
# NOTE: Grab mode_sub_type specific info.
|
||||
output = {}
|
||||
for k, v in dicto.items():
|
||||
if len(args) > 0 and k not in args:
|
||||
# logger.debug(f"Don't want {k}")
|
||||
continue
|
||||
else:
|
||||
output[k] = v
|
||||
if args:
|
||||
output = {k: v for k, v in dicto.items() if k in args}
|
||||
else:
|
||||
output = {k: v for k, v in dicto.items()}
|
||||
if isinstance(submission_type, SubmissionType):
|
||||
st = submission_type
|
||||
else:
|
||||
@@ -198,7 +194,7 @@ class BasicSubmission(BaseClass):
|
||||
else:
|
||||
output['submission_type'] = st.name
|
||||
for k, v in st.defaults.items():
|
||||
if len(args) > 0 and k not in args:
|
||||
if args and k not in args:
|
||||
# logger.debug(f"Don't want {k}")
|
||||
continue
|
||||
else:
|
||||
@@ -272,6 +268,7 @@ class BasicSubmission(BaseClass):
|
||||
field = self.__getattribute__(name)
|
||||
except AttributeError:
|
||||
return None
|
||||
# assert isinstance(field, list)
|
||||
for item in field:
|
||||
if extra:
|
||||
yield item.to_sub_dict(extra)
|
||||
@@ -1137,9 +1134,9 @@ class BasicSubmission(BaseClass):
|
||||
limit = 1
|
||||
case _:
|
||||
pass
|
||||
if chronologic:
|
||||
logger.debug("Attempting sort by date descending")
|
||||
query = query.order_by(cls.submitted_date.desc())
|
||||
# if chronologic:
|
||||
# logger.debug("Attempting sort by date descending")
|
||||
query = query.order_by(cls.submitted_date.desc())
|
||||
if page_size is not None:
|
||||
query = query.limit(page_size)
|
||||
page = page - 1
|
||||
@@ -2980,7 +2977,6 @@ class WastewaterArticAssociation(SubmissionSampleAssociation):
|
||||
Returns:
|
||||
dict: Updated dictionary with row, column and well updated
|
||||
"""
|
||||
|
||||
sample = super().to_sub_dict()
|
||||
sample['ct'] = self.ct
|
||||
sample['source_plate'] = self.source_plate
|
||||
|
||||
Reference in New Issue
Block a user