From 7c5d3f5b1daaa69a8d985beab1952a43929dd9af Mon Sep 17 00:00:00 2001 From: Lucas Tan Date: Sun, 20 Jul 2025 23:07:48 +0100 Subject: [PATCH] estimated time to swap calculation --- Utilities/DataVis.py | 10 +++++++++- dashboard.py | 7 +++++++ main.py | 8 ++++++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Utilities/DataVis.py b/Utilities/DataVis.py index 6f64c6b..6bd3436 100644 --- a/Utilities/DataVis.py +++ b/Utilities/DataVis.py @@ -2,7 +2,7 @@ import pandas as pd def format_dataframe( - bess_soc_for_cycle, bess_data, load_profiles_since_start, swap_time + bess_soc_for_cycle, bess_data, load_profiles_since_start, swap_time, current_time ): """Formats the DataFrame for display in the dashboard.""" # Create a DataFrame for sites @@ -15,6 +15,7 @@ def format_dataframe( "Current Load (kW)", "SoC (%)", "Predicted Swap Time", + "Estimated Time To Swap", "Cycle Discharge Profile", "Load Profile Since Start", ] @@ -26,6 +27,12 @@ def format_dataframe( current_load = bess_data["units"][index]["current_load_kW"] unit_name = bess_data["units"][index]["name"] predicted_swap_time = swap_time.get(unit_name, "N/A") + # calculate estimated time to swap + if isinstance(predicted_swap_time, float): + estimated_time_to_swap = predicted_swap_time - current_time + estimated_time_to_swap = pd.to_timedelta(estimated_time_to_swap, unit="s") + else: + estimated_time_to_swap = "N/A" # convert predicted_swap_time to a readable format if isinstance(predicted_swap_time, float): predicted_swap_time = pd.to_datetime( @@ -43,6 +50,7 @@ def format_dataframe( "Current Load (kW)": current_load, "SoC (%)": soc * 100, # Convert to percentage "Predicted Swap Time": predicted_swap_time, + "Estimated Time To Swap": estimated_time_to_swap, "Cycle Discharge Profile": bess_soc_for_cycle[unit_name][ "SoC" ].tolist(), diff --git a/dashboard.py b/dashboard.py index 734e0f3..61c71be 100644 --- a/dashboard.py +++ b/dashboard.py @@ -91,6 +91,13 @@ if st.session_state.running: "%Y-%m-%d %H:%M:%S" ), ) + st.metric( + "Current Time", + value=pd.to_datetime( + main.c["sim_start_time"] + main.sim_i * main.dt, unit="s" + ).strftime("%Y-%m-%d %H:%M:%S"), + ) + st.metric( "Time Elapsed in DD:HH:MM:SS", value=str(pd.to_timedelta(main.sim_i * main.dt, unit="s")), diff --git a/main.py b/main.py index 6bb3093..613bef4 100644 --- a/main.py +++ b/main.py @@ -122,11 +122,15 @@ def simulation_loop(): # format data for display status_df = format_dataframe( - bess_soc_for_cycle, bess_data, load_profiles_since_start, swap_times + bess_soc_for_cycle, + bess_data, + load_profiles_since_start, + swap_times, + timestamps[i], ) # small sleep to allow dashboard to refresh / release GIL - time.sleep(0.1) + time.sleep(0.01) ### <<< CONTROL ADDED >>> Control functions