combine user test
This commit is contained in:
55
scripts/combine_users_test.py
Normal file
55
scripts/combine_users_test.py
Normal file
@@ -0,0 +1,55 @@
|
||||
import os
|
||||
import firebase_admin
|
||||
from firebase_admin import credentials
|
||||
from firebase_admin import firestore
|
||||
from google.cloud.firestore_v1.base_query import FieldFilter
|
||||
import pandas as pd
|
||||
import datetime
|
||||
import sys
|
||||
|
||||
cred = credentials.Certificate(os.getcwd() + '/' + 'keys/hpos-prod-firebase-adminsdk.json')
|
||||
firebase_admin.initialize_app(cred)
|
||||
|
||||
db = firestore.client()
|
||||
|
||||
patient_collection = db.collection("patientData")
|
||||
test_collection = db.collection("testData")
|
||||
start_date = sys.argv[1] # '2023-01-12'
|
||||
end_date = sys.argv[2] #'2023-07-16'
|
||||
|
||||
query = patient_collection.where(filter=FieldFilter("createdAt", ">=", start_date)).where(filter=FieldFilter("createdAt", "<", end_date))
|
||||
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)
|
||||
data.append(patient_data)
|
||||
|
||||
df = pd.DataFrame(data)
|
||||
print(df)
|
||||
print(df.size)
|
||||
|
||||
output_filename = "users_test_data.csv"
|
||||
df.to_csv(output_filename, index=False)
|
||||
|
||||
downloads_dir = os.path.join(os.path.expanduser("~"), "Downloads")
|
||||
output_path = os.path.join(downloads_dir, output_filename)
|
||||
df.to_csv(output_path, index=False)
|
||||
|
||||
print(f"Data saved to '{output_path}'")
|
||||
|
||||
firebase_admin.delete_app(firebase_admin.get_app())
|
||||
Reference in New Issue
Block a user