Split Concentration controls on the chart so they are individually selectable.
This commit is contained in:
@@ -7,12 +7,14 @@ from backend.excel.reports import ConcentrationMaker
|
||||
from frontend.visualizations.concentrations_chart import ConcentrationsChart
|
||||
import logging
|
||||
|
||||
|
||||
logger = logging.getLogger(f"submissions.{__name__}")
|
||||
|
||||
|
||||
class Concentrations(InfoPane):
|
||||
|
||||
def __init__(self, parent: QWidget):
|
||||
from .. import CheckableComboBox
|
||||
super().__init__(parent)
|
||||
self.save_button = QPushButton("Save Chart", parent=self)
|
||||
self.save_button.pressed.connect(self.save_png)
|
||||
@@ -20,12 +22,14 @@ class Concentrations(InfoPane):
|
||||
self.export_button = QPushButton("Save Data", parent=self)
|
||||
self.export_button.pressed.connect(self.save_excel)
|
||||
self.layout.addWidget(self.export_button, 0, 3, 1, 1)
|
||||
check_label = QLabel("Controls Only")
|
||||
self.all_box = QCheckBox()
|
||||
self.all_box.setChecked(True)
|
||||
self.all_box.checkStateChanged.connect(self.update_data)
|
||||
self.layout.addWidget(check_label, 1, 0, 1, 1)
|
||||
self.layout.addWidget(self.all_box, 1, 1, 1, 1)
|
||||
self.pos_neg = CheckableComboBox(parent=self)
|
||||
self.pos_neg.model().itemChanged.connect(self.update_data)
|
||||
self.pos_neg.setEditable(False)
|
||||
self.pos_neg.addItem("Positive")
|
||||
self.pos_neg.addItem("Negative")
|
||||
self.pos_neg.addItem("Samples", start_checked=False)
|
||||
self.layout.addWidget(QLabel("Control Types"), 1, 0, 1, 1)
|
||||
self.layout.addWidget(self.pos_neg, 1, 1, 1, 1)
|
||||
self.fig = None
|
||||
self.report_object = None
|
||||
self.update_data()
|
||||
@@ -37,10 +41,14 @@ class Concentrations(InfoPane):
|
||||
Returns:
|
||||
None
|
||||
"""
|
||||
include = self.pos_neg.get_checked()
|
||||
# logger.debug(f"Include: {include}")
|
||||
super().update_data()
|
||||
months = self.diff_month(self.start_date, self.end_date)
|
||||
# logger.debug(f"Box checked: {self.all_box.isChecked()}")
|
||||
chart_settings = dict(start_date=self.start_date, end_date=self.end_date, controls_only=self.all_box.isChecked())
|
||||
# chart_settings = dict(start_date=self.start_date, end_date=self.end_date, controls_only=self.all_box.isChecked())
|
||||
chart_settings = dict(start_date=self.start_date, end_date=self.end_date,
|
||||
include=include)
|
||||
self.report_obj = ConcentrationMaker(**chart_settings)
|
||||
self.fig = ConcentrationsChart(df=self.report_obj.df, settings=chart_settings, modes=[], months=months)
|
||||
self.webview.setHtml(self.fig.html)
|
||||
|
||||
@@ -46,12 +46,15 @@ class CheckableComboBox(QComboBox):
|
||||
# once there is a checkState set, it is rendered
|
||||
# here we assume default Unchecked
|
||||
|
||||
def addItem(self, item, header: bool = False):
|
||||
def addItem(self, item, header: bool = False, start_checked: bool = True):
|
||||
super(CheckableComboBox, self).addItem(item)
|
||||
item: QStandardItem = self.model().item(self.count() - 1, 0)
|
||||
if not header:
|
||||
item.setFlags(Qt.ItemFlag.ItemIsUserCheckable | Qt.ItemFlag.ItemIsEnabled)
|
||||
item.setCheckState(Qt.CheckState.Checked)
|
||||
if start_checked:
|
||||
item.setCheckState(Qt.CheckState.Checked)
|
||||
else:
|
||||
item.setCheckState(Qt.CheckState.Unchecked)
|
||||
|
||||
def itemChecked(self, index):
|
||||
item = self.model().item(index, 0)
|
||||
@@ -60,14 +63,18 @@ class CheckableComboBox(QComboBox):
|
||||
def changed(self):
|
||||
self.updated.emit()
|
||||
|
||||
def get_checked(self):
|
||||
checked = [self.itemText(i) for i in range(self.count()) if self.itemChecked(i)]
|
||||
return checked
|
||||
|
||||
|
||||
class Pagifier(QWidget):
|
||||
|
||||
def __init__(self, page_max:int):
|
||||
def __init__(self, page_max: int):
|
||||
super().__init__()
|
||||
self.page_max = math.ceil(page_max)
|
||||
self.page_anchor = 1
|
||||
next = QPushButton(parent=self, icon = QIcon.fromTheme(QIcon.ThemeIcon.GoNext))
|
||||
next = QPushButton(parent=self, icon=QIcon.fromTheme(QIcon.ThemeIcon.GoNext))
|
||||
next.pressed.connect(self.increment_page)
|
||||
previous = QPushButton(parent=self, icon=QIcon.fromTheme(QIcon.ThemeIcon.GoPrevious))
|
||||
previous.pressed.connect(self.decrement_page)
|
||||
|
||||
@@ -92,6 +92,7 @@ class SubmissionDetails(QDialog):
|
||||
Args:
|
||||
sample (str): Submitter Id of the sample.
|
||||
"""
|
||||
logger.debug(f"Sample details.")
|
||||
if isinstance(sample, str):
|
||||
sample = BasicSample.query(submitter_id=sample)
|
||||
base_dict = sample.to_sub_dict(full_data=True)
|
||||
@@ -102,6 +103,8 @@ class SubmissionDetails(QDialog):
|
||||
with open(template_path.joinpath("css", "styles.css"), "r") as f:
|
||||
css = f.read()
|
||||
html = template.render(sample=base_dict, css=css)
|
||||
with open(f"{sample.submitter_id}.html", 'w') as f:
|
||||
f.write(html)
|
||||
self.webview.setHtml(html)
|
||||
self.setWindowTitle(f"Sample Details - {sample.submitter_id}")
|
||||
|
||||
@@ -114,6 +117,7 @@ class SubmissionDetails(QDialog):
|
||||
kit (str | KitType): Name of kit.
|
||||
reagent (str | Reagent): Lot number of the reagent
|
||||
"""
|
||||
logger.debug(f"Reagent details.")
|
||||
if isinstance(reagent, str):
|
||||
reagent = Reagent.query(lot=reagent)
|
||||
if isinstance(kit, str):
|
||||
@@ -164,6 +168,7 @@ class SubmissionDetails(QDialog):
|
||||
Args:
|
||||
submission (str | BasicSubmission): Submission of interest.
|
||||
"""
|
||||
logger.debug(f"Submission details.")
|
||||
if isinstance(submission, str):
|
||||
submission = BasicSubmission.query(rsl_plate_num=submission)
|
||||
self.rsl_plate_num = submission.rsl_plate_num
|
||||
|
||||
Reference in New Issue
Block a user