mid refactor for improved rebustness and readability
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
from backend.db.models import *
|
||||
import logging
|
||||
|
||||
|
||||
logger = logging.getLogger(f"submissions.{__name__}")
|
||||
|
||||
def check_kit_integrity(sub:BasicSubmission|KitType, reagenttypes:list|None=None) -> dict|None:
|
||||
@@ -21,6 +20,7 @@ def check_kit_integrity(sub:BasicSubmission|KitType, reagenttypes:list|None=None
|
||||
match sub:
|
||||
case BasicSubmission():
|
||||
ext_kit_rtypes = [reagenttype.name for reagenttype in sub.extraction_kit.reagent_types]
|
||||
# Overwrite function parameter reagenttypes
|
||||
reagenttypes = [reagent.type.name for reagent in sub.reagents]
|
||||
case KitType():
|
||||
ext_kit_rtypes = [reagenttype.name for reagenttype in sub.reagent_types]
|
||||
@@ -30,13 +30,14 @@ def check_kit_integrity(sub:BasicSubmission|KitType, reagenttypes:list|None=None
|
||||
check = set(ext_kit_rtypes) == set(reagenttypes)
|
||||
logger.debug(f"Checking if reagents match kit contents: {check}")
|
||||
# what reagent types are in both lists?
|
||||
common = list(set(ext_kit_rtypes).intersection(reagenttypes))
|
||||
logger.debug(f"common reagents types: {common}")
|
||||
# common = list(set(ext_kit_rtypes).intersection(reagenttypes))
|
||||
missing = list(set(ext_kit_rtypes).difference(reagenttypes))
|
||||
logger.debug(f"Missing reagents types: {missing}")
|
||||
# if lists are equal return no problem
|
||||
if check:
|
||||
if len(missing)==0:
|
||||
result = None
|
||||
else:
|
||||
missing = [x for x in ext_kit_rtypes if x not in common]
|
||||
# missing = [x for x in ext_kit_rtypes if x not in common]
|
||||
result = {'message' : f"Couldn't verify reagents match listed kit components.\n\nIt looks like you are missing: {[item.upper() for item in missing]}\n\nAlternatively, you may have set the wrong extraction kit.", 'missing': missing}
|
||||
return result
|
||||
|
||||
|
||||
Reference in New Issue
Block a user