Diego Marroquin commited on
Commit ·
204f8b8
1
Parent(s): 4d7222f
Modified main.py
Browse files
main.py
CHANGED
|
@@ -300,10 +300,10 @@ def nuc_monitor(rte_data, mongo_json_data, usr_start_date, usr_end_date, photo_d
|
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
-
mongo_data = mongo_json_data.json()
|
| 304 |
|
| 305 |
-
|
| 306 |
-
file_path = "/Users/diegomarroquin/HayaEnergy/Nucmonitor_MVP/NucPy_v0.2/testing/test_data3.txt"
|
| 307 |
|
| 308 |
# Open the file in write mode
|
| 309 |
with open(file_path, 'w') as file:
|
|
@@ -322,9 +322,9 @@ def nuc_monitor(rte_data, mongo_json_data, usr_start_date, usr_end_date, photo_d
|
|
| 322 |
# Drop the original column
|
| 323 |
mongo_df_result.drop(columns=['generation_unavailabilities'], inplace=True)
|
| 324 |
mongo_df_columns = mongo_df_result.columns
|
| 325 |
-
print(mongo_df_columns)
|
| 326 |
-
print(mongo_df_result)
|
| 327 |
-
print(mongo_df_result["values"])
|
| 328 |
# # Unpack values column
|
| 329 |
# # mongo_df2 = mongo_df_result.copy().apply(unpack_values, axis=1)
|
| 330 |
# mongo_df_values_unpacked = pd.json_normalize(mongo_df_result['values'])
|
|
@@ -342,8 +342,8 @@ def nuc_monitor(rte_data, mongo_json_data, usr_start_date, usr_end_date, photo_d
|
|
| 342 |
mongo_df_result['end_date'] = mongo_df_result['values'].apply(lambda x: x[0]['end_date'])
|
| 343 |
mongo_df_result['available_capacity'] = mongo_df_result['values'].apply(lambda x: x[0]['available_capacity'])
|
| 344 |
mongo_df_result['unavailable_capacity'] = mongo_df_result['values'].apply(lambda x: x[0]['unavailable_capacity'])
|
| 345 |
-
print(mongo_df_result)
|
| 346 |
-
print(mongo_df_result.columns)
|
| 347 |
# Drop the original 'values' column
|
| 348 |
mongo_df_result.drop('values', axis=1, inplace=True)
|
| 349 |
mongo_df2 = mongo_df_result
|
|
@@ -362,7 +362,7 @@ def nuc_monitor(rte_data, mongo_json_data, usr_start_date, usr_end_date, photo_d
|
|
| 362 |
|
| 363 |
# Merge dataframes
|
| 364 |
column_order = mongo_unavs.columns
|
| 365 |
-
print(column_order)
|
| 366 |
merged_df = pd.concat([mongo_unavs[column_order], rte_unavs[column_order]], ignore_index=True)
|
| 367 |
|
| 368 |
# --------------------------- HERE IS THE CHANGE TO GET ONLY ACTIVE OR ACTIVE AND INACTIVE --------------------------- #
|
|
@@ -417,12 +417,12 @@ def nuc_monitor(rte_data, mongo_json_data, usr_start_date, usr_end_date, photo_d
|
|
| 417 |
# Turn df into dict for json processing
|
| 418 |
filtered_unavs = filtered_df3.copy().to_dict(orient='records')
|
| 419 |
|
| 420 |
-
file_path = "/Users/diegomarroquin/HayaEnergy/Nucmonitor_MVP/NucPy_v0.2/testing/test_data4.txt"
|
| 421 |
|
| 422 |
-
# Open the file in write mode
|
| 423 |
-
with open(file_path, 'w') as file:
|
| 424 |
-
|
| 425 |
-
|
| 426 |
results = {}
|
| 427 |
|
| 428 |
for unav in filtered_unavs:
|
|
@@ -553,11 +553,11 @@ def nuc_monitor(rte_data, mongo_json_data, usr_start_date, usr_end_date, photo_d
|
|
| 553 |
|
| 554 |
# print(output_results)
|
| 555 |
add_total(output_results)
|
| 556 |
-
print("Done")
|
| 557 |
# print(results_plants)
|
| 558 |
# Convert datetime key to string to store in mongodb
|
| 559 |
output_results = {plant: {str(date): power for date, power in plant_data.items()} for plant, plant_data in output_results.items()}
|
| 560 |
-
print(output_results)
|
| 561 |
# -------------------------------------------------
|
| 562 |
if photo_date == False:
|
| 563 |
# Store the results_plants in MongoDB
|
|
@@ -570,7 +570,7 @@ def nuc_monitor(rte_data, mongo_json_data, usr_start_date, usr_end_date, photo_d
|
|
| 570 |
|
| 571 |
# json_data = json.dumps(convert_to_json(output_results))
|
| 572 |
json_data = json.dumps(output_results)
|
| 573 |
-
print(json_data)
|
| 574 |
return json_data
|
| 575 |
else:
|
| 576 |
database_name = "data" # Specify your database name
|
|
@@ -579,7 +579,7 @@ def nuc_monitor(rte_data, mongo_json_data, usr_start_date, usr_end_date, photo_d
|
|
| 579 |
|
| 580 |
# json_data = json.dumps(convert_to_json(output_results))
|
| 581 |
json_data = json.dumps(output_results)
|
| 582 |
-
print(json_data)
|
| 583 |
return json_data
|
| 584 |
# -------------------------------------------------
|
| 585 |
return
|
|
|
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
+
# mongo_data = mongo_json_data.json()
|
| 304 |
|
| 305 |
+
# # Specify the file path
|
| 306 |
+
# file_path = "/Users/diegomarroquin/HayaEnergy/Nucmonitor_MVP/NucPy_v0.2/testing/test_data3.txt"
|
| 307 |
|
| 308 |
# Open the file in write mode
|
| 309 |
with open(file_path, 'w') as file:
|
|
|
|
| 322 |
# Drop the original column
|
| 323 |
mongo_df_result.drop(columns=['generation_unavailabilities'], inplace=True)
|
| 324 |
mongo_df_columns = mongo_df_result.columns
|
| 325 |
+
# print(mongo_df_columns)
|
| 326 |
+
# print(mongo_df_result)
|
| 327 |
+
# print(mongo_df_result["values"])
|
| 328 |
# # Unpack values column
|
| 329 |
# # mongo_df2 = mongo_df_result.copy().apply(unpack_values, axis=1)
|
| 330 |
# mongo_df_values_unpacked = pd.json_normalize(mongo_df_result['values'])
|
|
|
|
| 342 |
mongo_df_result['end_date'] = mongo_df_result['values'].apply(lambda x: x[0]['end_date'])
|
| 343 |
mongo_df_result['available_capacity'] = mongo_df_result['values'].apply(lambda x: x[0]['available_capacity'])
|
| 344 |
mongo_df_result['unavailable_capacity'] = mongo_df_result['values'].apply(lambda x: x[0]['unavailable_capacity'])
|
| 345 |
+
# print(mongo_df_result)
|
| 346 |
+
# print(mongo_df_result.columns)
|
| 347 |
# Drop the original 'values' column
|
| 348 |
mongo_df_result.drop('values', axis=1, inplace=True)
|
| 349 |
mongo_df2 = mongo_df_result
|
|
|
|
| 362 |
|
| 363 |
# Merge dataframes
|
| 364 |
column_order = mongo_unavs.columns
|
| 365 |
+
# print(column_order)
|
| 366 |
merged_df = pd.concat([mongo_unavs[column_order], rte_unavs[column_order]], ignore_index=True)
|
| 367 |
|
| 368 |
# --------------------------- HERE IS THE CHANGE TO GET ONLY ACTIVE OR ACTIVE AND INACTIVE --------------------------- #
|
|
|
|
| 417 |
# Turn df into dict for json processing
|
| 418 |
filtered_unavs = filtered_df3.copy().to_dict(orient='records')
|
| 419 |
|
| 420 |
+
# file_path = "/Users/diegomarroquin/HayaEnergy/Nucmonitor_MVP/NucPy_v0.2/testing/test_data4.txt"
|
| 421 |
|
| 422 |
+
# # Open the file in write mode
|
| 423 |
+
# with open(file_path, 'w') as file:
|
| 424 |
+
# for item in filtered_unavs:
|
| 425 |
+
# file.write("%s" % item)
|
| 426 |
results = {}
|
| 427 |
|
| 428 |
for unav in filtered_unavs:
|
|
|
|
| 553 |
|
| 554 |
# print(output_results)
|
| 555 |
add_total(output_results)
|
| 556 |
+
# print("Done")
|
| 557 |
# print(results_plants)
|
| 558 |
# Convert datetime key to string to store in mongodb
|
| 559 |
output_results = {plant: {str(date): power for date, power in plant_data.items()} for plant, plant_data in output_results.items()}
|
| 560 |
+
# print(output_results)
|
| 561 |
# -------------------------------------------------
|
| 562 |
if photo_date == False:
|
| 563 |
# Store the results_plants in MongoDB
|
|
|
|
| 570 |
|
| 571 |
# json_data = json.dumps(convert_to_json(output_results))
|
| 572 |
json_data = json.dumps(output_results)
|
| 573 |
+
# print(json_data)
|
| 574 |
return json_data
|
| 575 |
else:
|
| 576 |
database_name = "data" # Specify your database name
|
|
|
|
| 579 |
|
| 580 |
# json_data = json.dumps(convert_to_json(output_results))
|
| 581 |
json_data = json.dumps(output_results)
|
| 582 |
+
# print(json_data)
|
| 583 |
return json_data
|
| 584 |
# -------------------------------------------------
|
| 585 |
return
|