Various bug fixes.
This commit is contained in:
@@ -35,7 +35,7 @@ class SheetParser(object):
|
||||
Args:
|
||||
filepath (Path | None, optional): file path to excel sheet. Defaults to None.
|
||||
"""
|
||||
logger.debug(f"\n\nParsing {filepath.__str__()}\n\n")
|
||||
logger.info(f"\n\nParsing {filepath.__str__()}\n\n")
|
||||
match filepath:
|
||||
case Path():
|
||||
self.filepath = filepath
|
||||
@@ -651,6 +651,15 @@ class PCRParser(object):
|
||||
info_map = self.submission_obj.get_submission_type().sample_map['pcr_general_info']
|
||||
sheet = self.xl[info_map['sheet']]
|
||||
iter_rows = sheet.iter_rows(min_row=info_map['start_row'], max_row=info_map['end_row'])
|
||||
pcr = {row[0].value.lower().replace(' ', '_'): row[1].value for row in iter_rows}
|
||||
pcr = {}
|
||||
for row in iter_rows:
|
||||
try:
|
||||
key = row[0].value.lower().replace(' ', '_')
|
||||
except AttributeError as e:
|
||||
logger.error(f"No key: {row[0].value} due to {e}")
|
||||
continue
|
||||
value = row[1].value or ""
|
||||
pcr[key] = value
|
||||
pcr['imported_by'] = getuser()
|
||||
# logger.debug(f"PCR: {pformat(pcr)}")
|
||||
return pcr
|
||||
|
||||
@@ -23,13 +23,13 @@ def make_report_xlsx(records:list[dict]) -> Tuple[DataFrame, DataFrame]:
|
||||
"""
|
||||
df = DataFrame.from_records(records)
|
||||
# put submissions with the same lab together
|
||||
df = df.sort_values("Submitting Lab")
|
||||
df = df.sort_values("submitting_lab")
|
||||
# aggregate cost and sample count columns
|
||||
df2 = df.groupby(["Submitting Lab", "Extraction Kit"]).agg({'Extraction Kit':'count', 'Cost': 'sum', 'Sample Count':'sum'})
|
||||
df2 = df2.rename(columns={"Extraction Kit": 'Run Count'})
|
||||
df2 = df.groupby(["submitting_lab", "extraction_kit"]).agg({'extraction_kit':'count', 'cost': 'sum', 'sample_count':'sum'})
|
||||
df2 = df2.rename(columns={"extraction_kit": 'run_count'})
|
||||
# logger.debug(f"Output daftaframe for xlsx: {df2.columns}")
|
||||
df = df.drop('id', axis=1)
|
||||
df = df.sort_values(['Submitting Lab', "Submitted Date"])
|
||||
df = df.sort_values(['submitting_lab', "submitted_date"])
|
||||
return df, df2
|
||||
|
||||
def make_report_html(df:DataFrame, start_date:date, end_date:date) -> str:
|
||||
|
||||
@@ -85,6 +85,7 @@ class SheetWriter(object):
|
||||
class InfoWriter(object):
|
||||
|
||||
def __init__(self, xl: Workbook, submission_type: SubmissionType | str, info_dict: dict, sub_object:BasicSubmission|None=None):
|
||||
logger.debug(f"Info_dict coming into InfoWriter: {pformat(info_dict)}")
|
||||
if isinstance(submission_type, str):
|
||||
submission_type = SubmissionType.query(name=submission_type)
|
||||
if sub_object is None:
|
||||
@@ -110,10 +111,15 @@ class InfoWriter(object):
|
||||
dicto['value'] = v
|
||||
if len(dicto) > 0:
|
||||
output[k] = dicto
|
||||
# logger.debug(f"Reconciled info: {pformat(output)}")
|
||||
return output
|
||||
|
||||
def write_info(self):
|
||||
for k, v in self.info.items():
|
||||
# NOTE: merge all comments to fit in single cell.
|
||||
if k == "comment" and isinstance(v['value'], list):
|
||||
json_join = [item['text'] for item in v['value'] if 'text' in item.keys()]
|
||||
v['value'] = "\n".join(json_join)
|
||||
try:
|
||||
locations = v['locations']
|
||||
except KeyError:
|
||||
@@ -183,6 +189,7 @@ class SampleWriter(object):
|
||||
output = []
|
||||
multiples = ['row', 'column', 'assoc_id', 'submission_rank']
|
||||
for sample in sample_list:
|
||||
# logger.debug(f"Writing sample: {sample}")
|
||||
for assoc in zip(sample['row'], sample['column'], sample['submission_rank']):
|
||||
new = dict(row=assoc[0], column=assoc[1], submission_rank=assoc[2])
|
||||
for k, v in sample.items():
|
||||
|
||||
Reference in New Issue
Block a user