take only test collection data

This commit is contained in:
Pritimay Sarkar
2023-08-25 13:31:28 +05:30
parent 9f3689f22e
commit 70b339b93e
2 changed files with 28 additions and 43 deletions

View File

@@ -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())

View File

@@ -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