diff --git a/scripts/device_qc_report.py b/scripts/device_qc_report.py index 5dd4736..e1c354f 100644 --- a/scripts/device_qc_report.py +++ b/scripts/device_qc_report.py @@ -11,13 +11,9 @@ precision_tolerance = 0.009 accuracy_tolerance = 0.02 def perform_calculations(curdir, path_delim, report_file): - # print(curdir + path_delim + "hemocube_qc_09_08_2023_data.xlsx") df = pd.read_excel(curdir + path_delim + "hemocube_qc_09_08_2023_data.xlsx", sheet_name="qc_data") df_ref = pd.read_excel(curdir + path_delim + "hemocube_qc_09_08_2023_data.xlsx", sheet_name="reference_values") - # df_ref['device - con'] = "" - # for idx, row in df_ref.iterrows(): - # df_ref["device - con"][idx] = str(row["deviceId"]) + ", " + row["sol"] + ", " + row["wavelength"] print(df_ref) writer = pd.ExcelWriter(report_file, engine = 'xlsxwriter') @@ -27,47 +23,40 @@ def perform_calculations(curdir, path_delim, report_file): # duplicate columns df["device"] = df["deviceId"] - df["device - con"] = "" + df["identifier"] = "" for idx, row in df.iterrows(): - df['device - con'][idx] = row["deviceId"] + ", " + row["sol"] + ", " + row["wavelength"] + df['identifier'][idx] = row["deviceId"] + ", " + row["sol"] + ", " + row["wavelength"] - # print(df) df_max = df.groupby(['deviceId', "sol"]).max() - df_max['device - con'] = "" - # print(df_max.iloc[1]) + df_max['identifier'] = "" df_min = df.groupby(['deviceId', "sol"]).min() - df_min['device - con'] = "" + df_min['identifier'] = "" for group, row in df_max.iterrows(): - df_max["device - con"][group] = group[0] + ", " + group[1] + ", " + row["wavelength"] + df_max["identifier"][group] = group[0] + ", " + group[1] + ", " + row["wavelength"] df_max.to_excel(writer, sheet_name="max", index=False) for group, row in df_min.iterrows(): - df_min["device - con"][group] = group[0] + ", " + group[1] + ", " + row["wavelength"] + df_min["identifier"][group] = group[0] + ", " + group[1] + ", " + row["wavelength"] - # TODO: combine 427 mean and 555 mean using df.groupby(['device - con'])[["Abs 427", "Abs555"]].mean() - df_427nm_mean = df.groupby(['device - con'])["Abs 427"].mean().to_frame() + # TODO: combine 427 mean and 555 mean using df.groupby(['identifier'])[["Abs 427", "Abs555"]].mean() + df_427nm_mean = df.groupby(['identifier'])["Abs 427"].mean().to_frame() df_427nm_mean.rename(columns={'Abs 427': "Abs427_mean"}, inplace = True) - df_555nm_mean = df.groupby(['device - con'])["Abs555"].mean().to_frame() + df_555nm_mean = df.groupby(['identifier'])["Abs555"].mean().to_frame() df_555nm_mean.rename(columns={'Abs555': "Abs555_mean"}, inplace = True) # df_mean = df.copy() - df_mean = df_427nm_mean.merge(df_555nm_mean, on="device - con") + df_mean = df_427nm_mean.merge(df_555nm_mean, on="identifier") df_describe = df.groupby(['deviceId', "sol"]).describe() - # print(df.groupby(['deviceId', "sol"]).describe()) df_describe.to_excel(writer, sheet_name="describe") - # for group, row in df_describe.iterrows(): - # df_mean["Abs555_mean"] = row["Abs 427"]["mean"] - # print(df_mean) - - df_max_min = df_max.merge(df_min, on="device - con") - df_max_min_mean = df_max_min.merge(df_mean, on="device - con") - df_max_min_mean_ref = df_max_min_mean.merge(df_ref, on="device - con") + df_max_min = df_max.merge(df_min, on="identifier") + df_max_min_mean = df_max_min.merge(df_mean, on="identifier") + df_max_min_mean_ref = df_max_min_mean.merge(df_ref, on="identifier") df_min.to_excel(writer, sheet_name="min", index=False) df_max_min_mean_ref.to_excel(writer, sheet_name="df_max_min_mean_ref", index=False) @@ -79,12 +68,7 @@ def perform_calculations(curdir, path_delim, report_file): df_result["accuracy_555nm"] = df_max_min_mean_ref["ref_device_abs"] - df_max_min_mean_ref["Abs555_mean"] df_result = df_result.drop(["Abs 427_x", "Abs555_x", "wavelength_x", "Abs 427_y", "Abs555_y", "wavelength_y", "device_y"], axis=1) - df_result = df_result.groupby('device_x')[['device_x', "device - con", "precision_427nm", "precision_555nm", "accuracy_427nm", "accuracy_555nm"]].apply(lambda x: x) - # print(df_result) - - # for idx, row in df_result.iterrows(): - # print(idx, row) - # df_result["precision_427nm"][1] = df_max.loc["Abs 427"][1] + df_min["Abs 427"][1] + df_result = df_result.groupby('device_x')[['device_x', "identifier", "precision_427nm", "precision_555nm", "accuracy_427nm", "accuracy_555nm"]].apply(lambda x: x) df_result.to_excel(writer, sheet_name="precision", index=False) workbook = writer.book