take only test collection data
This commit is contained in:
@@ -56,32 +56,17 @@ def consolidation(request):
|
|||||||
|
|
||||||
db = firestore.client()
|
db = firestore.client()
|
||||||
|
|
||||||
patient_collection = db.collection("patientData")
|
|
||||||
test_collection = db.collection("testData")
|
test_collection = db.collection("testData")
|
||||||
|
|
||||||
query = test_collection
|
|
||||||
patient_docs = query.stream()
|
|
||||||
|
|
||||||
data = []
|
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()
|
test_docs = test_collection.stream()
|
||||||
|
for test_doc in test_docs:
|
||||||
for test_doc in test_docs:
|
print(test_doc)
|
||||||
test_data = test_doc.to_dict()
|
test_data = test_doc.to_dict()
|
||||||
|
data.append(test_data)
|
||||||
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)
|
|
||||||
|
|
||||||
df = pd.DataFrame(data)
|
df = pd.DataFrame(data)
|
||||||
df = df.drop_duplicates()
|
|
||||||
|
|
||||||
output_filename = f'data_{datetime.today().strftime("%d_%m_%Y_%H_%M")}.xlsx'
|
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())
|
# firebase_admin.delete_app(firebase_admin.get_app())
|
||||||
|
|
||||||
# return 'df size {}!'.format(df.size)
|
|
||||||
|
|
||||||
with open(output_path,'rb') as f:
|
with open(output_path,'rb') as f:
|
||||||
file_data = io.BytesIO(f.read())
|
file_data = io.BytesIO(f.read())
|
||||||
|
|
||||||
|
|||||||
@@ -29,37 +29,39 @@ if __name__ == "__main__":
|
|||||||
start_date = sys.argv[1] # '2023-01-12' #input("Please enter the start date (yyyy-mm-dd): ")
|
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): ")
|
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_collection = db.collection("patientData")
|
||||||
patient_docs = query.stream()
|
test_collection = db.collection("testData")
|
||||||
|
|
||||||
|
# query = test_collection
|
||||||
|
# patient_docs = query.stream()
|
||||||
|
|
||||||
# Prepare data to store in CSV
|
|
||||||
data = []
|
data = []
|
||||||
for patient_doc in patient_docs:
|
# for patient_doc in patient_docs:
|
||||||
# print(patient_doc)
|
# patient_data = patient_doc.to_dict()
|
||||||
patient_data = patient_doc.to_dict()
|
# patient_id = patient_data["_id"]
|
||||||
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:
|
# for test_doc in test_docs:
|
||||||
# print(test_doc)
|
# test_data = test_doc.to_dict()
|
||||||
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():
|
||||||
for key, value in combined_data.items():
|
# if value == "" and key in patient_data:
|
||||||
if value == "" and key in patient_data:
|
# combined_data[key] = patient_data[key]
|
||||||
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
|
# Convert the data to a DataFrame
|
||||||
df = pd.DataFrame(data)
|
df = pd.DataFrame(data)
|
||||||
df = df.drop_duplicates()
|
# print(df)
|
||||||
print(df)
|
|
||||||
print(df.size)
|
print(df.size)
|
||||||
|
|
||||||
# Save the DataFrame to a CSV file
|
# Save the DataFrame to a CSV file
|
||||||
|
|||||||
Reference in New Issue
Block a user