Added details tab to cost report.

This commit is contained in:
Landon Wark
2023-05-18 12:27:45 -05:00
parent 7f0e13168a
commit df30c93364
4 changed files with 16 additions and 9 deletions

View File

@@ -1,3 +1,7 @@
## 202305.03
- Added a detailed tab to the cost report.
## 202305.02 ## 202305.02
- Added rudimentary barcode printing. - Added rudimentary barcode printing.

View File

@@ -1,3 +1,3 @@
- [ ] Create a method for commenting submissions. - [x] Create a method for commenting submissions.
- [ ] Create barcode generator, because of reasons that may or may not exist. - [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. - [x] Move bulk of functions from frontend.__init__ to frontend.functions as __init__ is getting bloated.

View File

@@ -39,9 +39,11 @@ def make_report_xlsx(records:list[dict]) -> DataFrame:
df = df.sort_values("Submitting Lab") df = df.sort_values("Submitting Lab")
# aggregate cost and sample count columns # aggregate cost and sample count columns
df2 = df.groupby(["Submitting Lab", "Extraction Kit"]).agg({'Extraction Kit':'count', 'Cost': 'sum', 'Sample Count':'sum'}) 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}") 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: def make_report_html(df:DataFrame, start_date:date, end_date:date) -> str:

View File

@@ -293,8 +293,8 @@ def generate_report_function(obj:QMainWindow) -> QMainWindow:
# convert each object to dict # convert each object to dict
records = [item.report_dict() for item in subs] records = [item.report_dict() for item in subs]
# make dataframe from record dictionaries # make dataframe from record dictionaries
df = make_report_xlsx(records=records) detailed_df, summary_df = make_report_xlsx(records=records)
html = make_report_html(df=df, start_date=info['start_date'], end_date=info['end_date']) 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 # 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__() 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]) 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: with open(fname, "w+b") as f:
pisa.CreatePDF(html, dest=f) pisa.CreatePDF(html, dest=f)
writer = pd.ExcelWriter(fname.with_suffix(".xlsx"), engine='openpyxl') 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'] worksheet = writer.sheets['Report']
for idx, col in enumerate(df): # loop through all columns for idx, col in enumerate(summary_df): # loop through all columns
series = df[col] series = summary_df[col]
max_len = max(( max_len = max((
series.astype(str).map(len).max(), # len of largest item series.astype(str).map(len).max(), # len of largest item
len(str(series.name)) # len of column name/header len(str(series.name)) # len of column name/header