dmarr commited on
Commit
5acc1b8
·
1 Parent(s): 993bbcb

Updated with suggestions from JC

Browse files
Files changed (1) hide show
  1. app.py +24 -43
app.py CHANGED
@@ -305,7 +305,7 @@ def nuc_monitor(usr_start_date, usr_end_date, past_date, mongo_db_data):
305
  results_plants = {plant_name: {date: {"available_capacity": power, "updated_date": pd.to_datetime("1970-01-01", utc=True)} for date in dates_of_interest}
306
  for plant_name, power in plants_metadata.items()}
307
 
308
- print(results_sorted)
309
  for plant, unavailabilities in results_sorted.items():
310
  # Get the full power of a given plant according to the sorted results
311
  original_power = plants_metadata[plant]
@@ -398,7 +398,9 @@ def nuc_monitor(usr_start_date, usr_end_date, past_date, mongo_db_data):
398
  # print(results_plants)
399
  # Convert datetime key to string to store in mongodb
400
  output_results = {plant: {str(date): power for date, power in plant_data.items()} for plant, plant_data in output_results.items()}
 
401
  # print(output_results)
 
402
  # -------------------------------------------------
403
 
404
  json_data = json.dumps(output_results)
@@ -457,14 +459,14 @@ def run_app():
457
  # df_winter_date = get_nucmonitor_data(start_date, end_date, winter_date)
458
  current_date_str = str(current_date.strftime('%Y-%m-%d'))
459
  past_date_str = str(past_date.strftime('%Y-%m-%d'))
460
- st.write("Nucmonitor")
461
  st.write(df_nucmonitor) # Display DataFrame
462
 
463
- st.write("Photo Date")
464
  st.write(df_photo_date)
465
 
466
  # Get info on current forecast Nucmonitor
467
- st.title("Total Energy per Day at Current Forecast")
468
 
469
  # Remove the final row 'Total'
470
  df_nucmonitor_2 = df_nucmonitor.iloc[:-1, :]
@@ -476,7 +478,7 @@ def run_app():
476
  st.write(df_nucmonitor_2)
477
 
478
  # Get info on past date forecast Nucmonitor
479
- st.title("Total Energy per Day at Past Date Forecast")
480
 
481
  # Remove the final row 'Total'
482
  df_photo_date_2 = df_photo_date.iloc[:-1, :]
@@ -551,9 +553,9 @@ def run_app():
551
  ]
552
 
553
  # Display the filtered DataFrames
554
- st.write(f"Forecast update {current_date_str}")
555
  st.write(df_nucmonitor_filtered)
556
- st.write(f"Forecast update {past_date_str}")
557
  st.write(df_photo_date_filtered)
558
 
559
  current_forecast_update = df_nucmonitor_filtered.tolist()
@@ -568,8 +570,8 @@ def run_app():
568
  # Create a DataFrame for display
569
  data_avg_expected_normal = {
570
  'Dates': [two_months_before, one_month_before, current_date.strftime('%Y-%m'), one_month_after, two_months_after],
571
- f"Forecast update {current_date_str}": current_forecast_update,
572
- f"Forecast update {past_date_str}": past_forecast_update,
573
  'Delta': delta
574
  }
575
  df_display_normal_bool = True
@@ -643,57 +645,36 @@ def run_app():
643
  st.table(df_display_winter)
644
 
645
  # Line charts of the forecasts (need to combine them so they appear in the same chart)
646
- st.write("Current forecast")
647
  st.line_chart(df_nucmonitor_2)
648
 
649
- st.write("Previous forecast")
650
  st.line_chart(df_photo_date_2)
651
- # Create a new dataframe out of df_nucmonitor_2 call real_forecast that contains df_nucmonitor_2 up until current_date
652
 
653
  # Slice the DataFrame to include data up until current_date
654
- real_forecast = df_nucmonitor_2.loc[df_nucmonitor_2.index <= current_date_str]
655
 
656
  # Winter forecast still not the correct one, this is just a placeholder
657
  # winter_forecast = df_nucmonitor_2.loc[(df_nucmonitor_2.index >= winter_start_date) & (df_nucmonitor_2.index <= winter_end_date)]
658
 
659
  # Optionally, if you want to reset the index
660
- # real_forecast = real_forecast.reset_index()
661
- # print(real_forecast)
662
- st.write("Real forecast")
663
- st.line_chart(real_forecast)
664
 
665
  # Combine dataframes
666
- # combined_df = pd.concat([df_nucmonitor_2, df_photo_date_2, real_forecast, winter_forecast], axis=1)
667
- combined_df = pd.concat([df_nucmonitor_2, df_photo_date_2, real_forecast], axis=1)
668
 
669
- # combined_df.columns = [f'Forecast {current_date_str}', f'Forecast {past_date_str}', 'Real Forecast', f'Winter forecast {winter_start}/{winter_end}']
670
- combined_df.columns = [f'Forecast {current_date_str}', f'Forecast {past_date_str}', 'Real Forecast']
671
 
672
  # print(combined_df)
673
- st.write(f"Graph 1. {start_date} to {end_date}")
674
  st.line_chart(combined_df)
675
 
676
- # # Set Nucmonitor as a dotted line until the current date
677
-
678
- # fig, ax = plt.subplots(figsize=(10, 6))
679
-
680
- # plt.plot(combined_df.index, combined_df[f'Forecast {current_date_str}'], 'r--', label=f'Forecast {current_date_str}')
681
- # plt.plot(combined_df.index, combined_df[f'Forecast {past_date_str}'], 'b-', label=f'Forecast {past_date_str}')
682
-
683
- # plt.axvline(current_date_str, color='k', linestyle='--', linewidth=1, label='Current Date')
684
-
685
- # # Set the x-axis to show only the first day of every month
686
- # ax.xaxis.set_major_locator(MonthLocator(bymonthday=1))
687
-
688
- # plt.legend()
689
-
690
- # plt.xticks(rotation=45)
691
-
692
- # st.pyplot(fig)
693
-
694
- # For Historical Winter Availability, can just get the max and min of each month, store as list in a column, and try to graph that
695
-
696
-
697
  # Add a download button
698
  # Create a BytesIO object to hold the Excel data
699
 
 
305
  results_plants = {plant_name: {date: {"available_capacity": power, "updated_date": pd.to_datetime("1970-01-01", utc=True)} for date in dates_of_interest}
306
  for plant_name, power in plants_metadata.items()}
307
 
308
+ # print(results_sorted)
309
  for plant, unavailabilities in results_sorted.items():
310
  # Get the full power of a given plant according to the sorted results
311
  original_power = plants_metadata[plant]
 
398
  # print(results_plants)
399
  # Convert datetime key to string to store in mongodb
400
  output_results = {plant: {str(date): power for date, power in plant_data.items()} for plant, plant_data in output_results.items()}
401
+ # output_results = pd.DataFrame(output_results)
402
  # print(output_results)
403
+
404
  # -------------------------------------------------
405
 
406
  json_data = json.dumps(output_results)
 
459
  # df_winter_date = get_nucmonitor_data(start_date, end_date, winter_date)
460
  current_date_str = str(current_date.strftime('%Y-%m-%d'))
461
  past_date_str = str(past_date.strftime('%Y-%m-%d'))
462
+ st.write(f"Current View Forecast at {current_date_str} (MW)")
463
  st.write(df_nucmonitor) # Display DataFrame
464
 
465
+ st.write(f"Past View Forecast at {past_date_str}")
466
  st.write(df_photo_date)
467
 
468
  # Get info on current forecast Nucmonitor
469
+ st.write(f"Total Energy per Day at Current View Forecast {current_date_str} (MW)")
470
 
471
  # Remove the final row 'Total'
472
  df_nucmonitor_2 = df_nucmonitor.iloc[:-1, :]
 
478
  st.write(df_nucmonitor_2)
479
 
480
  # Get info on past date forecast Nucmonitor
481
+ st.write(f"Total Energy per Day at Past View Forecast {past_date_str} (MW)")
482
 
483
  # Remove the final row 'Total'
484
  df_photo_date_2 = df_photo_date.iloc[:-1, :]
 
553
  ]
554
 
555
  # Display the filtered DataFrames
556
+ st.write(f"Forecast at {current_date_str} (MW)")
557
  st.write(df_nucmonitor_filtered)
558
+ st.write(f"Forecast at {past_date_str} (MW)")
559
  st.write(df_photo_date_filtered)
560
 
561
  current_forecast_update = df_nucmonitor_filtered.tolist()
 
570
  # Create a DataFrame for display
571
  data_avg_expected_normal = {
572
  'Dates': [two_months_before, one_month_before, current_date.strftime('%Y-%m'), one_month_after, two_months_after],
573
+ f"Forecast update {current_date_str} (MW)": current_forecast_update,
574
+ f"Forecast update {past_date_str} (MW)": past_forecast_update,
575
  'Delta': delta
576
  }
577
  df_display_normal_bool = True
 
645
  st.table(df_display_winter)
646
 
647
  # Line charts of the forecasts (need to combine them so they appear in the same chart)
648
+ st.write("Current forecast (MW)")
649
  st.line_chart(df_nucmonitor_2)
650
 
651
+ st.write("Previous forecast (MW)")
652
  st.line_chart(df_photo_date_2)
653
+ # Create a new dataframe out of df_nucmonitor_2 call real_avail that contains df_nucmonitor_2 up until current_date
654
 
655
  # Slice the DataFrame to include data up until current_date
656
+ real_avail = df_nucmonitor_2.loc[df_nucmonitor_2.index <= current_date_str]
657
 
658
  # Winter forecast still not the correct one, this is just a placeholder
659
  # winter_forecast = df_nucmonitor_2.loc[(df_nucmonitor_2.index >= winter_start_date) & (df_nucmonitor_2.index <= winter_end_date)]
660
 
661
  # Optionally, if you want to reset the index
662
+ # real_avail = real_avail.reset_index()
663
+ # print(real_avail)
664
+ st.write("Observed Historical Availability (MW)")
665
+ st.line_chart(real_avail)
666
 
667
  # Combine dataframes
668
+ # combined_df = pd.concat([df_nucmonitor_2, df_photo_date_2, real_avail, winter_forecast], axis=1)
669
+ combined_df = pd.concat([df_nucmonitor_2, df_photo_date_2, real_avail], axis=1)
670
 
671
+ # combined_df.columns = [f'Forecast {current_date_str}', f'Forecast {past_date_str}', 'Observed Historical Availability', f'Winter forecast {winter_start}/{winter_end}']
672
+ combined_df.columns = [f'Forecast {current_date_str} (MW)', f'Forecast {past_date_str} (MW)', 'Observed Historical Availability (MW)']
673
 
674
  # print(combined_df)
675
+ st.write(f"Graph 1. {start_date} to {end_date} (MW)")
676
  st.line_chart(combined_df)
677
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
678
  # Add a download button
679
  # Create a BytesIO object to hold the Excel data
680