Improved reporting, price tracking
This commit is contained in:
@@ -5,7 +5,7 @@ import sqlite3
|
||||
# from sqlalchemy.exc import IntegrityError, OperationalError
|
||||
# from sqlite3 import IntegrityError, OperationalError
|
||||
import logging
|
||||
from datetime import date, datetime
|
||||
from datetime import date, datetime, timedelta
|
||||
from sqlalchemy import and_
|
||||
import uuid
|
||||
import base64
|
||||
@@ -132,6 +132,12 @@ def construct_submission_info(ctx:dict, info_dict:dict) -> models.BasicSubmissio
|
||||
except AttributeError:
|
||||
logger.debug(f"Could not set attribute: {item} to {info_dict[item]}")
|
||||
continue
|
||||
# calculate cost of the run: immutable cost + mutable times number of columns
|
||||
try:
|
||||
instance.run_cost = instance.extraction_kit.immutable_cost + (instance.extraction_kit.mutable_cost * ((instance.sample_count / 8)/12))
|
||||
except TypeError:
|
||||
logger.debug(f"Looks like that kit doesn't have cost breakdown yet, using full plate cost.")
|
||||
instance.run_cost = instance.extraction_kit.cost_per_run
|
||||
logger.debug(f"Constructed instance: {instance.to_string()}")
|
||||
logger.debug(msg)
|
||||
return instance, {'message':msg}
|
||||
@@ -395,12 +401,13 @@ def create_kit_from_yaml(ctx:dict, exp:dict) -> None:
|
||||
exp (dict): Experiment dictionary created from yaml file
|
||||
"""
|
||||
try:
|
||||
super_users = ctx['super_users']
|
||||
power_users = ctx['power_users']
|
||||
except KeyError:
|
||||
logger.debug("This user does not have permission to add kits.")
|
||||
return {'code':1,'message':"This user does not have permission to add kits."}
|
||||
if getuser not in super_users:
|
||||
logger.debug("This user does not have permission to add kits.")
|
||||
logger.debug(f"Adding kit for user: {getuser()}")
|
||||
if getuser() not in power_users:
|
||||
logger.debug(f"{getuser()} does not have permission to add kits.")
|
||||
return {'code':1, 'message':"This user does not have permission to add kits."}
|
||||
for type in exp:
|
||||
if type == "password":
|
||||
@@ -410,7 +417,7 @@ def create_kit_from_yaml(ctx:dict, exp:dict) -> None:
|
||||
for r in exp[type]['kits'][kt]['reagenttypes']:
|
||||
look_up = ctx['database_session'].query(models.ReagentType).filter(models.ReagentType.name==r).first()
|
||||
if look_up == None:
|
||||
rt = models.ReagentType(name=r.replace(" ", "_").lower(), eol_ext=datetime.timedelta(30*exp[type]['kits'][kt]['reagenttypes'][r]['eol_ext']), kits=[kit])
|
||||
rt = models.ReagentType(name=r.replace(" ", "_").lower(), eol_ext=timedelta(30*exp[type]['kits'][kt]['reagenttypes'][r]['eol_ext']), kits=[kit])
|
||||
else:
|
||||
rt = look_up
|
||||
rt.kits.append(kit)
|
||||
|
||||
@@ -18,6 +18,8 @@ class KitType(Base):
|
||||
submissions = relationship("BasicSubmission", back_populates="extraction_kit") #: submissions this kit was used for
|
||||
used_for = Column(JSON) #: list of names of sample types this kit can process
|
||||
cost_per_run = Column(FLOAT(2)) #: dollar amount for each full run of this kit
|
||||
mutable_cost = Column(FLOAT(2)) #: dollar amount that can change with number of columns (reagents, tips, etc)
|
||||
constant_cost = Column(FLOAT(2)) #: dollar amount that will remain constant (plates, man hours, etc)
|
||||
reagent_types = relationship("ReagentType", back_populates="kits", uselist=True, secondary=reagenttypes_kittypes) #: reagent types this kit contains
|
||||
reagent_types_id = Column(INTEGER, ForeignKey("_reagent_types.id", ondelete='SET NULL', use_alter=True, name="fk_KT_reagentstype_id")) #: joined reagent type id
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from . import Base
|
||||
from sqlalchemy import Column, String, TIMESTAMP, INTEGER, ForeignKey, Table
|
||||
from sqlalchemy import Column, String, TIMESTAMP, INTEGER, ForeignKey, Table, JSON, FLOAT
|
||||
from sqlalchemy.orm import relationship
|
||||
from datetime import datetime as dt
|
||||
|
||||
@@ -26,6 +26,8 @@ class BasicSubmission(Base):
|
||||
# Move this into custom types?
|
||||
reagents = relationship("Reagent", back_populates="submissions", secondary=reagents_submissions) #: relationship to reagents
|
||||
reagents_id = Column(String, ForeignKey("_reagents.id", ondelete="SET NULL", name="fk_BS_reagents_id")) #: id of used reagents
|
||||
extraction_info = Column(JSON) #: unstructured output from the extraction table logger.
|
||||
run_cost = Column(FLOAT(2))
|
||||
|
||||
__mapper_args__ = {
|
||||
"polymorphic_identity": "basic_submission",
|
||||
@@ -73,6 +75,7 @@ class BasicSubmission(Base):
|
||||
"Sample Count": self.sample_count,
|
||||
"Extraction Kit": ext_kit,
|
||||
"Technician": self.technician,
|
||||
"Cost": self.run_cost,
|
||||
}
|
||||
return output
|
||||
|
||||
@@ -99,10 +102,11 @@ class BasicSubmission(Base):
|
||||
except AttributeError:
|
||||
ext_kit = None
|
||||
# get extraction kit cost from nested kittype object
|
||||
try:
|
||||
cost = self.extraction_kit.cost_per_run
|
||||
except AttributeError:
|
||||
cost = None
|
||||
# depreciated as it will change kit cost overtime
|
||||
# try:
|
||||
# cost = self.extraction_kit.cost_per_run
|
||||
# except AttributeError:
|
||||
# cost = None
|
||||
output = {
|
||||
"id": self.id,
|
||||
"Plate Number": self.rsl_plate_num,
|
||||
@@ -112,7 +116,7 @@ class BasicSubmission(Base):
|
||||
"Submitting Lab": sub_lab,
|
||||
"Sample Count": self.sample_count,
|
||||
"Extraction Kit": ext_kit,
|
||||
"Cost": cost
|
||||
"Cost": self.run_cost
|
||||
}
|
||||
return output
|
||||
|
||||
|
||||
Reference in New Issue
Block a user