mabuseif commited on
Commit
70e6fe9
·
verified ·
1 Parent(s): 625d246

Update app/hvac_loads.py

Browse files
Files changed (1) hide show
  1. app/hvac_loads.py +20 -8
app/hvac_loads.py CHANGED
@@ -20,6 +20,8 @@ from utils.ctf_calculations import CTFCalculator, ComponentType, CTFCoefficients
20
  from utils.solar import SolarCalculations # Import SolarCalculations for SHGC data
21
  from app.m_c_data import SAMPLE_MATERIALS, SAMPLE_FENESTRATIONS, DEFAULT_MATERIAL_PROPERTIES, DEFAULT_WINDOW_PROPERTIES
22
  import plotly.express as px
 
 
23
 
24
  # Configure logging
25
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
@@ -809,7 +811,7 @@ def make_pie(data: Dict[str, float], title: str) -> px.pie:
809
  fig.update_traces(textinfo='percent+label', hoverinfo='label+percent+value')
810
  return fig
811
 
812
- def display_hvac_results_ui(loads: List[Dict[str, Any]]):
813
  """Display HVAC load results with enhanced UI elements in a two-column format."""
814
  st.subheader("HVAC Load Results")
815
 
@@ -943,10 +945,14 @@ def display_hvac_loads_page():
943
  st.header("HVAC Loads")
944
  st.markdown("Configure and calculate HVAC loads for the building.")
945
 
 
 
 
 
946
  # Check for existing results
 
947
  if (st.session_state.project_data.get("hvac_loads", {}).get("cooling", {}).get("hourly") or
948
  st.session_state.project_data.get("hvac_loads", {}).get("heating", {}).get("hourly")):
949
- loads = []
950
  cooling_loads = st.session_state.project_data["hvac_loads"]["cooling"].get("hourly", [])
951
  heating_loads = st.session_state.project_data["hvac_loads"]["heating"].get("hourly", [])
952
  loads.extend(cooling_loads)
@@ -955,7 +961,7 @@ def display_hvac_loads_page():
955
  loads = sorted(loads, key=lambda x: (x["month"], x["day"], x["hour"]))
956
  if loads:
957
  st.info("Displaying previously calculated HVAC load results.")
958
- display_hvac_results_ui(loads)
959
 
960
  # Location Information
961
  st.subheader("Location Information")
@@ -967,7 +973,7 @@ def display_hvac_loads_page():
967
  "Latitude": climate_data.get("location", {}).get("latitude", 0.0),
968
  "Longitude": climate_data.get("location", {}).get("longitude", 0.0),
969
  "Elevation": climate_data.get("location", {}).get("elevation", 0.0),
970
- "Time Zone": climate_data.get("location", {}).get("timezone", 0.0),
971
  "Ground Reflectivity": climate_data.get("ground_reflectivity", 0.2)
972
  }
973
 
@@ -1013,7 +1019,7 @@ def display_hvac_loads_page():
1013
  "Time Zone (UTC offset)",
1014
  min_value=-12.0,
1015
  max_value=14.0,
1016
- value=location_data["Time Zone"],
1017
  step=0.5,
1018
  key="hvac_timezone"
1019
  )
@@ -1178,7 +1184,13 @@ def display_hvac_loads_page():
1178
  hvac_settings=hvac_settings
1179
  )
1180
 
1181
- # Update session state with results
 
 
 
 
 
 
1182
  cooling_loads = [load for load in loads if load["total_cooling"] > 0]
1183
  heating_loads = [load for load in loads if load["total_heating"] > 0]
1184
  st.session_state.project_data["hvac_loads"]["cooling"]["hourly"] = cooling_loads
@@ -1204,8 +1216,8 @@ def display_hvac_loads_page():
1204
  st.session_state.project_data["hvac_loads"]["cooling"]["breakdown"] = cooling_breakdown
1205
  st.session_state.project_data["hvac_loads"]["heating"]["breakdown"] = heating_breakdown
1206
 
1207
- # Display Results UI
1208
- display_hvac_results_ui(loads)
1209
 
1210
  st.success("HVAC loads calculated successfully.")
1211
  logger.info("HVAC loads calculated and stored in session state")
 
20
  from utils.solar import SolarCalculations # Import SolarCalculations for SHGC data
21
  from app.m_c_data import SAMPLE_MATERIALS, SAMPLE_FENESTRATIONS, DEFAULT_MATERIAL_PROPERTIES, DEFAULT_WINDOW_PROPERTIES
22
  import plotly.express as px
23
+ import uuid
24
+ run_id = str(uuid.uuid4())
25
 
26
  # Configure logging
27
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
 
811
  fig.update_traces(textinfo='percent+label', hoverinfo='label+percent+value')
812
  return fig
813
 
814
+ def display_hvac_results_ui(loads: List[Dict[str, Any]], run_id: str = "default"):
815
  """Display HVAC load results with enhanced UI elements in a two-column format."""
816
  st.subheader("HVAC Load Results")
817
 
 
945
  st.header("HVAC Loads")
946
  st.markdown("Configure and calculate HVAC loads for the building.")
947
 
948
+ # Generate a unique run ID for this session
949
+ import uuid
950
+ run_id = str(uuid.uuid4())
951
+
952
  # Check for existing results
953
+ loads = []
954
  if (st.session_state.project_data.get("hvac_loads", {}).get("cooling", {}).get("hourly") or
955
  st.session_state.project_data.get("hvac_loads", {}).get("heating", {}).get("hourly")):
 
956
  cooling_loads = st.session_state.project_data["hvac_loads"]["cooling"].get("hourly", [])
957
  heating_loads = st.session_state.project_data["hvac_loads"]["heating"].get("hourly", [])
958
  loads.extend(cooling_loads)
 
961
  loads = sorted(loads, key=lambda x: (x["month"], x["day"], x["hour"]))
962
  if loads:
963
  st.info("Displaying previously calculated HVAC load results.")
964
+ display_hvac_results_ui(loads, run_id=run_id)
965
 
966
  # Location Information
967
  st.subheader("Location Information")
 
973
  "Latitude": climate_data.get("location", {}).get("latitude", 0.0),
974
  "Longitude": climate_data.get("location", {}).get("longitude", 0.0),
975
  "Elevation": climate_data.get("location", {}).get("elevation", 0.0),
976
+ "Time Zone": climate_data.get("location", {}).get("timezone", "UTC"),
977
  "Ground Reflectivity": climate_data.get("ground_reflectivity", 0.2)
978
  }
979
 
 
1019
  "Time Zone (UTC offset)",
1020
  min_value=-12.0,
1021
  max_value=14.0,
1022
+ value=float(location_data["Time Zone"]) if isinstance(location_data["Time Zone"], (int, float, str)) else 0.0,
1023
  step=0.5,
1024
  key="hvac_timezone"
1025
  )
 
1184
  hvac_settings=hvac_settings
1185
  )
1186
 
1187
+ # Clear previous HVAC loads from session state
1188
+ st.session_state.project_data["hvac_loads"] = {
1189
+ "cooling": {"hourly": [], "peak": 0, "charts": {}, "breakdown": {}},
1190
+ "heating": {"hourly": [], "peak": 0, "charts": {}, "breakdown": {}}
1191
+ }
1192
+
1193
+ # Update session state with new results
1194
  cooling_loads = [load for load in loads if load["total_cooling"] > 0]
1195
  heating_loads = [load for load in loads if load["total_heating"] > 0]
1196
  st.session_state.project_data["hvac_loads"]["cooling"]["hourly"] = cooling_loads
 
1216
  st.session_state.project_data["hvac_loads"]["cooling"]["breakdown"] = cooling_breakdown
1217
  st.session_state.project_data["hvac_loads"]["heating"]["breakdown"] = heating_breakdown
1218
 
1219
+ # Display Results UI with unique run_id
1220
+ display_hvac_results_ui(loads, run_id=run_id)
1221
 
1222
  st.success("HVAC loads calculated successfully.")
1223
  logger.info("HVAC loads calculated and stored in session state")