From b0292aa75710153b1d4dc0f312835b471f5d75ed Mon Sep 17 00:00:00 2001 From: Pritimay Sarkar Date: Sun, 10 Dec 2023 13:44:34 +0530 Subject: [PATCH] add HB in fun --- .../python/functions/performance/main.py | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/cloud-functions/python/functions/performance/main.py b/cloud-functions/python/functions/performance/main.py index 298a435..e528f14 100644 --- a/cloud-functions/python/functions/performance/main.py +++ b/cloud-functions/python/functions/performance/main.py @@ -135,6 +135,13 @@ def performance(request): "1450": 0.447634285, "1550": 0.478220085, }, + "HB": { + "2": 0.187191676, + "4": 0.187191676, + "5": 0.187191676, + "6": 0.187191676, + "8": 0.077846397, + }, } df_reference_device = pd.DataFrame(denovix_reference_values).T df_reference_device.index.name = 'Solution' @@ -142,14 +149,19 @@ def performance(request): if not df.empty: conditions = [df['name'].str.contains('Tar', case=False, na=False), - df['name'].str.contains('KM', case=False, na=False)] + df['name'].str.contains('KM', case=False, na=False), + df['name'].str.contains('HB', case=False, na=False)] - choices = ['Tartrazine', 'KMnO4'] + choices = ['Tartrazine', 'KMnO4', "HB"] df['solution'] = np.select(conditions, choices, default=None) def extract_numbers(s): - match = re.search(r'-(\d+)', s) or re.search(r'(\d+)', s) + if "HB" in s: + match = re.search(r'-(\d+)$', s) + else: + match = re.search(r'-(\d+)', s) or re.search(r'(\d+)', s) + if match: return int(match.group(1)) else: @@ -250,7 +262,7 @@ def performance(request): fig, ax = plt.subplots() - filtered_df = df[df['solution'].isin(['KMnO4', 'Tartrazine'])] + filtered_df = df[df['solution'].isin(['KMnO4', 'Tartrazine', 'HB'])] for solution in filtered_df['solution'].unique(): if pd.notna(solution): @@ -270,8 +282,8 @@ def performance(request): ax.text(concentration_means.index[-1] + 5, np.polyval(coefficients, concentration_means.index[-1]), annotation_text, fontsize=10, verticalalignment='center') wks1.write(row, 0, solution) - wks1.write(row, 1, coefficients[0]) - wks1.write(row, 2, coefficients[1]) + wks1.write(row, 1, str(coefficients[0])) + wks1.write(row, 2, str(coefficients[1])) row += 1 @@ -299,7 +311,6 @@ def performance(request): writer.close() else: - # If df is empty, create an empty Excel file output_filename = f'/tmp/empty_excel_{datetime.today().strftime("%d_%m_%Y_%H_%M")}.xlsx' pd.DataFrame().to_excel(output_filename, engine='xlsxwriter', index=False)