refactor for
- test date - sorting - excel save
This commit is contained in:
@@ -11,10 +11,10 @@ import platform
|
||||
if __name__ == "__main__":
|
||||
|
||||
path_delim = ""
|
||||
if platform.system() == 'Darwin':
|
||||
path_delim = '/'
|
||||
else:
|
||||
if platform.system() == 'Windows':
|
||||
path_delim = '\\'
|
||||
else:
|
||||
path_delim = '/'
|
||||
|
||||
key_file_path = os.getcwd() + path_delim + "keys" + path_delim + "hpos-af3cc-firebase-adminsdk-n261k-2bfd463ec0.json"
|
||||
cred = credentials.Certificate(key_file_path) # Replace with your own service account key path
|
||||
@@ -35,7 +35,7 @@ if __name__ == "__main__":
|
||||
# Prepare data to store in CSV
|
||||
data = []
|
||||
for patient_doc in patient_docs:
|
||||
print(patient_doc)
|
||||
# print(patient_doc)
|
||||
patient_data = patient_doc.to_dict()
|
||||
patient_id = patient_data["_id"]
|
||||
|
||||
@@ -43,7 +43,7 @@ if __name__ == "__main__":
|
||||
test_docs = test_collection.where("_id", "==", patient_id).stream()
|
||||
|
||||
for test_doc in test_docs:
|
||||
print(test_doc)
|
||||
# print(test_doc)
|
||||
test_data = test_doc.to_dict()
|
||||
|
||||
# Combine the data from both collections into a single dictionary
|
||||
@@ -62,12 +62,17 @@ if __name__ == "__main__":
|
||||
print(df.size)
|
||||
|
||||
# Save the DataFrame to a CSV file
|
||||
output_filename = "data.csv"
|
||||
output_filename = "data.xlsx"
|
||||
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)
|
||||
writer = pd.ExcelWriter(output_path, engine = 'openpyxl')
|
||||
df = df[(df['testTime'] > start_date) & (df['testTime'] <= end_date)]
|
||||
df = df.sort_values(by=['testTime'], ascending=False)
|
||||
df = df.drop(['resultData', "reportUploadTime", "userImageURL", "testType", "birthYear", "testStatus", "reportPath", "createdBy", "csvPath", "result", "mobileId", "resultRatio", "localFlag", "led2", "led1"], axis=1)
|
||||
df.to_excel(writer, sheet_name = 'data', index=False)
|
||||
writer.close()
|
||||
|
||||
print(f"Data saved to '{output_path}'")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user