57 lines
2.0 KiB
Python
57 lines
2.0 KiB
Python
import pandas as pd
|
|
import numpy as np
|
|
import os
|
|
import re
|
|
import xlsxwriter
|
|
from datetime import datetime
|
|
|
|
|
|
curdir = os.getcwd()
|
|
path_delim = '/'
|
|
|
|
df = pd.read_excel(curdir + path_delim + "data" + path_delim + "data_03_12_2023_11_25.xlsx", sheet_name="Sheet1")
|
|
|
|
texts_to_check = ['Tar', 'KM']
|
|
df['solution'] = df['name'].str.extract(f"({'|'.join(texts_to_check)})", flags=re.IGNORECASE)
|
|
df['solution'] = df['solution'].replace({'Tar': 'Tartrazine', 'KM': 'KMnO4'}, regex=True)
|
|
|
|
def extract_numbers(s):
|
|
match = re.match(r'\d+', s)
|
|
if match:
|
|
return int(match.group())
|
|
else:
|
|
return None
|
|
|
|
df["concentration"] = df['name'].apply(extract_numbers)
|
|
df['absorbance'] = df.apply(lambda row: row['led2Average'] if row['solution'] == 'Tartrazine' else row['led1Average'], axis=1)
|
|
output_filename = f'precision_{datetime.today().strftime("%d_%m_%Y_%H_%M")}.xlsx'
|
|
writer = pd.ExcelWriter(output_filename, engine = 'xlsxwriter')
|
|
|
|
df_precision = df[["deviceId", "solution", "concentration", "led1Average", "led2Average", "absorbance"]].groupby(["deviceId", "solution", "concentration"]).describe()["absorbance"][["count", "min", "max"]]
|
|
# df_precision = df_precision.reset_index(drop=True)
|
|
df_precision['precision'] = df_precision['max'] - df_precision['min']
|
|
threshold = 0.02
|
|
df_precision['result'] = ['Fail' if diff > threshold else 'Pass' for diff in df_precision['precision']]
|
|
|
|
device_results = {}
|
|
for index, group_df in df_precision.groupby(level=[0, 1, 2]):
|
|
soln = index[1]
|
|
concen = index[2]
|
|
result_values = group_df['result'].values
|
|
|
|
if index[0] not in device_results:
|
|
device_results[index[0]] = "Pass"
|
|
else:
|
|
result = 'Fail' if 'Fail' in result_values else 'Pass'
|
|
if result == 'Fail':
|
|
device_results[index[0]] = 'Fail'
|
|
|
|
print(device_results)
|
|
df_device_results = pd.DataFrame(list(device_results.items()), columns=['Device', 'Result'])
|
|
|
|
|
|
df.to_excel(writer, sheet_name="in")
|
|
df_precision.to_excel(writer, sheet_name="precision")
|
|
df_device_results.to_excel(writer, sheet_name="device_results")
|
|
|
|
writer.close() |