From 3a318fff38a3b7a8f281952e6e491d290dd95148 Mon Sep 17 00:00:00 2001 From: lwark Date: Wed, 2 Apr 2025 13:08:32 -0500 Subject: [PATCH] Bug fixes --- .../backend/db/models/submissions.py | 56 ++++++------ src/submissions/backend/excel/reports.py | 10 ++- .../visualizations/concentrations_chart.py | 2 +- src/submissions/frontend/widgets/app.py | 90 +++++++++---------- 4 files changed, 82 insertions(+), 76 deletions(-) diff --git a/src/submissions/backend/db/models/submissions.py b/src/submissions/backend/db/models/submissions.py index af8fe65..3d80282 100644 --- a/src/submissions/backend/db/models/submissions.py +++ b/src/submissions/backend/db/models/submissions.py @@ -1880,34 +1880,34 @@ class Wastewater(BasicSubmission): new_control.save() return report - def update_subsampassoc(self, assoc: SubmissionSampleAssociation, input_dict: dict) -> SubmissionSampleAssociation: - """ - Updates a joined submission sample association by assigning ct values to n1 or n2 based on alphabetical sorting. - - Args: - sample (BasicSample): Associated sample. - input_dict (dict): values to be updated - - Returns: - SubmissionSampleAssociation: Updated association - """ - # logger.debug(f"Input dict: {pformat(input_dict)}") - # - assoc = super().update_subsampassoc(assoc=assoc, input_dict=input_dict) - # targets = {k: input_dict[k] for k in sorted(input_dict.keys()) if k.startswith("ct_")} - # assert 0 < len(targets) <= 2 - # for k, v in targets.items(): - # # logger.debug(f"Setting sample {sample} with key {k} to value {v}") - # # update_key = f"ct_n{i}" - # current_value = getattr(assoc, k) - # logger.debug(f"Current value came back as: {current_value}") - # if current_value is None: - # setattr(assoc, k, v) - # else: - # logger.debug(f"Have a value already, {current_value}... skipping.") - if assoc.column == 3: - logger.debug(f"Final association for association {assoc}:\n{pformat(assoc.__dict__)}") - return assoc + # def update_subsampassoc(self, assoc: SubmissionSampleAssociation, input_dict: dict) -> SubmissionSampleAssociation: + # """ + # Updates a joined submission sample association by assigning ct values to n1 or n2 based on alphabetical sorting. + # + # Args: + # sample (BasicSample): Associated sample. + # input_dict (dict): values to be updated + # + # Returns: + # SubmissionSampleAssociation: Updated association + # """ + # # logger.debug(f"Input dict: {pformat(input_dict)}") + # # + # assoc = super().update_subsampassoc(assoc=assoc, input_dict=input_dict) + # # targets = {k: input_dict[k] for k in sorted(input_dict.keys()) if k.startswith("ct_")} + # # assert 0 < len(targets) <= 2 + # # for k, v in targets.items(): + # # # logger.debug(f"Setting sample {sample} with key {k} to value {v}") + # # # update_key = f"ct_n{i}" + # # current_value = getattr(assoc, k) + # # logger.debug(f"Current value came back as: {current_value}") + # # if current_value is None: + # # setattr(assoc, k, v) + # # else: + # # logger.debug(f"Have a value already, {current_value}... skipping.") + # if assoc.column == 3: + # logger.debug(f"Final association for association {assoc}:\n{pformat(assoc.__dict__)}") + # return assoc class WastewaterArtic(BasicSubmission): diff --git a/src/submissions/backend/excel/reports.py b/src/submissions/backend/excel/reports.py index dca98de..f6f5e3d 100644 --- a/src/submissions/backend/excel/reports.py +++ b/src/submissions/backend/excel/reports.py @@ -2,6 +2,7 @@ Contains functions for generating summary reports """ import itertools +import re import sys from pprint import pformat from pandas import DataFrame, ExcelWriter @@ -211,8 +212,13 @@ class ConcentrationMaker(ReportArchetype): @classmethod def build_record(cls, control) -> dict: - - positive = not control.submitter_id.lower().startswith("en") + regex = re.compile(r"^(ATCC)|(MCS)", flags=re.IGNORECASE) + if bool(regex.match(control.submitter_id)): + positive = "positive" + elif control.submitter_id.lower().startswith("en"): + positive = "negative" + else: + positive = "sample" try: concentration = float(control.concentration) except (TypeError, ValueError): diff --git a/src/submissions/frontend/visualizations/concentrations_chart.py b/src/submissions/frontend/visualizations/concentrations_chart.py index 75e85e5..9a4610a 100644 --- a/src/submissions/frontend/visualizations/concentrations_chart.py +++ b/src/submissions/frontend/visualizations/concentrations_chart.py @@ -34,7 +34,7 @@ class ConcentrationsChart(CustomFigure): # logger.debug(f"DF after changes:\n{self.df}") scatter = px.scatter(data_frame=self.df, x='submission', y="concentration", hover_data=["name", "submission", "submitted_date", "concentration"], - color="positive", color_discrete_map={True: "red", False: "green"} + color="positive", color_discrete_map={"positive": "red", "negative": "green", "sample":"orange"} ) except (ValueError, AttributeError) as e: logger.error(f"Error constructing chart: {e}") diff --git a/src/submissions/frontend/widgets/app.py b/src/submissions/frontend/widgets/app.py index d210b02..f1660a2 100644 --- a/src/submissions/frontend/widgets/app.py +++ b/src/submissions/frontend/widgets/app.py @@ -80,8 +80,8 @@ class App(QMainWindow): helpMenu.addAction(self.docsAction) helpMenu.addAction(self.githubAction) fileMenu.addAction(self.importAction) - fileMenu.addAction(self.yamlExportAction) - fileMenu.addAction(self.yamlImportAction) + # fileMenu.addAction(self.yamlExportAction) + # fileMenu.addAction(self.yamlImportAction) methodsMenu.addAction(self.searchSample) maintenanceMenu.addAction(self.joinExtractionAction) maintenanceMenu.addAction(self.joinPCRAction) @@ -112,8 +112,8 @@ class App(QMainWindow): self.docsAction = QAction("&Docs", self) self.searchSample = QAction("Search Sample", self) self.githubAction = QAction("Github", self) - self.yamlExportAction = QAction("Export Type Example", self) - self.yamlImportAction = QAction("Import Type Template", self) + # self.yamlExportAction = QAction("Export Type Example", self) + # self.yamlImportAction = QAction("Import Type Template", self) self.editReagentAction = QAction("Edit Reagent", self) self.manageOrgsAction = QAction("Manage Clients", self) self.manageKitsAction = QAction("Manage Kits", self) @@ -130,8 +130,8 @@ class App(QMainWindow): self.docsAction.triggered.connect(self.openDocs) self.searchSample.triggered.connect(self.runSampleSearch) self.githubAction.triggered.connect(self.openGithub) - self.yamlExportAction.triggered.connect(self.export_ST_yaml) - self.yamlImportAction.triggered.connect(self.import_ST_yaml) + # self.yamlExportAction.triggered.connect(self.export_ST_yaml) + # self.yamlImportAction.triggered.connect(self.import_ST_yaml) self.table_widget.pager.current_page.textChanged.connect(self.update_data) self.editReagentAction.triggered.connect(self.edit_reagent) self.manageOrgsAction.triggered.connect(self.manage_orgs) @@ -186,46 +186,46 @@ class App(QMainWindow): dlg = SearchBox(parent=self, object_type=Reagent, extras=[dict(name='Role', field="role")]) dlg.exec() - def export_ST_yaml(self): - """ - Copies submission type yaml to file system for editing and remport + # def export_ST_yaml(self): + # """ + # Copies submission type yaml to file system for editing and remport + # + # Returns: + # None + # """ + # if check_if_app(): + # yaml_path = Path(sys._MEIPASS).joinpath("files", "resources", "viral_culture.yml") + # else: + # yaml_path = project_path.joinpath("src", "submissions", "resources", "viral_culture.yml") + # fname = select_save_file(obj=self, default_name="Submission Type Template.yml", extension="yml") + # shutil.copyfile(yaml_path, fname) - Returns: - None - """ - if check_if_app(): - yaml_path = Path(sys._MEIPASS).joinpath("files", "resources", "viral_culture.yml") - else: - yaml_path = project_path.joinpath("src", "submissions", "resources", "viral_culture.yml") - fname = select_save_file(obj=self, default_name="Submission Type Template.yml", extension="yml") - shutil.copyfile(yaml_path, fname) - - @check_authorization - def import_ST_yaml(self, *args, **kwargs): - """ - Imports a yml form into a submission type. - - Args: - *args (): - **kwargs (): - - Returns: - - """ - fname = select_open_file(obj=self, file_extension="yml") - if not fname: - logger.info(f"Import cancelled.") - return - ap = AlertPop(message="This function will proceed in the debug window.", status="Warning", owner=self) - ap.exec() - st = SubmissionType.import_from_json(filepath=fname) - if st: - # NOTE: Do not delete the print statement below. - choice = input("Save the above submission type? [y/N]: ") - if choice.lower() == "y": - pass - else: - logger.warning("Save of submission type cancelled.") + # @check_authorization + # def import_ST_yaml(self, *args, **kwargs): + # """ + # Imports a yml form into a submission type. + # + # Args: + # *args (): + # **kwargs (): + # + # Returns: + # + # """ + # fname = select_open_file(obj=self, file_extension="yml") + # if not fname: + # logger.info(f"Import cancelled.") + # return + # ap = AlertPop(message="This function will proceed in the debug window.", status="Warning", owner=self) + # ap.exec() + # st = SubmissionType.import_from_json(filepath=fname) + # if st: + # # NOTE: Do not delete the print statement below. + # choice = input("Save the above submission type? [y/N]: ") + # if choice.lower() == "y": + # pass + # else: + # logger.warning("Save of submission type cancelled.") def update_data(self): self.table_widget.sub_wid.setData(page=self.table_widget.pager.page_anchor, page_size=page_size)