From 70b339b93e386eb73719ae6bb96cce19a4265686 Mon Sep 17 00:00:00 2001 From: Pritimay Sarkar Date: Fri, 25 Aug 2023 13:31:28 +0530 Subject: [PATCH] take only test collection data --- .../python/functions/consolidation.py | 27 +++--------- scripts/consolidated_data.py | 44 ++++++++++--------- 2 files changed, 28 insertions(+), 43 deletions(-) diff --git a/cloud-functions/python/functions/consolidation.py b/cloud-functions/python/functions/consolidation.py index 48f6557..195cb51 100644 --- a/cloud-functions/python/functions/consolidation.py +++ b/cloud-functions/python/functions/consolidation.py @@ -56,32 +56,17 @@ def consolidation(request): db = firestore.client() - patient_collection = db.collection("patientData") test_collection = db.collection("testData") - query = test_collection - patient_docs = query.stream() - data = [] - for patient_doc in patient_docs: - patient_data = patient_doc.to_dict() - patient_id = patient_data["_id"] - test_docs = test_collection.where("_id", "==", patient_id).stream() - - for test_doc in test_docs: - test_data = test_doc.to_dict() - - combined_data = {**patient_data, **test_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) + test_docs = test_collection.stream() + for test_doc in test_docs: + print(test_doc) + test_data = test_doc.to_dict() + data.append(test_data) df = pd.DataFrame(data) - df = df.drop_duplicates() output_filename = f'data_{datetime.today().strftime("%d_%m_%Y_%H_%M")}.xlsx' @@ -98,8 +83,6 @@ def consolidation(request): # firebase_admin.delete_app(firebase_admin.get_app()) - # return 'df size {}!'.format(df.size) - with open(output_path,'rb') as f: file_data = io.BytesIO(f.read()) diff --git a/scripts/consolidated_data.py b/scripts/consolidated_data.py index 0d00ef5..89133e9 100644 --- a/scripts/consolidated_data.py +++ b/scripts/consolidated_data.py @@ -29,37 +29,39 @@ if __name__ == "__main__": start_date = sys.argv[1] # '2023-01-12' #input("Please enter the start date (yyyy-mm-dd): ") end_date = sys.argv[2] #'2023-07-16' #input("Please enter the end date (yyyy-mm-dd): ") - query = test_collection.where(filter=FieldFilter("testTime", ">=", start_date)).where(filter=FieldFilter("testTime", "<", end_date)) - patient_docs = query.stream() + # patient_collection = db.collection("patientData") + test_collection = db.collection("testData") + + # query = test_collection + # patient_docs = query.stream() - # Prepare data to store in CSV data = [] - for patient_doc in patient_docs: - # print(patient_doc) - patient_data = patient_doc.to_dict() - patient_id = patient_data["_id"] + # for patient_doc in patient_docs: + # patient_data = patient_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() + # test_docs = test_collection.where("_id", "==", patient_id).stream() - for test_doc in test_docs: - # print(test_doc) - test_data = test_doc.to_dict() + # for test_doc in test_docs: + # test_data = test_doc.to_dict() - # Combine the data from both collections into a single dictionary - combined_data = {**patient_data, **test_data} + # 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] + # 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(combined_data) + + test_docs = test_collection.stream() + for test_doc in test_docs: + print(test_doc) + test_data = test_doc.to_dict() + data.append(test_data) # Convert the data to a DataFrame df = pd.DataFrame(data) - df = df.drop_duplicates() - print(df) + # print(df) print(df.size) # Save the DataFrame to a CSV file