Mid change in details templates

This commit is contained in:
lwark
2024-06-20 07:46:46 -05:00
parent 12e552800a
commit 337112a27d
20 changed files with 575 additions and 300 deletions

View File

@@ -113,7 +113,7 @@ class ControlsViewer(QWidget):
"""
report = Report()
# logger.debug(f"Control getter context: \n\tControl type: {self.con_type}\n\tMode: {self.mode}\n\tStart Date: {self.start_date}\n\tEnd Date: {self.end_date}")
# set the subtype for kraken
# NOTE: set the subtype for kraken
if self.sub_typer.currentText() == "":
self.subtype = None
else:
@@ -121,28 +121,28 @@ class ControlsViewer(QWidget):
# logger.debug(f"Subtype: {self.subtype}")
# query all controls using the type/start and end dates from the gui
controls = Control.query(control_type=self.con_type, start_date=self.start_date, end_date=self.end_date)
# if no data found from query set fig to none for reporting in webview
if controls == None:
# NOTE: if no data found from query set fig to none for reporting in webview
if controls is None:
fig = None
else:
# change each control to list of dictionaries
# NOTE: change each control to list of dictionaries
data = [control.convert_by_mode(mode=self.mode) for control in controls]
# flatten data to one dimensional list
# 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: {type(data)}")
if data == []:
if not data:
self.report.add_result(Result(status="Critical", msg="No data found for controls in given date range."))
return
# send to dataframe creator
# NOTE send to dataframe creator
df = convert_data_list_to_df(input=data, subtype=self.subtype)
if self.subtype == None:
if self.subtype is None:
title = self.mode
else:
title = f"{self.mode} - {self.subtype}"
# send dataframe to chart maker
fig = create_charts(ctx=self.app.ctx, df=df, ytitle=title)
# logger.debug(f"Updating figure...")
# construct html for webview
# NOTE: construct html for webview
html = construct_html(figure=fig)
# logger.debug(f"The length of html code is: {len(html)}")
self.webengineview.setHtml(html)

View File

@@ -25,7 +25,7 @@ class AddReagentForm(QDialog):
"""
def __init__(self, reagent_lot:str|None=None, reagent_role: str | None=None, expiry: date | None=None, reagent_name: str | None=None) -> None:
super().__init__()
if reagent_lot == None:
if reagent_lot is None:
reagent_lot = reagent_role
self.setWindowTitle("Add Reagent")
@@ -47,7 +47,7 @@ class AddReagentForm(QDialog):
self.exp_input = QDateEdit(calendarPopup=True)
self.exp_input.setObjectName('expiry')
# if expiry is not passed in from gui, use today
if expiry == None:
if expiry is None:
self.exp_input.setDate(QDate.currentDate())
else:
try:
@@ -144,7 +144,7 @@ class FirstStrandSalvage(QDialog):
def __init__(self, ctx:Settings, submitter_id:str, rsl_plate_num:str|None=None) -> None:
super().__init__()
if rsl_plate_num == None:
if rsl_plate_num is None:
rsl_plate_num = ""
self.setWindowTitle("Add Reagent")

View File

@@ -92,6 +92,7 @@ class SubmissionDetails(QDialog):
# logger.debug(f"Making platemap...")
self.base_dict['platemap'] = BasicSubmission.make_plate_map(sample_list=submission.hitpick_plate())
self.base_dict, self.template = submission.get_details_template(base_dict=self.base_dict)
logger.debug(f"Submission_details: {pformat(self.base_dict)}")
self.html = self.template.render(sub=self.base_dict, signing_permission=is_power_user())
self.webview.setHtml(self.html)
# with open("test.html", "w") as f:
@@ -110,8 +111,9 @@ class SubmissionDetails(QDialog):
def export(self):
"""
Renders submission to html, then creates and saves .pdf file to user selected file.
"""
fname = select_save_file(obj=self, default_name=self.base_dict['Plate Number'], extension="pdf")
"""
logger.debug(f"Base dict: {pformat(self.base_dict)}")
fname = select_save_file(obj=self, default_name=self.base_dict['plate_number'], extension="docx")
image_io = BytesIO()
temp_dir = Path(TemporaryDirectory().name)
hti = Html2Image(output_path=temp_dir, size=(2400, 1500))

View File

@@ -7,7 +7,7 @@ from PyQt6.QtWidgets import QTableView, QMenu
from PyQt6.QtCore import Qt, QAbstractTableModel, QSortFilterProxyModel
from PyQt6.QtGui import QAction, QCursor
from backend.db.models import BasicSubmission
from backend.excel import make_report_html, make_report_xlsx
from backend.excel import make_report_html, make_report_xlsx, ReportMaker
from tools import Report, Result, row_map, get_first_blank_df_row, html_to_pdf
from .functions import select_save_file, select_open_file
from .misc import ReportDatePicker
@@ -168,7 +168,7 @@ class SubmissionsSheet(QTableView):
# NOTE: Lookup imported submissions
sub = BasicSubmission.query(rsl_plate_num=new_run['rsl_plate_num'])
# NOTE: If no such submission exists, move onto the next run
if sub == None:
if sub is None:
continue
try:
# logger.debug(f"Found submission: {sub.rsl_plate_num}")
@@ -215,7 +215,7 @@ class SubmissionsSheet(QTableView):
# NOTE: lookup imported submission
sub = BasicSubmission.query(rsl_number=new_run['rsl_plate_num'])
# NOTE: if imported submission doesn't exist move on to next run
if sub == None:
if sub is None:
continue
# try:
# logger.debug(f"Found submission: {sub.rsl_plate_num}")
@@ -255,12 +255,12 @@ class SubmissionsSheet(QTableView):
subs = BasicSubmission.query(start_date=info['start_date'], end_date=info['end_date'])
# NOTE: convert each object to dict
records = [item.to_dict(report=True) for item in subs]
logger.debug(f"Records: {pformat(records)}")
# logger.debug(f"Records: {pformat(records)}")
# NOTE: make dataframe from record dictionaries
detailed_df, summary_df = make_report_xlsx(records=records)
html = make_report_html(df=summary_df, start_date=info['start_date'], end_date=info['end_date'])
# NOTE: get save location of report
fname = select_save_file(obj=self, default_name=f"Submissions_Report_{info['start_date']}-{info['end_date']}.pdf", extension="pdf")
fname = select_save_file(obj=self, default_name=f"Submissions_Report_{info['start_date']}-{info['end_date']}.docx", extension="docx")
html_to_pdf(html=html, output_file=fname)
writer = pd.ExcelWriter(fname.with_suffix(".xlsx"), engine='openpyxl')
summary_df.to_excel(writer, sheet_name="Report")
@@ -287,4 +287,6 @@ class SubmissionsSheet(QTableView):
if cell.row > 1:
cell.style = 'Currency'
writer.close()
# rp = ReportMaker(start_date=info['start_date'], end_date=info['end_date'])
# rp.write_report(filename=fname, obj=self)
self.report.add_result(report)

View File

@@ -89,7 +89,7 @@ class SubmissionFormContainer(QWidget):
self.samples = []
self.missing_info = []
# NOTE: set file dialog
if isinstance(fname, bool) or fname == None:
if isinstance(fname, bool) or fname is None:
fname = select_open_file(self, file_extension="xlsx")
# logger.debug(f"Attempting to parse file: {fname}")
if not fname.exists():
@@ -172,7 +172,7 @@ class SubmissionFormWidget(QWidget):
logger.error(f"Couldn't get attribute from pyd: {k}")
value = dict(value=None, missing=True)
add_widget = self.create_widget(key=k, value=value, submission_type=self.pyd.submission_type['value'], sub_obj=st)
if add_widget != None:
if add_widget is not None:
self.layout.addWidget(add_widget)
if k == "extraction_kit":
add_widget.input.currentTextChanged.connect(self.scrape_reagents)
@@ -347,7 +347,7 @@ class SubmissionFormWidget(QWidget):
Args:
fname (Path | None, optional): Input filename. Defaults to None.
"""
if isinstance(fname, bool) or fname == None:
if isinstance(fname, bool) or fname is None:
fname = select_save_file(obj=self, default_name=self.pyd.construct_filename(), extension="csv")
try:
@@ -546,7 +546,7 @@ class SubmissionFormWidget(QWidget):
check = not value['missing']
except:
check = True
if label_name != None:
if label_name is not None:
self.setObjectName(label_name)
else:
self.setObjectName(f"{key}_label")
@@ -605,7 +605,7 @@ class SubmissionFormWidget(QWidget):
# logger.debug(f"Using this lot for the reagent {self.reagent}: {lot}")
wanted_reagent = Reagent.query(lot_number=lot, reagent_role=self.reagent.role)
# NOTE: if reagent doesn't exist in database, offer to add it (uses App.add_reagent)
if wanted_reagent == None:
if wanted_reagent is None:
dlg = QuestionAsker(title=f"Add {lot}?",
message=f"Couldn't find reagent type {self.reagent.role}: {lot} in the database.\n\nWould you like to add it?")
if dlg.exec():
@@ -621,7 +621,7 @@ class SubmissionFormWidget(QWidget):
# NOTE: Since this now gets passed in directly from the parser -> pyd -> form and the parser gets the name
# from the db, it should no longer be necessary to query the db with reagent/kit, but with rt name directly.
rt = ReagentRole.query(name=self.reagent.role)
if rt == None:
if rt is None:
rt = ReagentRole.query(kit_type=self.extraction_kit, reagent=wanted_reagent)
return PydReagent(name=wanted_reagent.name, lot=wanted_reagent.lot, role=rt.name,
expiry=wanted_reagent.expiry, missing=False), None
@@ -689,7 +689,7 @@ class SubmissionFormWidget(QWidget):
if isinstance(looked_up_reg, list):
looked_up_reg = None
# logger.debug(f"Because there was no reagent listed for {reagent.lot}, we will insert the last lot used: {looked_up_reg}")
if looked_up_reg != None:
if looked_up_reg is not None:
try:
relevant_reagents.remove(str(looked_up_reg.lot))
relevant_reagents.insert(0, str(looked_up_reg.lot))