Mid-code cleanup
This commit is contained in:
@@ -11,25 +11,33 @@ logger = logging.getLogger(f"submissions.{__name__}")
|
||||
|
||||
class TurnaroundChart(CustomFigure):
|
||||
|
||||
def __init__(self, df: pd.DataFrame, modes: list, settings: dict, ytitle: str | None = None,
|
||||
def __init__(self, df: pd.DataFrame, modes: list, settings: dict, threshold: float | None = None,
|
||||
ytitle: str | None = None,
|
||||
parent: QWidget | None = None,
|
||||
months: int = 6):
|
||||
super().__init__(df=df, modes=modes, settings=settings)
|
||||
self.df = df
|
||||
try:
|
||||
months = int(settings['months'])
|
||||
except KeyError:
|
||||
months = 6
|
||||
# logger.debug(f"DF: {self.df}")
|
||||
self.construct_chart(df=df)
|
||||
self.add_hline(y=3.5)
|
||||
self.construct_chart()
|
||||
if threshold:
|
||||
self.add_hline(y=threshold)
|
||||
# self.update_xaxes()
|
||||
self.update_layout(showlegend=False)
|
||||
|
||||
def construct_chart(self, df: pd.DataFrame):
|
||||
def construct_chart(self, df: pd.DataFrame | None = None):
|
||||
if df:
|
||||
self.df = df
|
||||
# logger.debug(f"PCR df:\n {df}")
|
||||
df = df.sort_values(by=['submitted_date', 'name'])
|
||||
self.df = self.df[self.df.days.notnull()]
|
||||
self.df = self.df.sort_values(['submitted_date', 'name'], ascending=[True, True]).reset_index(drop=True)
|
||||
self.df = self.df.reset_index().rename(columns={"index": "idx"})
|
||||
# logger.debug(f"DF: {self.df}")
|
||||
try:
|
||||
scatter = px.scatter(data_frame=df, x='name', y="days",
|
||||
scatter = px.scatter(data_frame=self.df, x='idx', y="days",
|
||||
hover_data=["name", "submitted_date", "completed_date", "days"],
|
||||
color="acceptable", color_discrete_map={True: "green", False: "red"}
|
||||
)
|
||||
@@ -37,3 +45,12 @@ class TurnaroundChart(CustomFigure):
|
||||
scatter = px.scatter()
|
||||
self.add_traces(scatter.data)
|
||||
self.update_traces(marker={'size': 15})
|
||||
tickvals = self.df['idx'].tolist()
|
||||
ticklabels = self.df['name'].tolist()
|
||||
self.update_layout(
|
||||
xaxis=dict(
|
||||
tickmode='array',
|
||||
tickvals=tickvals,
|
||||
ticktext=ticklabels,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -8,7 +8,7 @@ from PyQt6.QtWebChannel import QWebChannel
|
||||
from PyQt6.QtCore import Qt, pyqtSlot
|
||||
from jinja2 import TemplateNotFound
|
||||
from backend.db.models import BasicSubmission, BasicSample, Reagent, KitType
|
||||
from tools import is_power_user, jinja_template_loading
|
||||
from tools import is_power_user, jinja_template_loading, timezone
|
||||
from .functions import select_save_file
|
||||
from .misc import save_pdf
|
||||
from pathlib import Path
|
||||
@@ -176,7 +176,8 @@ class SubmissionDetails(QDialog):
|
||||
if isinstance(submission, str):
|
||||
submission = BasicSubmission.query(rsl_plate_num=submission)
|
||||
submission.signed_by = getuser()
|
||||
submission.completed_date = datetime.now().date()
|
||||
submission.completed_date = datetime.now()
|
||||
submission.completed_date.replace(tzinfo=timezone)
|
||||
submission.save()
|
||||
self.submission_details(submission=self.rsl_plate_num)
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
from PyQt6.QtCore import QSignalBlocker
|
||||
from PyQt6.QtWebEngineWidgets import QWebEngineView
|
||||
from PyQt6.QtWidgets import QWidget, QGridLayout, QPushButton, QLabel
|
||||
from PyQt6.QtWidgets import QWidget, QGridLayout, QPushButton, QLabel, QComboBox
|
||||
from .info_tab import InfoPane
|
||||
from backend.excel.reports import TurnaroundMaker
|
||||
from pandas import DataFrame
|
||||
from backend.db import BasicSubmission
|
||||
from backend.db import BasicSubmission, SubmissionType
|
||||
from frontend.visualizations.turnaround_chart import TurnaroundChart
|
||||
import logging
|
||||
|
||||
@@ -17,6 +17,11 @@ class TurnaroundTime(InfoPane):
|
||||
super().__init__(parent)
|
||||
self.chart = None
|
||||
self.report_object = None
|
||||
self.submission_typer = QComboBox(self)
|
||||
subs = ["Any"] + [item.name for item in SubmissionType.query()]
|
||||
self.submission_typer.addItems(subs)
|
||||
self.layout.addWidget(self.submission_typer, 1, 1, 1, 3)
|
||||
self.submission_typer.currentTextChanged.connect(self.date_changed)
|
||||
self.date_changed()
|
||||
|
||||
def date_changed(self):
|
||||
@@ -31,6 +36,16 @@ class TurnaroundTime(InfoPane):
|
||||
return
|
||||
super().date_changed()
|
||||
chart_settings = dict(start_date=self.start_date, end_date=self.end_date)
|
||||
self.report_obj = TurnaroundMaker(start_date=self.start_date, end_date=self.end_date)
|
||||
self.chart = TurnaroundChart(df=self.report_obj.df, settings=chart_settings, modes=[])
|
||||
if self.submission_typer.currentText() == "Any":
|
||||
submission_type = None
|
||||
subtype_obj = None
|
||||
else:
|
||||
submission_type = self.submission_typer.currentText()
|
||||
subtype_obj = SubmissionType.query(name = submission_type)
|
||||
self.report_obj = TurnaroundMaker(start_date=self.start_date, end_date=self.end_date, submission_type=submission_type)
|
||||
if subtype_obj:
|
||||
threshold = subtype_obj.defaults['turnaround_time'] + 0.5
|
||||
else:
|
||||
threshold = None
|
||||
self.chart = TurnaroundChart(df=self.report_obj.df, settings=chart_settings, modes=[], threshold=threshold)
|
||||
self.webview.setHtml(self.chart.to_html())
|
||||
|
||||
Reference in New Issue
Block a user