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( | 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.""" |     """Formats the DataFrame for display in the dashboard.""" | ||||||
|     # Create a DataFrame for sites |     # Create a DataFrame for sites | ||||||
| @ -15,6 +15,7 @@ def format_dataframe( | |||||||
|             "Current Load (kW)", |             "Current Load (kW)", | ||||||
|             "SoC (%)", |             "SoC (%)", | ||||||
|             "Predicted Swap Time", |             "Predicted Swap Time", | ||||||
|  |             "Estimated Time To Swap", | ||||||
|             "Cycle Discharge Profile", |             "Cycle Discharge Profile", | ||||||
|             "Load Profile Since Start", |             "Load Profile Since Start", | ||||||
|         ] |         ] | ||||||
| @ -26,6 +27,12 @@ def format_dataframe( | |||||||
|         current_load = bess_data["units"][index]["current_load_kW"] |         current_load = bess_data["units"][index]["current_load_kW"] | ||||||
|         unit_name = bess_data["units"][index]["name"] |         unit_name = bess_data["units"][index]["name"] | ||||||
|         predicted_swap_time = swap_time.get(unit_name, "N/A") |         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 |         # convert predicted_swap_time to a readable format | ||||||
|         if isinstance(predicted_swap_time, float): |         if isinstance(predicted_swap_time, float): | ||||||
|             predicted_swap_time = pd.to_datetime( |             predicted_swap_time = pd.to_datetime( | ||||||
| @ -43,6 +50,7 @@ def format_dataframe( | |||||||
|                             "Current Load (kW)": current_load, |                             "Current Load (kW)": current_load, | ||||||
|                             "SoC (%)": soc * 100,  # Convert to percentage |                             "SoC (%)": soc * 100,  # Convert to percentage | ||||||
|                             "Predicted Swap Time": predicted_swap_time, |                             "Predicted Swap Time": predicted_swap_time, | ||||||
|  |                             "Estimated Time To Swap": estimated_time_to_swap, | ||||||
|                             "Cycle Discharge Profile": bess_soc_for_cycle[unit_name][ |                             "Cycle Discharge Profile": bess_soc_for_cycle[unit_name][ | ||||||
|                                 "SoC" |                                 "SoC" | ||||||
|                             ].tolist(), |                             ].tolist(), | ||||||
|  | |||||||
| @ -91,6 +91,13 @@ if st.session_state.running: | |||||||
|             "%Y-%m-%d %H:%M:%S" |             "%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( |     st.metric( | ||||||
|         "Time Elapsed in DD:HH:MM:SS", |         "Time Elapsed in DD:HH:MM:SS", | ||||||
|         value=str(pd.to_timedelta(main.sim_i * main.dt, unit="s")), |         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 |             # format data for display | ||||||
|             status_df = format_dataframe( |             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 |             # small sleep to allow dashboard to refresh / release GIL | ||||||
|             time.sleep(0.1) |             time.sleep(0.01) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| ### <<< CONTROL ADDED >>> Control functions | ### <<< CONTROL ADDED >>> Control functions | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user