Improvements to JSON updaters.
This commit is contained in:
@@ -7,24 +7,26 @@ from PyQt6.QtWidgets import (QWidget, QDialog, QGridLayout,
|
||||
)
|
||||
import numpy as np
|
||||
import pyqtgraph as pg
|
||||
from PyQt6.QtGui import QIcon
|
||||
from PyQt6.QtGui import QIcon, QFont
|
||||
from PIL import Image
|
||||
import numpy as np
|
||||
import logging
|
||||
from pprint import pformat
|
||||
from typing import Tuple, List
|
||||
from pathlib import Path
|
||||
from backend.db.models import WastewaterArtic
|
||||
|
||||
logger = logging.getLogger(f"submissions.{__name__}")
|
||||
|
||||
# Main window class
|
||||
class GelBox(QDialog):
|
||||
|
||||
def __init__(self, parent, img_path:str|Path):
|
||||
def __init__(self, parent, img_path:str|Path, submission:WastewaterArtic):
|
||||
super().__init__(parent)
|
||||
# setting title
|
||||
self.setWindowTitle("PyQtGraph")
|
||||
self.img_path = img_path
|
||||
self.submission = submission
|
||||
# setting geometry
|
||||
self.setGeometry(50, 50, 1200, 900)
|
||||
# icon
|
||||
@@ -57,7 +59,11 @@ class GelBox(QDialog):
|
||||
# plot window goes on right side, spanning 3 rows
|
||||
layout.addWidget(self.imv, 1, 1,20,20)
|
||||
# setting this widget as central widget of the main window
|
||||
self.form = ControlsForm(parent=self)
|
||||
try:
|
||||
control_info = sorted(self.submission.gel_controls, key=lambda d: d['location'])
|
||||
except KeyError:
|
||||
control_info = None
|
||||
self.form = ControlsForm(parent=self, control_info=control_info)
|
||||
layout.addWidget(self.form,22,1,1,4)
|
||||
QBtn = QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel
|
||||
self.buttonBox = QDialogButtonBox(QBtn)
|
||||
@@ -79,16 +85,24 @@ class GelBox(QDialog):
|
||||
|
||||
class ControlsForm(QWidget):
|
||||
|
||||
def __init__(self, parent) -> None:
|
||||
def __init__(self, parent, control_info:List=None) -> None:
|
||||
super().__init__(parent)
|
||||
self.layout = QGridLayout()
|
||||
columns = []
|
||||
rows = []
|
||||
try:
|
||||
tt_text = "\n".join([f"{item['sample_id']} - CELL {item['location']}" for item in control_info])
|
||||
except TypeError:
|
||||
tt_text = None
|
||||
for iii, item in enumerate(["Negative Control Key", "Description", "Results - 65 C", "Results - 63 C", "Results - Spike"]):
|
||||
label = QLabel(item)
|
||||
self.layout.addWidget(label, 0, iii,1,1)
|
||||
if iii > 1:
|
||||
columns.append(item)
|
||||
elif iii == 0:
|
||||
if tt_text:
|
||||
label.setStyleSheet("font-weight: bold; color: blue; text-decoration: underline;")
|
||||
label.setToolTip(tt_text)
|
||||
for iii, item in enumerate(["RSL-NTC", "ENC-NTC", "NTC"], start=1):
|
||||
label = QLabel(item)
|
||||
self.layout.addWidget(label, iii, 0, 1, 1)
|
||||
@@ -102,6 +116,11 @@ class ControlsForm(QWidget):
|
||||
widge.setText("Neg")
|
||||
widge.setObjectName(f"{rows[iii]} : {columns[jjj]}")
|
||||
self.layout.addWidget(widge, iii+1, jjj+2, 1, 1)
|
||||
# try:
|
||||
# for iii, item in enumerate(control_info, start=1):
|
||||
# self.layout.addWidget(QLabel(f"{item['sample_id']} - {item['location']}"), iii+4, 1)
|
||||
# except TypeError:
|
||||
# pass
|
||||
self.layout.addWidget(QLabel("Comments:"), 0,5,1,1)
|
||||
self.comment_field = QTextEdit(self)
|
||||
self.comment_field.setFixedHeight(50)
|
||||
|
||||
@@ -95,8 +95,8 @@ class SubmissionDetails(QDialog):
|
||||
self.html = self.template.render(sub=self.base_dict, signing_permission=is_power_user())
|
||||
self.webview.setHtml(self.html)
|
||||
self.setWindowTitle(f"Submission Details - {submission.rsl_plate_num}")
|
||||
with open("details.html", "w") as f:
|
||||
f.write(self.html)
|
||||
# with open("details.html", "w") as f:
|
||||
# f.write(self.html)
|
||||
|
||||
@pyqtSlot(str)
|
||||
def sign_off(self, submission:str|BasicSubmission):
|
||||
@@ -171,7 +171,7 @@ class SubmissionComment(QDialog):
|
||||
commenter = getuser()
|
||||
comment = self.txt_editor.toPlainText()
|
||||
dt = datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M:%S")
|
||||
full_comment = [{"name":commenter, "time": dt, "text": comment}]
|
||||
full_comment = {"name":commenter, "time": dt, "text": comment}
|
||||
logger.debug(f"Full comment: {full_comment}")
|
||||
return full_comment
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'''
|
||||
Contains widgets specific to the submission summary and submission details.
|
||||
'''
|
||||
import logging, json
|
||||
import logging
|
||||
from pprint import pformat
|
||||
from PyQt6.QtWidgets import QTableView, QMenu
|
||||
from PyQt6.QtCore import Qt, QAbstractTableModel, QSortFilterProxyModel
|
||||
@@ -177,35 +177,36 @@ class SubmissionsSheet(QTableView):
|
||||
count += 1
|
||||
except AttributeError:
|
||||
continue
|
||||
if sub.extraction_info != None:
|
||||
# existing = json.loads(sub.extraction_info)
|
||||
existing = sub.extraction_info
|
||||
else:
|
||||
existing = None
|
||||
# Check if the new info already exists in the imported submission
|
||||
try:
|
||||
# if json.dumps(new_run) in sub.extraction_info:
|
||||
if new_run in sub.extraction_info:
|
||||
logger.debug(f"Looks like we already have that info.")
|
||||
continue
|
||||
except TypeError:
|
||||
pass
|
||||
# Update or create the extraction info
|
||||
if existing != None:
|
||||
try:
|
||||
logger.debug(f"Updating {type(existing)}: {existing} with {type(new_run)}: {new_run}")
|
||||
existing.append(new_run)
|
||||
logger.debug(f"Setting: {existing}")
|
||||
# sub.extraction_info = json.dumps(existing)
|
||||
sub.extraction_info = existing
|
||||
except TypeError:
|
||||
logger.error(f"Error updating!")
|
||||
# sub.extraction_info = json.dumps([new_run])
|
||||
sub.extraction_info = [new_run]
|
||||
logger.debug(f"Final ext info for {sub.rsl_plate_num}: {sub.extraction_info}")
|
||||
else:
|
||||
# sub.extraction_info = json.dumps([new_run])
|
||||
sub.extraction_info = [new_run]
|
||||
sub.set_attribute('extraction_info', new_run)
|
||||
# if sub.extraction_info != None:
|
||||
# # existing = json.loads(sub.extraction_info)
|
||||
# existing = sub.extraction_info
|
||||
# else:
|
||||
# existing = None
|
||||
# # Check if the new info already exists in the imported submission
|
||||
# try:
|
||||
# # if json.dumps(new_run) in sub.extraction_info:
|
||||
# if new_run in sub.extraction_info:
|
||||
# logger.debug(f"Looks like we already have that info.")
|
||||
# continue
|
||||
# except TypeError:
|
||||
# pass
|
||||
# # Update or create the extraction info
|
||||
# if existing != None:
|
||||
# try:
|
||||
# logger.debug(f"Updating {type(existing)}: {existing} with {type(new_run)}: {new_run}")
|
||||
# existing.append(new_run)
|
||||
# logger.debug(f"Setting: {existing}")
|
||||
# # sub.extraction_info = json.dumps(existing)
|
||||
# sub.extraction_info = existing
|
||||
# except TypeError:
|
||||
# logger.error(f"Error updating!")
|
||||
# # sub.extraction_info = json.dumps([new_run])
|
||||
# sub.extraction_info = [new_run]
|
||||
# logger.debug(f"Final ext info for {sub.rsl_plate_num}: {sub.extraction_info}")
|
||||
# else:
|
||||
# # sub.extraction_info = json.dumps([new_run])
|
||||
# sub.extraction_info = [new_run]
|
||||
sub.save()
|
||||
self.report.add_result(Result(msg=f"We added {count} logs to the database.", status='Information'))
|
||||
|
||||
@@ -253,37 +254,38 @@ class SubmissionsSheet(QTableView):
|
||||
logger.debug(f"Found submission: {sub.rsl_plate_num}")
|
||||
except AttributeError:
|
||||
continue
|
||||
# check if pcr_info already exists
|
||||
if hasattr(sub, 'pcr_info') and sub.pcr_info != None:
|
||||
# existing = json.loads(sub.pcr_info)
|
||||
existing = sub.pcr_info
|
||||
else:
|
||||
existing = None
|
||||
# check if this entry already exists in imported submission
|
||||
try:
|
||||
# if json.dumps(new_run) in sub.pcr_info:
|
||||
if new_run in sub.pcr_info:
|
||||
logger.debug(f"Looks like we already have that info.")
|
||||
continue
|
||||
else:
|
||||
count += 1
|
||||
except TypeError:
|
||||
logger.error(f"No json to dump")
|
||||
if existing is not None:
|
||||
try:
|
||||
logger.debug(f"Updating {type(existing)}: {existing} with {type(new_run)}: {new_run}")
|
||||
existing.append(new_run)
|
||||
logger.debug(f"Setting: {existing}")
|
||||
# sub.pcr_info = json.dumps(existing)
|
||||
sub.pcr_info = existing
|
||||
except TypeError:
|
||||
logger.error(f"Error updating!")
|
||||
# sub.pcr_info = json.dumps([new_run])
|
||||
sub.pcr_info = [new_run]
|
||||
logger.debug(f"Final ext info for {sub.rsl_plate_num}: {sub.pcr_info}")
|
||||
else:
|
||||
# sub.pcr_info = json.dumps([new_run])
|
||||
sub.pcr_info = [new_run]
|
||||
sub.set_attribute('pcr_info', new_run)
|
||||
# # check if pcr_info already exists
|
||||
# if hasattr(sub, 'pcr_info') and sub.pcr_info != None:
|
||||
# # existing = json.loads(sub.pcr_info)
|
||||
# existing = sub.pcr_info
|
||||
# else:
|
||||
# existing = None
|
||||
# # check if this entry already exists in imported submission
|
||||
# try:
|
||||
# # if json.dumps(new_run) in sub.pcr_info:
|
||||
# if new_run in sub.pcr_info:
|
||||
# logger.debug(f"Looks like we already have that info.")
|
||||
# continue
|
||||
# else:
|
||||
# count += 1
|
||||
# except TypeError:
|
||||
# logger.error(f"No json to dump")
|
||||
# if existing is not None:
|
||||
# try:
|
||||
# logger.debug(f"Updating {type(existing)}: {existing} with {type(new_run)}: {new_run}")
|
||||
# existing.append(new_run)
|
||||
# logger.debug(f"Setting: {existing}")
|
||||
# # sub.pcr_info = json.dumps(existing)
|
||||
# sub.pcr_info = existing
|
||||
# except TypeError:
|
||||
# logger.error(f"Error updating!")
|
||||
# # sub.pcr_info = json.dumps([new_run])
|
||||
# sub.pcr_info = [new_run]
|
||||
# logger.debug(f"Final ext info for {sub.rsl_plate_num}: {sub.pcr_info}")
|
||||
# else:
|
||||
# # sub.pcr_info = json.dumps([new_run])
|
||||
# sub.pcr_info = [new_run]
|
||||
sub.save()
|
||||
self.report.add_result(Result(msg=f"We added {count} logs to the database.", status='Information'))
|
||||
|
||||
|
||||
@@ -5,14 +5,14 @@ from PyQt6.QtWidgets import (
|
||||
from PyQt6.QtCore import pyqtSignal
|
||||
from pathlib import Path
|
||||
from . import select_open_file, select_save_file
|
||||
import logging, difflib, inspect, pickle
|
||||
import logging, difflib, inspect
|
||||
from pathlib import Path
|
||||
from tools import Report, Result, check_not_nan
|
||||
from backend.excel.parser import SheetParser, PCRParser
|
||||
from backend.excel.parser import SheetParser
|
||||
from backend.validators import PydSubmission, PydReagent
|
||||
from backend.db import (
|
||||
KitType, Organization, SubmissionType, Reagent,
|
||||
ReagentType, KitTypeReagentTypeAssociation, BasicSubmission
|
||||
ReagentType, KitTypeReagentTypeAssociation
|
||||
)
|
||||
from pprint import pformat
|
||||
from .pop_ups import QuestionAsker, AlertPop
|
||||
@@ -154,7 +154,7 @@ class SubmissionFormWidget(QWidget):
|
||||
# self.samples = []
|
||||
self.missing_info = []
|
||||
self.ignore = ['filepath', 'samples', 'reagents', 'csv', 'ctx', 'comment',
|
||||
'equipment', 'source_plates', 'id', 'cost', 'extraction_info',
|
||||
'equipment', 'gel_controls', 'id', 'cost', 'extraction_info',
|
||||
'controls', 'pcr_info', 'gel_info', 'gel_image']
|
||||
self.recover = ['filepath', 'samples', 'csv', 'comment', 'equipment']
|
||||
self.layout = QVBoxLayout()
|
||||
|
||||
Reference in New Issue
Block a user