From df30c933649bc5f58d51827ef0e41b741a41a974 Mon Sep 17 00:00:00 2001 From: Landon Wark Date: Thu, 18 May 2023 12:27:45 -0500 Subject: [PATCH] Added details tab to cost report. --- CHANGELOG.md | 4 ++++ TODO.md | 4 ++-- src/submissions/backend/excel/reports.py | 6 ++++-- src/submissions/frontend/main_window_functions.py | 11 ++++++----- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 866c245..cee6c98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 202305.03 + +- Added a detailed tab to the cost report. + ## 202305.02 - Added rudimentary barcode printing. diff --git a/TODO.md b/TODO.md index bdd2875..263355c 100644 --- a/TODO.md +++ b/TODO.md @@ -1,3 +1,3 @@ -- [ ] Create a method for commenting submissions. -- [ ] Create barcode generator, because of reasons that may or may not exist. +- [x] Create a method for commenting submissions. +- [x] Create barcode generator, because of reasons that may or may not exist. - [x] Move bulk of functions from frontend.__init__ to frontend.functions as __init__ is getting bloated. \ No newline at end of file diff --git a/src/submissions/backend/excel/reports.py b/src/submissions/backend/excel/reports.py index ea9dab0..68e2e5f 100644 --- a/src/submissions/backend/excel/reports.py +++ b/src/submissions/backend/excel/reports.py @@ -39,9 +39,11 @@ def make_report_xlsx(records:list[dict]) -> DataFrame: 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": 'Kit Count'}) + df2 = df2.rename(columns={"Extraction Kit": 'Plate Count'}) logger.debug(f"Output daftaframe for xlsx: {df2.columns}") - return df2 + df = df.drop('id', axis=1) + df = df.sort_values(['Submitting Lab', "Submitted Date"]) + return df, df2 def make_report_html(df:DataFrame, start_date:date, end_date:date) -> str: diff --git a/src/submissions/frontend/main_window_functions.py b/src/submissions/frontend/main_window_functions.py index 1a094f1..d980616 100644 --- a/src/submissions/frontend/main_window_functions.py +++ b/src/submissions/frontend/main_window_functions.py @@ -293,8 +293,8 @@ def generate_report_function(obj:QMainWindow) -> QMainWindow: # convert each object to dict records = [item.report_dict() for item in subs] # make dataframe from record dictionaries - df = make_report_xlsx(records=records) - html = make_report_html(df=df, start_date=info['start_date'], end_date=info['end_date']) + 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']) # setup filedialog to handle save location of report home_dir = Path(obj.ctx["directory_path"]).joinpath(f"Submissions_Report_{info['start_date']}-{info['end_date']}.pdf").resolve().__str__() fname = Path(QFileDialog.getSaveFileName(obj, "Save File", home_dir, filter=".pdf")[0]) @@ -302,10 +302,11 @@ def generate_report_function(obj:QMainWindow) -> QMainWindow: with open(fname, "w+b") as f: pisa.CreatePDF(html, dest=f) writer = pd.ExcelWriter(fname.with_suffix(".xlsx"), engine='openpyxl') - df.to_excel(writer, sheet_name="Report") + summary_df.to_excel(writer, sheet_name="Report") + detailed_df.to_excel(writer, sheet_name="Details", index=False) worksheet = writer.sheets['Report'] - for idx, col in enumerate(df): # loop through all columns - series = df[col] + for idx, col in enumerate(summary_df): # loop through all columns + series = summary_df[col] max_len = max(( series.astype(str).map(len).max(), # len of largest item len(str(series.name)) # len of column name/header