add stats sheet in tests data
This commit is contained in:
@@ -6,15 +6,13 @@ from google.cloud.firestore_v1.base_query import FieldFilter
|
||||
import pandas as pd
|
||||
from datetime import datetime
|
||||
import sys
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# Initialize Firebase Admin SDK
|
||||
cred = credentials.Certificate(os.getcwd() + '/' + 'keys/hpos-prod-firebase-adminsdk.json') # Replace with your own service account key path
|
||||
firebase_admin.initialize_app(cred)
|
||||
|
||||
# Get a reference to the Firestore database
|
||||
db = firestore.client()
|
||||
|
||||
# Specify the collections
|
||||
patient_collection = db.collection("patientData")
|
||||
test_collection = db.collection("testData")
|
||||
start_date = sys.argv[1] # '2023-09-12' #input("Please enter the start date (yyyy-mm-dd): ")
|
||||
@@ -23,31 +21,11 @@ end_date = sys.argv[2] #'2023-07-16' #input("Please enter the end date (yyyy-mm-
|
||||
query = test_collection.where(filter=FieldFilter("testTime", ">=", start_date)).where(filter=FieldFilter("testTime", "<", end_date))
|
||||
docs = query.stream()
|
||||
|
||||
# Prepare data to store in CSV
|
||||
data = []
|
||||
for doc in docs:
|
||||
doc_data = doc.to_dict()
|
||||
# patient_id = patient_data["_id"]
|
||||
|
||||
# # Query the document from testData collection based on the common _id
|
||||
# test_docs = test_collection.where("_id", "==", patient_id).stream()
|
||||
|
||||
# for test_doc in test_docs:
|
||||
# print(test_doc)
|
||||
# test_data = test_doc.to_dict()
|
||||
|
||||
# # Combine the data from both collections into a single dictionary
|
||||
# combined_data = {**patient_data, **test_data}
|
||||
|
||||
# # Fill empty fields in test_data with corresponding values from patient_data
|
||||
# for key, value in combined_data.items():
|
||||
# if value == "" and key in patient_data:
|
||||
# combined_data[key] = patient_data[key]
|
||||
|
||||
# data.append(combined_data)
|
||||
data.append(doc_data)
|
||||
|
||||
# Convert the data to a DataFrame
|
||||
df = pd.DataFrame(data)
|
||||
print(df)
|
||||
print(df.size)
|
||||
@@ -56,10 +34,21 @@ df = df[["_id", "classificationResult", "calculatedRatio", "deviceId", "deviceRa
|
||||
# df = df.groupby(["classificationResult"]).describe()
|
||||
df_count = df.groupby(["classificationResult"]).describe()["calculatedRatio"]["count"]
|
||||
print(df.groupby(["classificationResult"]).describe()["calculatedRatio"]["count"])
|
||||
print(df.groupby(["deviceId"]).describe()["calculatedRatio"]["count"])
|
||||
print(df.groupby(["deviceSerialNumber"]).describe()["calculatedRatio"]["count"])
|
||||
# print(df.groupby(["kitSerial", "classificationResult"]).describe())
|
||||
|
||||
# df_device = df[df["deviceId"] == "HCV1003"]
|
||||
# df.plot(kind = 'scatter', x = 'testTime', y = 'led2Buffer')
|
||||
# plt.show()
|
||||
|
||||
# df[df["deviceId"] == "HCV2013"]['led2Sample'].plot.box()
|
||||
# plt.show()
|
||||
|
||||
print(df.groupby(["kitSerial"]).describe()["calculatedRatio"]["count"])
|
||||
|
||||
print("duplicates", len(df['_id']) - len(df['_id'].drop_duplicates()))
|
||||
|
||||
# Save the DataFrame to a CSV file
|
||||
output_filename = f'tests_{datetime.today().strftime("%d_%m_%Y_%H_%M")}.xlsx'
|
||||
|
||||
downloads_dir = os.path.join(os.path.expanduser("~"), "Downloads")
|
||||
@@ -67,10 +56,13 @@ output_path = os.path.join(downloads_dir, output_filename)
|
||||
writer = pd.ExcelWriter(output_path, engine = 'openpyxl')
|
||||
df.to_excel(writer, sheet_name = 'data', index=False)
|
||||
df_count.to_excel(writer, sheet_name = "count")
|
||||
df.groupby(["deviceId"]).describe().to_excel(writer, sheet_name = "stats")
|
||||
df.groupby(["kitSerial"]).describe()["calculatedRatio"]["count"].to_excel(writer, sheet_name = "kit_count")
|
||||
df.groupby(["kitSerial", "classificationResult"]).describe()["calculatedRatio"]["count"].to_excel(writer, sheet_name = "kit_class")
|
||||
df.groupby(["deviceId", "classificationResult"]).describe()["calculatedRatio"]["count"].to_excel(writer, sheet_name = "device_class")
|
||||
writer.close()
|
||||
|
||||
print(f"Data saved to '{output_path}'")
|
||||
|
||||
# Close the Firebase Admin SDK
|
||||
firebase_admin.delete_app(firebase_admin.get_app())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user