estimated time to swap calculation
This commit is contained in:
		
							parent
							
								
									d3dbd9c9f3
								
							
						
					
					
						commit
						7c5d3f5b1d
					
				| @ -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(), | ||||
|  | ||||
| @ -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")), | ||||
|  | ||||
							
								
								
									
										8
									
								
								main.py
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								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 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user