Diego Marroquin commited on
Commit ·
5b21d40
1
Parent(s): f32d855
previous version
Browse files
app.py
CHANGED
|
@@ -577,55 +577,31 @@ def run_app():
|
|
| 577 |
|
| 578 |
st.write(df_photo_date_2)
|
| 579 |
|
| 580 |
-
# --------------------------------- AVERAGE EXPECTED AVAILABILITY M-1 M M+1 M+2 PIPELINE --------------------------------- #
|
| 581 |
-
|
| 582 |
# Create a Table that displays the forecast of each dataframe total for two months before date and two months after
|
|
|
|
|
|
|
| 583 |
# Filter dates for two months before and after the current date
|
| 584 |
# Define date ranges
|
| 585 |
-
two_months_before = (current_date - pd.DateOffset(months=2)).strftime('%Y-%m')
|
| 586 |
-
one_month_before = (current_date - pd.DateOffset(months=1)).strftime('%Y-%m')
|
| 587 |
-
one_month_after = (current_date + pd.DateOffset(months=1)).strftime('%Y-%m')
|
| 588 |
-
two_months_after = (current_date + pd.DateOffset(months=2)).strftime('%Y-%m')
|
| 589 |
-
|
| 590 |
-
# Assuming df is the DataFrame containing the date index and the 'Total' column
|
| 591 |
-
|
| 592 |
-
# # Convert the index to datetime if it's not already
|
| 593 |
-
# df_nucmonitor_2.index = pd.to_datetime(df_nucmonitor_2.index)
|
| 594 |
-
# df_photo_date_2.index = pd.to_datetime(df_photo_date_2.index)
|
| 595 |
-
|
| 596 |
-
# # Calculate monthly averages with date in yyyy-mm format
|
| 597 |
-
# monthly_average_nucmonitor = df_nucmonitor_2.resample('M').mean()
|
| 598 |
-
# monthly_average_photo_date = df_photo_date_2.resample('M').mean()
|
| 599 |
|
| 600 |
-
# Convert the index to datetime if it's not already
|
| 601 |
-
df_nucmonitor_2.index = pd.to_datetime(df_nucmonitor_2.index)
|
| 602 |
-
df_photo_date_2.index = pd.to_datetime(df_photo_date_2.index)
|
| 603 |
-
|
| 604 |
-
# Calculate monthly averages with date in yyyy-mm format
|
| 605 |
-
monthly_average_nucmonitor = df_nucmonitor_2.resample('M').mean()
|
| 606 |
-
monthly_average_nucmonitor.index = monthly_average_nucmonitor.index.strftime('%Y-%m')
|
| 607 |
-
|
| 608 |
-
monthly_average_photo_date = df_photo_date_2.resample('M').mean()
|
| 609 |
-
monthly_average_photo_date.index = monthly_average_photo_date.index.strftime('%Y-%m')
|
| 610 |
-
|
| 611 |
-
|
| 612 |
-
print(monthly_average_nucmonitor)
|
| 613 |
-
print(two_months_before, one_month_before, current_date.strftime('%Y-%m'), one_month_after, two_months_after)
|
| 614 |
# Filter DataFrames based on date ranges
|
| 615 |
-
df_nucmonitor_filtered =
|
| 616 |
-
(
|
| 617 |
-
(
|
| 618 |
-
(
|
| 619 |
-
(
|
| 620 |
-
(
|
| 621 |
]
|
| 622 |
|
| 623 |
-
df_photo_date_filtered =
|
| 624 |
-
(
|
| 625 |
-
(
|
| 626 |
-
(
|
| 627 |
-
(
|
| 628 |
-
(
|
| 629 |
]
|
| 630 |
|
| 631 |
# Display the filtered DataFrames
|
|
@@ -633,82 +609,24 @@ def run_app():
|
|
| 633 |
st.write(df_nucmonitor_filtered)
|
| 634 |
st.write(f"Forecast update {past_date_str}")
|
| 635 |
st.write(df_photo_date_filtered)
|
| 636 |
-
|
| 637 |
current_forecast_update = df_nucmonitor_filtered.tolist()
|
| 638 |
past_forecast_update = df_photo_date_filtered.tolist()
|
| 639 |
delta = [current - past for current, past in zip(current_forecast_update, past_forecast_update)]
|
| 640 |
|
| 641 |
-
print('Dates:', [two_months_before, one_month_before, current_date.strftime('%Y-%m'), one_month_after, two_months_after])
|
| 642 |
-
print(f"Forecast update {current_date_str}", current_forecast_update)
|
| 643 |
-
print(f"Forecast update {past_date_str}", past_forecast_update,)
|
| 644 |
-
print('Delta', delta)
|
| 645 |
-
|
| 646 |
# Create a DataFrame for display
|
| 647 |
-
|
| 648 |
-
'Dates': [two_months_before, one_month_before,
|
| 649 |
f"Forecast update {current_date_str}": current_forecast_update,
|
| 650 |
f"Forecast update {past_date_str}": past_forecast_update,
|
| 651 |
'Delta': delta
|
| 652 |
}
|
| 653 |
-
# --------------------------------- AVERAGE EXPECTED AVAILABILITY M-1 M M+1 M+2 PIPELINE --------------------------------- #
|
| 654 |
|
| 655 |
-
|
| 656 |
-
# Create a Table that displays the forecast of each dataframe for the Winter months (Nov, Dec, Jan, Feb, Mar)
|
| 657 |
-
|
| 658 |
-
# Create a table that gets the forecast for winter. This involves creating a new dataframe with
|
| 659 |
-
# only the winter months with the total of each day, and another dataframe with the average of each month. Each month
|
| 660 |
-
# included will only be 20xx-11, 12, and 20xx+1-01, 02, 03
|
| 661 |
-
|
| 662 |
-
# Define date ranges for winter months
|
| 663 |
-
winter_start_date = current_date.replace(month=11, day=1)
|
| 664 |
-
winter_end_date = (current_date.replace(year=current_date.year+1, month=3, day=31))
|
| 665 |
-
winter_start = f"{current_date.year}-11"
|
| 666 |
-
winter_end = f"{current_date.year+1}-3"
|
| 667 |
-
winter_start_str = str(winter_start)
|
| 668 |
-
winter_end_str = str(winter_end)
|
| 669 |
-
print("winter_start_str", winter_start_str)
|
| 670 |
-
print("winter_end_str", winter_end_str)
|
| 671 |
-
print(monthly_average_nucmonitor.index)
|
| 672 |
-
# Filter DataFrames based on winter date range
|
| 673 |
-
df_nucmonitor_winter = monthly_average_nucmonitor[(monthly_average_nucmonitor.index >= winter_start_str) & (monthly_average_nucmonitor.index <= winter_end_str)]
|
| 674 |
-
df_photo_date_winter = monthly_average_photo_date[(monthly_average_photo_date.index >= winter_start_str) & (monthly_average_photo_date.index <= winter_end_str)]
|
| 675 |
-
|
| 676 |
-
# Display the forecast DataFrames for winter
|
| 677 |
-
st.title("Forecast for Winter Months")
|
| 678 |
-
st.write(f"Forecast for {current_date.year}-{current_date.year+1} (Nov, Dec, Jan, Feb, Mar)")
|
| 679 |
-
st.write("Nucmonitor Forecast:")
|
| 680 |
-
st.write(df_nucmonitor_winter)
|
| 681 |
-
st.write("Photo Date Forecast:")
|
| 682 |
-
st.write(df_photo_date_winter)
|
| 683 |
-
|
| 684 |
-
current_winter_forecast_update = df_nucmonitor_winter.tolist()
|
| 685 |
-
past_winter_forecast_update = df_photo_date_winter.tolist()
|
| 686 |
-
winter_delta = [current - past for current, past in zip(current_winter_forecast_update, past_winter_forecast_update)]
|
| 687 |
-
print("Dates:", [f'Nov-{current_date.year}', f'Dec-{current_date.year}', f'Jan-{current_date.year+1}', f'Feb-{current_date.year+1}', f'Mar-{current_date.year+1}'])
|
| 688 |
-
print(f"Forecast update {current_date_str}:", current_winter_forecast_update)
|
| 689 |
-
print(f"Forecast update {past_date_str}:", past_winter_forecast_update)
|
| 690 |
-
print('Delta:', winter_delta)
|
| 691 |
-
# Create a DataFrame for display
|
| 692 |
-
data_avg_expected_winter = {
|
| 693 |
-
'Dates': [f'Nov-{current_date.year}', f'Dec-{current_date.year}', f'Jan-{current_date.year+1}', f'Feb-{current_date.year+1}', f'Mar-{current_date.year+1}'],
|
| 694 |
-
f"Forecast update {current_date_str}": current_winter_forecast_update,
|
| 695 |
-
f"Forecast update {past_date_str}": past_winter_forecast_update,
|
| 696 |
-
'Delta': winter_delta
|
| 697 |
-
}
|
| 698 |
-
|
| 699 |
-
# --------------------------------- AVERAGE EXPECTED AVAILABILITY WINTER PIPELINE --------------------------------- #
|
| 700 |
-
|
| 701 |
-
# --------------------------------- VISUALIZE --------------------------------- #
|
| 702 |
-
|
| 703 |
-
df_display_normal = pd.DataFrame(data_avg_expected_normal)
|
| 704 |
-
df_display_winter = pd.DataFrame(data_avg_expected_winter)
|
| 705 |
|
| 706 |
# Display the DataFrame as a horizontal table
|
| 707 |
st.write("Table 1. Average expected availability on the French nuclear fleet (MW) - M-1, M, M+1, M+2, M+3")
|
| 708 |
-
st.table(
|
| 709 |
|
| 710 |
-
st.write(f"Table 2. Average expected availability on the French nuclear fleet (MW) - Winter {winter_start}/{winter_end}")
|
| 711 |
-
st.table(df_display_winter)
|
| 712 |
|
| 713 |
# Line charts of the forecasts (need to combine them so they appear in the same chart)
|
| 714 |
st.write("Current forecast")
|
|
@@ -721,17 +639,15 @@ def run_app():
|
|
| 721 |
# Slice the DataFrame to include data up until current_date
|
| 722 |
real_forecast = df_nucmonitor_2.loc[df_nucmonitor_2.index <= current_date_str]
|
| 723 |
|
| 724 |
-
# Winter forecast still not the correct one, this is just a placeholder
|
| 725 |
-
winter_forecast = df_nucmonitor_2.loc[(df_nucmonitor_2.index >= winter_start_date) & (df_nucmonitor_2.index <= winter_end_date)]
|
| 726 |
# Optionally, if you want to reset the index
|
| 727 |
# real_forecast = real_forecast.reset_index()
|
| 728 |
print(real_forecast)
|
| 729 |
st.write("Real forecast")
|
| 730 |
st.line_chart(real_forecast)
|
| 731 |
-
|
| 732 |
# Combine dataframes
|
| 733 |
-
combined_df = pd.concat([df_nucmonitor_2, df_photo_date_2, real_forecast
|
| 734 |
-
combined_df.columns = [f'Forecast {current_date_str}', f'Forecast {past_date_str}', 'Real Forecast'
|
| 735 |
|
| 736 |
print(combined_df)
|
| 737 |
st.write(f"Graph 1. {start_date} to {end_date}")
|
|
|
|
| 577 |
|
| 578 |
st.write(df_photo_date_2)
|
| 579 |
|
|
|
|
|
|
|
| 580 |
# Create a Table that displays the forecast of each dataframe total for two months before date and two months after
|
| 581 |
+
# Create a Table that displays the forecast of each dataframe for the Winter months (Nov, Dec, Jan, Feb, Mar)
|
| 582 |
+
|
| 583 |
# Filter dates for two months before and after the current date
|
| 584 |
# Define date ranges
|
| 585 |
+
two_months_before = (current_date - pd.DateOffset(months=2)).strftime('%Y-%m-%d')
|
| 586 |
+
one_month_before = (current_date - pd.DateOffset(months=1)).strftime('%Y-%m-%d')
|
| 587 |
+
one_month_after = (current_date + pd.DateOffset(months=1)).strftime('%Y-%m-%d')
|
| 588 |
+
two_months_after = (current_date + pd.DateOffset(months=2)).strftime('%Y-%m-%d')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 589 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 590 |
# Filter DataFrames based on date ranges
|
| 591 |
+
df_nucmonitor_filtered = df_nucmonitor_2[
|
| 592 |
+
(df_nucmonitor_2.index == two_months_before) |
|
| 593 |
+
(df_nucmonitor_2.index == one_month_before) |
|
| 594 |
+
(df_nucmonitor_2.index == current_date_str) |
|
| 595 |
+
(df_nucmonitor_2.index == one_month_after) |
|
| 596 |
+
(df_nucmonitor_2.index == two_months_after)
|
| 597 |
]
|
| 598 |
|
| 599 |
+
df_photo_date_filtered = df_photo_date_2[
|
| 600 |
+
(df_photo_date_2.index == two_months_before) |
|
| 601 |
+
(df_photo_date_2.index == one_month_before) |
|
| 602 |
+
(df_photo_date_2.index == current_date_str) |
|
| 603 |
+
(df_photo_date_2.index == one_month_after) |
|
| 604 |
+
(df_photo_date_2.index == two_months_after)
|
| 605 |
]
|
| 606 |
|
| 607 |
# Display the filtered DataFrames
|
|
|
|
| 609 |
st.write(df_nucmonitor_filtered)
|
| 610 |
st.write(f"Forecast update {past_date_str}")
|
| 611 |
st.write(df_photo_date_filtered)
|
|
|
|
| 612 |
current_forecast_update = df_nucmonitor_filtered.tolist()
|
| 613 |
past_forecast_update = df_photo_date_filtered.tolist()
|
| 614 |
delta = [current - past for current, past in zip(current_forecast_update, past_forecast_update)]
|
| 615 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 616 |
# Create a DataFrame for display
|
| 617 |
+
data = {
|
| 618 |
+
'Dates': [two_months_before, one_month_before, current_date_str, one_month_after, two_months_after],
|
| 619 |
f"Forecast update {current_date_str}": current_forecast_update,
|
| 620 |
f"Forecast update {past_date_str}": past_forecast_update,
|
| 621 |
'Delta': delta
|
| 622 |
}
|
|
|
|
| 623 |
|
| 624 |
+
df_display = pd.DataFrame(data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 625 |
|
| 626 |
# Display the DataFrame as a horizontal table
|
| 627 |
st.write("Table 1. Average expected availability on the French nuclear fleet (MW) - M-1, M, M+1, M+2, M+3")
|
| 628 |
+
st.table(df_display)
|
| 629 |
|
|
|
|
|
|
|
| 630 |
|
| 631 |
# Line charts of the forecasts (need to combine them so they appear in the same chart)
|
| 632 |
st.write("Current forecast")
|
|
|
|
| 639 |
# Slice the DataFrame to include data up until current_date
|
| 640 |
real_forecast = df_nucmonitor_2.loc[df_nucmonitor_2.index <= current_date_str]
|
| 641 |
|
|
|
|
|
|
|
| 642 |
# Optionally, if you want to reset the index
|
| 643 |
# real_forecast = real_forecast.reset_index()
|
| 644 |
print(real_forecast)
|
| 645 |
st.write("Real forecast")
|
| 646 |
st.line_chart(real_forecast)
|
| 647 |
+
|
| 648 |
# Combine dataframes
|
| 649 |
+
combined_df = pd.concat([df_nucmonitor_2, df_photo_date_2, real_forecast], axis=1)
|
| 650 |
+
combined_df.columns = [f'Forecast {current_date_str}', f'Forecast {past_date_str}', 'Real Forecast']
|
| 651 |
|
| 652 |
print(combined_df)
|
| 653 |
st.write(f"Graph 1. {start_date} to {end_date}")
|