From 439efbc1c907201335b9fe91d758494342f0b13f Mon Sep 17 00:00:00 2001 From: Pritimay Sarkar Date: Mon, 19 Feb 2024 12:04:46 +0530 Subject: [PATCH] fix append error and decimal regex --- .../python/functions/performance/main.py | 8 ++++---- scripts/device_accuracy.py | 20 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/cloud-functions/python/functions/performance/main.py b/cloud-functions/python/functions/performance/main.py index 8f88cf9..a2d5fbc 100644 --- a/cloud-functions/python/functions/performance/main.py +++ b/cloud-functions/python/functions/performance/main.py @@ -184,16 +184,16 @@ def performance(request): def extract_numbers(s): if "HB" in s: - match = re.search(r'-(\d+)$', s) + match = re.search(r'-([\d.]+)$', s) else: - match = re.search(r'-(\d+)', s) or re.search(r'(\d+)', s) + match = re.search(r'-([\d.]+)', s) or re.search(r'([\d.]+)', s) if match: - return int(match.group(1)) + return float(match.group(1)) else: return None - df["concentration"] = df['name'].apply(extract_numbers) + df["concentration"] = df['name'].apply(extract_numbers) df['absorbance'] = df.apply(lambda row: row['led1Average'] if row['solution'] == 'Tartrazine' else row['led3Average'], axis=1) df_precision_acc = df[["deviceId", "solution", "concentration", "led1Average", "led3Average", "absorbance"]].groupby(["deviceId", "solution", "concentration"]).describe()["absorbance"][["count", "min", "max", "mean"]] diff --git a/scripts/device_accuracy.py b/scripts/device_accuracy.py index eb8a972..93ccaa0 100644 --- a/scripts/device_accuracy.py +++ b/scripts/device_accuracy.py @@ -74,29 +74,29 @@ df_reference_device = pd.DataFrame(denovix_reference_values).T df_reference_device.index.name = 'Solution' df_reference_device.columns.name = 'Wavelength' -df = pd.read_excel(curdir + path_delim + "data" + path_delim + "data_06_12_2023_12_47.xlsx", sheet_name="data") +df = pd.read_excel(curdir + path_delim + "data" + path_delim + "data_19_02_2024_05_58.xlsx", sheet_name="data") if not df.empty: - conditions = [df['name'].str.contains('Tar', case=False, na=False), - df['name'].str.contains('KM', case=False, na=False), + conditions = [df['name'].str.contains('Tartrazine', case=False, na=False), + df['name'].str.contains('Acid Red', case=False, na=False), df['name'].str.contains('HB', case=False, na=False)] - choices = ['Tartrazine', 'KMnO4', "HB"] + choices = ['Tartrazine', 'Acid Red', "HB"] df['solution'] = np.select(conditions, choices, default=None) def extract_numbers(s): if "HB" in s: - match = re.search(r'-(\d+)$', s) + match = re.search(r'-([\d.]+)$', s) else: - match = re.search(r'-(\d+)', s) or re.search(r'(\d+)', s) + match = re.search(r'-([\d.]+)', s) or re.search(r'([\d.]+)', s) if match: - return int(match.group(1)) + return float(match.group(1)) else: return None - df["concentration"] = df['name'].apply(extract_numbers) + df["concentration"] = df['name'].apply(extract_numbers) df['absorbance'] = df.apply(lambda row: row['led2Average'] if row['solution'] == 'Tartrazine' else row['led1Average'], axis=1) df_precision_acc = df[["deviceId", "solution", "concentration", "led1Average", "led2Average", "absorbance"]].groupby(["deviceId", "solution", "concentration"]).describe()["absorbance"][["count", "min", "max", "mean"]] @@ -195,7 +195,7 @@ if not df.empty: fig, ax = plt.subplots() - filtered_df = df[df['solution'].isin(['KMnO4', 'Tartrazine', 'HB'])] + filtered_df = df[df['solution'].isin(['Acid Red', 'Tartrazine', 'HB'])] for solution in filtered_df['solution'].unique(): if pd.notna(solution): @@ -224,7 +224,7 @@ if not df.empty: wks1.write(row, 3, str(r_value**2)) # Add the linear fit results to the new DataFrame - df_linearfit_results = df_linearfit_results.append({'Solution': solution, 'Slope': slope, 'Intercept': intercept, 'R^2': r_value**2}, ignore_index=True) + df_linearfit_results = df_linearfit_results._append({'Solution': solution, 'Slope': slope, 'Intercept': intercept, 'R^2': r_value**2}, ignore_index=True) row += 1