I hope I fixed the error where we were not getting all updated_dates up to the specified photo date. I had to fix it at the mongo call bc for some fucking reason the filter wasn't working properly at the dataframe. Golfech test passed
Browse files- .gitignore +2 -1
- app.py +48 -27
.gitignore
CHANGED
|
@@ -1,2 +1,3 @@
|
|
| 1 |
/app_with_api.py
|
| 2 |
-
/app_with_rte.py
|
|
|
|
|
|
| 1 |
/app_with_api.py
|
| 2 |
+
/app_with_rte.py
|
| 3 |
+
/venv
|
app.py
CHANGED
|
@@ -33,6 +33,7 @@ def mongo_unavs_call(user_input_start_date, user_input_end_date, user_input_past
|
|
| 33 |
|
| 34 |
start_date = f"{user_input_start_date}T00:00:00"
|
| 35 |
end_date = f"{user_input_end_date}T23:59:59"
|
|
|
|
| 36 |
|
| 37 |
pipeline = [
|
| 38 |
{
|
|
@@ -46,7 +47,8 @@ def mongo_unavs_call(user_input_start_date, user_input_end_date, user_input_past
|
|
| 46 |
"results.generation_unavailabilities.production_type": "NUCLEAR",
|
| 47 |
# "results.generation_unavailabilities.start_date": {"$lte": end_date},
|
| 48 |
# "results.generation_unavailabilities.end_date": {"$gte": start_date},
|
| 49 |
-
"results.generation_unavailabilities.updated_date": {"$lte": end_date}
|
|
|
|
| 50 |
}
|
| 51 |
},
|
| 52 |
{
|
|
@@ -158,12 +160,15 @@ def nuc_monitor(usr_start_date, usr_end_date, past_date, mongo_db_data):
|
|
| 158 |
# end_date_str = usr_end_date.strftime("%Y-%m-%d")
|
| 159 |
end_date_str = str(usr_end_date)
|
| 160 |
current_datetime = datetime.datetime.now()
|
| 161 |
-
past_date_str = str(past_date)
|
| 162 |
current_datetime_str = current_datetime.strftime("%Y-%m-%d")
|
| 163 |
|
| 164 |
# nuclear_unav = mongo_unavs.copy()[(mongo_unavs.copy()["production_type"] == "NUCLEAR") & (mongo_unavs.copy()["updated_date"] <= past_date_str)]
|
| 165 |
-
|
| 166 |
-
|
|
|
|
|
|
|
|
|
|
| 167 |
|
| 168 |
# if photo_date == True:
|
| 169 |
# nuclear_unav = merged_df.copy()[(merged_df.copy()["production_type"] == "NUCLEAR") & (merged_df.copy()["updated_date"] <= past_date_str)]
|
|
@@ -181,11 +186,17 @@ def nuc_monitor(usr_start_date, usr_end_date, past_date, mongo_db_data):
|
|
| 181 |
|
| 182 |
sorted_df = sorted_df.copy().reset_index(drop=True)
|
| 183 |
|
|
|
|
|
|
|
|
|
|
| 184 |
# Filter to get identifiers
|
| 185 |
filtered_id_df = sorted_df.copy()
|
| 186 |
# --------------------------- !!!!!!!!!!!!!!!!!!!!!!! HERE IS POTENTIAL ERROR!!!!!!!!!!!!!!!!!!!!!!! --------------------------- #
|
| 187 |
# I commented this out
|
| 188 |
-
filtered_id_df.drop_duplicates(subset='identifier', keep='last'
|
|
|
|
|
|
|
|
|
|
| 189 |
# --------------------------- !!!!!!!!!!!!!!!!!!!!!!! HERE IS POTENTIAL ERROR!!!!!!!!!!!!!!!!!!!!!!! --------------------------- #
|
| 190 |
|
| 191 |
filtered_id_df = filtered_id_df.copy().reset_index(drop=True)
|
|
@@ -379,7 +390,17 @@ def get_nucmonitor_data(start_date, end_date, past_date):
|
|
| 379 |
response_nucmonitor = nuc_monitor(start_date, end_date, past_date, mongo)
|
| 380 |
# nucmonitor_data = response_nucmonitor.json()
|
| 381 |
# nucmonitor_json = json.loads(nucmonitor_data)
|
| 382 |
-
print(response_nucmonitor)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 383 |
df = pd.read_json(response_nucmonitor)
|
| 384 |
return df
|
| 385 |
|
|
@@ -404,7 +425,7 @@ def run_app():
|
|
| 404 |
else:
|
| 405 |
st.write("Data received from Flask:")
|
| 406 |
df_nucmonitor = get_nucmonitor_data(start_date, end_date, current_date)
|
| 407 |
-
df_photo_date =
|
| 408 |
# df_winter_date = get_nucmonitor_data(start_date, end_date, winter_date)
|
| 409 |
current_date_str = str(current_date.strftime('%Y-%m-%d'))
|
| 410 |
past_date_str = str(past_date.strftime('%Y-%m-%d'))
|
|
@@ -422,7 +443,7 @@ def run_app():
|
|
| 422 |
# Get the last column
|
| 423 |
df_nucmonitor_2 = df_nucmonitor_2.iloc[:, -1]
|
| 424 |
|
| 425 |
-
print(df_nucmonitor_2)
|
| 426 |
|
| 427 |
st.write(df_nucmonitor_2)
|
| 428 |
|
|
@@ -434,7 +455,7 @@ def run_app():
|
|
| 434 |
# Get the last column
|
| 435 |
df_photo_date_2 = df_photo_date_2.iloc[:, -1]
|
| 436 |
|
| 437 |
-
print(df_photo_date_2)
|
| 438 |
|
| 439 |
st.write(df_photo_date_2)
|
| 440 |
|
|
@@ -476,14 +497,14 @@ def run_app():
|
|
| 476 |
monthly_average_photo_date.index = monthly_average_photo_date.index.strftime('%Y-%m')
|
| 477 |
|
| 478 |
|
| 479 |
-
print(monthly_average_nucmonitor)
|
| 480 |
-
print(monthly_average_nucmonitor.index)
|
| 481 |
-
print(len(monthly_average_nucmonitor.index) < 5)
|
| 482 |
if (len(monthly_average_nucmonitor.index) < 5) or (two_months_before not in monthly_average_nucmonitor.index or two_months_after not in monthly_average_nucmonitor.index):
|
| 483 |
df_display_normal_bool = False
|
| 484 |
|
| 485 |
else:
|
| 486 |
-
print(two_months_before, one_month_before, current_date.strftime('%Y-%m'), one_month_after, two_months_after)
|
| 487 |
# Filter DataFrames based on date ranges
|
| 488 |
df_nucmonitor_filtered = monthly_average_nucmonitor[
|
| 489 |
(monthly_average_nucmonitor.index == two_months_before) |
|
|
@@ -511,10 +532,10 @@ def run_app():
|
|
| 511 |
past_forecast_update = df_photo_date_filtered.tolist()
|
| 512 |
delta = [current - past for current, past in zip(current_forecast_update, past_forecast_update)]
|
| 513 |
|
| 514 |
-
print('Dates:', [two_months_before, one_month_before, current_date.strftime('%Y-%m'), one_month_after, two_months_after])
|
| 515 |
-
print(f"Forecast update {current_date_str}", current_forecast_update)
|
| 516 |
-
print(f"Forecast update {past_date_str}", past_forecast_update,)
|
| 517 |
-
print('Delta', delta)
|
| 518 |
|
| 519 |
# Create a DataFrame for display
|
| 520 |
data_avg_expected_normal = {
|
|
@@ -541,11 +562,11 @@ def run_app():
|
|
| 541 |
winter_end = f"{current_date.year+1}-03"
|
| 542 |
winter_start_str = str(winter_start)
|
| 543 |
winter_end_str = str(winter_end)
|
| 544 |
-
print("winter_start_str", winter_start)
|
| 545 |
-
print("winter_end_str", winter_end)
|
| 546 |
-
print("monthly_average_nucmonitor.index", monthly_average_nucmonitor.index)
|
| 547 |
-
print(monthly_average_nucmonitor.index == winter_start)
|
| 548 |
-
print(monthly_average_nucmonitor.index == winter_end)
|
| 549 |
if monthly_average_nucmonitor.index.any() != winter_start or monthly_average_nucmonitor.index.any() != winter_end:
|
| 550 |
df_display_winter_bool = False
|
| 551 |
|
|
@@ -566,8 +587,8 @@ def run_app():
|
|
| 566 |
current_winter_forecast_update = df_nucmonitor_winter.tolist()
|
| 567 |
past_winter_forecast_update = df_photo_date_winter.tolist()
|
| 568 |
winter_delta = [current - past for current, past in zip(current_winter_forecast_update, past_winter_forecast_update)]
|
| 569 |
-
print("current_winter_forecast_update:", current_winter_forecast_update)
|
| 570 |
-
print("past_winter_forecast_update:", past_winter_forecast_update)
|
| 571 |
|
| 572 |
# Create a DataFrame for display
|
| 573 |
data_avg_expected_winter = {
|
|
@@ -576,7 +597,7 @@ def run_app():
|
|
| 576 |
f"Forecast update {past_date_str}": past_winter_forecast_update,
|
| 577 |
'Delta': winter_delta
|
| 578 |
}
|
| 579 |
-
print(data_avg_expected_winter)
|
| 580 |
df_display_winter_bool = True
|
| 581 |
|
| 582 |
# --------------------------------- AVERAGE EXPECTED AVAILABILITY WINTER PIPELINE --------------------------------- #
|
|
@@ -609,7 +630,7 @@ def run_app():
|
|
| 609 |
|
| 610 |
# Optionally, if you want to reset the index
|
| 611 |
# real_forecast = real_forecast.reset_index()
|
| 612 |
-
print(real_forecast)
|
| 613 |
st.write("Real forecast")
|
| 614 |
st.line_chart(real_forecast)
|
| 615 |
|
|
@@ -620,7 +641,7 @@ def run_app():
|
|
| 620 |
# combined_df.columns = [f'Forecast {current_date_str}', f'Forecast {past_date_str}', 'Real Forecast', f'Winter forecast {winter_start}/{winter_end}']
|
| 621 |
combined_df.columns = [f'Forecast {current_date_str}', f'Forecast {past_date_str}', 'Real Forecast']
|
| 622 |
|
| 623 |
-
print(combined_df)
|
| 624 |
st.write(f"Graph 1. {start_date} to {end_date}")
|
| 625 |
st.line_chart(combined_df)
|
| 626 |
|
|
|
|
| 33 |
|
| 34 |
start_date = f"{user_input_start_date}T00:00:00"
|
| 35 |
end_date = f"{user_input_end_date}T23:59:59"
|
| 36 |
+
past_date = f"{user_input_past_date}T23:59:59"
|
| 37 |
|
| 38 |
pipeline = [
|
| 39 |
{
|
|
|
|
| 47 |
"results.generation_unavailabilities.production_type": "NUCLEAR",
|
| 48 |
# "results.generation_unavailabilities.start_date": {"$lte": end_date},
|
| 49 |
# "results.generation_unavailabilities.end_date": {"$gte": start_date},
|
| 50 |
+
# "results.generation_unavailabilities.updated_date": {"$lte": end_date}
|
| 51 |
+
"results.generation_unavailabilities.updated_date": {"$lte": past_date}
|
| 52 |
}
|
| 53 |
},
|
| 54 |
{
|
|
|
|
| 160 |
# end_date_str = usr_end_date.strftime("%Y-%m-%d")
|
| 161 |
end_date_str = str(usr_end_date)
|
| 162 |
current_datetime = datetime.datetime.now()
|
| 163 |
+
past_date_str = str(past_date.strftime("%Y-%m-%dT%H:%M:%S%z"))
|
| 164 |
current_datetime_str = current_datetime.strftime("%Y-%m-%d")
|
| 165 |
|
| 166 |
# nuclear_unav = mongo_unavs.copy()[(mongo_unavs.copy()["production_type"] == "NUCLEAR") & (mongo_unavs.copy()["updated_date"] <= past_date_str)]
|
| 167 |
+
print(past_date_str)
|
| 168 |
+
nuclear_unav = mongo_unavs[
|
| 169 |
+
(mongo_unavs["production_type"] == "NUCLEAR") &
|
| 170 |
+
# (mongo_unavs["updated_date"] <= past_date_str) &
|
| 171 |
+
(mongo_unavs["status"] != "DISMISSED")]
|
| 172 |
|
| 173 |
# if photo_date == True:
|
| 174 |
# nuclear_unav = merged_df.copy()[(merged_df.copy()["production_type"] == "NUCLEAR") & (merged_df.copy()["updated_date"] <= past_date_str)]
|
|
|
|
| 186 |
|
| 187 |
sorted_df = sorted_df.copy().reset_index(drop=True)
|
| 188 |
|
| 189 |
+
golfech_1 = sorted_df.copy()[(sorted_df.copy()["name"] == "GOLFECH 1") & (sorted_df.copy()["end_date"] >= start_date_str)]
|
| 190 |
+
print(golfech_1[['updated_date', 'available_capacity']])
|
| 191 |
+
|
| 192 |
# Filter to get identifiers
|
| 193 |
filtered_id_df = sorted_df.copy()
|
| 194 |
# --------------------------- !!!!!!!!!!!!!!!!!!!!!!! HERE IS POTENTIAL ERROR!!!!!!!!!!!!!!!!!!!!!!! --------------------------- #
|
| 195 |
# I commented this out
|
| 196 |
+
filtered_id_df = filtered_id_df.drop_duplicates(subset='identifier', keep='last')
|
| 197 |
+
|
| 198 |
+
golfech_1 = filtered_id_df.copy()[(filtered_id_df.copy()["name"] == "GOLFECH 1") & (filtered_id_df.copy()["end_date"] >= start_date_str)]
|
| 199 |
+
print(golfech_1[['updated_date', 'available_capacity']])
|
| 200 |
# --------------------------- !!!!!!!!!!!!!!!!!!!!!!! HERE IS POTENTIAL ERROR!!!!!!!!!!!!!!!!!!!!!!! --------------------------- #
|
| 201 |
|
| 202 |
filtered_id_df = filtered_id_df.copy().reset_index(drop=True)
|
|
|
|
| 390 |
response_nucmonitor = nuc_monitor(start_date, end_date, past_date, mongo)
|
| 391 |
# nucmonitor_data = response_nucmonitor.json()
|
| 392 |
# nucmonitor_json = json.loads(nucmonitor_data)
|
| 393 |
+
# print(response_nucmonitor)
|
| 394 |
+
df = pd.read_json(response_nucmonitor)
|
| 395 |
+
return df
|
| 396 |
+
|
| 397 |
+
@st.cache_data
|
| 398 |
+
def get_photodate_data(start_date, end_date, past_date):
|
| 399 |
+
mongo = get_mongodb_data(start_date, end_date, past_date)
|
| 400 |
+
response_nucmonitor = nuc_monitor(start_date, end_date, past_date, mongo)
|
| 401 |
+
# nucmonitor_data = response_nucmonitor.json()
|
| 402 |
+
# nucmonitor_json = json.loads(nucmonitor_data)
|
| 403 |
+
# print(response_nucmonitor)
|
| 404 |
df = pd.read_json(response_nucmonitor)
|
| 405 |
return df
|
| 406 |
|
|
|
|
| 425 |
else:
|
| 426 |
st.write("Data received from Flask:")
|
| 427 |
df_nucmonitor = get_nucmonitor_data(start_date, end_date, current_date)
|
| 428 |
+
df_photo_date = get_photodate_data(start_date, end_date, past_date)
|
| 429 |
# df_winter_date = get_nucmonitor_data(start_date, end_date, winter_date)
|
| 430 |
current_date_str = str(current_date.strftime('%Y-%m-%d'))
|
| 431 |
past_date_str = str(past_date.strftime('%Y-%m-%d'))
|
|
|
|
| 443 |
# Get the last column
|
| 444 |
df_nucmonitor_2 = df_nucmonitor_2.iloc[:, -1]
|
| 445 |
|
| 446 |
+
# print(df_nucmonitor_2)
|
| 447 |
|
| 448 |
st.write(df_nucmonitor_2)
|
| 449 |
|
|
|
|
| 455 |
# Get the last column
|
| 456 |
df_photo_date_2 = df_photo_date_2.iloc[:, -1]
|
| 457 |
|
| 458 |
+
# print(df_photo_date_2)
|
| 459 |
|
| 460 |
st.write(df_photo_date_2)
|
| 461 |
|
|
|
|
| 497 |
monthly_average_photo_date.index = monthly_average_photo_date.index.strftime('%Y-%m')
|
| 498 |
|
| 499 |
|
| 500 |
+
# print(monthly_average_nucmonitor)
|
| 501 |
+
# print(monthly_average_nucmonitor.index)
|
| 502 |
+
# print(len(monthly_average_nucmonitor.index) < 5)
|
| 503 |
if (len(monthly_average_nucmonitor.index) < 5) or (two_months_before not in monthly_average_nucmonitor.index or two_months_after not in monthly_average_nucmonitor.index):
|
| 504 |
df_display_normal_bool = False
|
| 505 |
|
| 506 |
else:
|
| 507 |
+
# print(two_months_before, one_month_before, current_date.strftime('%Y-%m'), one_month_after, two_months_after)
|
| 508 |
# Filter DataFrames based on date ranges
|
| 509 |
df_nucmonitor_filtered = monthly_average_nucmonitor[
|
| 510 |
(monthly_average_nucmonitor.index == two_months_before) |
|
|
|
|
| 532 |
past_forecast_update = df_photo_date_filtered.tolist()
|
| 533 |
delta = [current - past for current, past in zip(current_forecast_update, past_forecast_update)]
|
| 534 |
|
| 535 |
+
# print('Dates:', [two_months_before, one_month_before, current_date.strftime('%Y-%m'), one_month_after, two_months_after])
|
| 536 |
+
# print(f"Forecast update {current_date_str}", current_forecast_update)
|
| 537 |
+
# print(f"Forecast update {past_date_str}", past_forecast_update,)
|
| 538 |
+
# print('Delta', delta)
|
| 539 |
|
| 540 |
# Create a DataFrame for display
|
| 541 |
data_avg_expected_normal = {
|
|
|
|
| 562 |
winter_end = f"{current_date.year+1}-03"
|
| 563 |
winter_start_str = str(winter_start)
|
| 564 |
winter_end_str = str(winter_end)
|
| 565 |
+
# print("winter_start_str", winter_start)
|
| 566 |
+
# print("winter_end_str", winter_end)
|
| 567 |
+
# print("monthly_average_nucmonitor.index", monthly_average_nucmonitor.index)
|
| 568 |
+
# print(monthly_average_nucmonitor.index == winter_start)
|
| 569 |
+
# print(monthly_average_nucmonitor.index == winter_end)
|
| 570 |
if monthly_average_nucmonitor.index.any() != winter_start or monthly_average_nucmonitor.index.any() != winter_end:
|
| 571 |
df_display_winter_bool = False
|
| 572 |
|
|
|
|
| 587 |
current_winter_forecast_update = df_nucmonitor_winter.tolist()
|
| 588 |
past_winter_forecast_update = df_photo_date_winter.tolist()
|
| 589 |
winter_delta = [current - past for current, past in zip(current_winter_forecast_update, past_winter_forecast_update)]
|
| 590 |
+
# print("current_winter_forecast_update:", current_winter_forecast_update)
|
| 591 |
+
# print("past_winter_forecast_update:", past_winter_forecast_update)
|
| 592 |
|
| 593 |
# Create a DataFrame for display
|
| 594 |
data_avg_expected_winter = {
|
|
|
|
| 597 |
f"Forecast update {past_date_str}": past_winter_forecast_update,
|
| 598 |
'Delta': winter_delta
|
| 599 |
}
|
| 600 |
+
# print(data_avg_expected_winter)
|
| 601 |
df_display_winter_bool = True
|
| 602 |
|
| 603 |
# --------------------------------- AVERAGE EXPECTED AVAILABILITY WINTER PIPELINE --------------------------------- #
|
|
|
|
| 630 |
|
| 631 |
# Optionally, if you want to reset the index
|
| 632 |
# real_forecast = real_forecast.reset_index()
|
| 633 |
+
# print(real_forecast)
|
| 634 |
st.write("Real forecast")
|
| 635 |
st.line_chart(real_forecast)
|
| 636 |
|
|
|
|
| 641 |
# combined_df.columns = [f'Forecast {current_date_str}', f'Forecast {past_date_str}', 'Real Forecast', f'Winter forecast {winter_start}/{winter_end}']
|
| 642 |
combined_df.columns = [f'Forecast {current_date_str}', f'Forecast {past_date_str}', 'Real Forecast']
|
| 643 |
|
| 644 |
+
# print(combined_df)
|
| 645 |
st.write(f"Graph 1. {start_date} to {end_date}")
|
| 646 |
st.line_chart(combined_df)
|
| 647 |
|