Spaces:
Sleeping
Sleeping
Update app/hvac_loads.py
Browse files- app/hvac_loads.py +23 -16
app/hvac_loads.py
CHANGED
@@ -1151,23 +1151,30 @@ def display_hvac_loads_page():
|
|
1151 |
"""
|
1152 |
Display the HVAC Loads page in the Streamlit application.
|
1153 |
Checks for existing results in session state before recalculating.
|
|
|
1154 |
"""
|
1155 |
try:
|
1156 |
st.header("HVAC Loads")
|
1157 |
st.markdown("Configure and calculate HVAC loads for the building.")
|
1158 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1159 |
# Generate a unique run ID for this session
|
1160 |
-
import uuid
|
1161 |
run_id = str(uuid.uuid4())
|
1162 |
|
1163 |
# Check for existing results
|
1164 |
loads = []
|
1165 |
-
if
|
1166 |
-
|
1167 |
-
|
1168 |
-
|
1169 |
-
|
1170 |
-
|
1171 |
# Sort loads by month, day, hour to ensure consistent display
|
1172 |
loads = sorted(loads, key=lambda x: (x["month"], x["day"], x["hour"]))
|
1173 |
if loads:
|
@@ -1560,6 +1567,12 @@ def display_hvac_loads_page():
|
|
1560 |
logger.error("HVAC calculation failed: No building components defined")
|
1561 |
return
|
1562 |
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
1563 |
loads = TFMCalculations.calculate_tfm_loads(
|
1564 |
components=components,
|
1565 |
hourly_data=hourly_data,
|
@@ -1570,12 +1583,6 @@ def display_hvac_loads_page():
|
|
1570 |
hvac_settings=hvac_settings
|
1571 |
)
|
1572 |
|
1573 |
-
# Clear previous HVAC loads from session state
|
1574 |
-
st.session_state.project_data["hvac_loads"] = {
|
1575 |
-
"cooling": {"hourly": [], "peak": 0, "charts": {}, "breakdown": {}},
|
1576 |
-
"heating": {"hourly": [], "peak": 0, "charts": {}, "breakdown": {}}
|
1577 |
-
}
|
1578 |
-
|
1579 |
# Update session state with new results
|
1580 |
cooling_loads = [load for load in loads if load["total_cooling"] > 0]
|
1581 |
heating_loads = [load for load in loads if load["total_heating"] > 0]
|
@@ -1597,9 +1604,9 @@ def display_hvac_loads_page():
|
|
1597 |
"Infiltration Latent": sum(system.get("latent_load", 0.0) for system in st.session_state.project_data["internal_loads"].get("infiltration", []))
|
1598 |
}
|
1599 |
heating_breakdown = {
|
1600 |
-
"
|
1601 |
-
"
|
1602 |
-
"
|
1603 |
}
|
1604 |
st.session_state.project_data["hvac_loads"]["cooling"]["charts"]["pie_by_component"] = cooling_breakdown
|
1605 |
st.session_state.project_data["hvac_loads"]["heating"]["breakdown"] = heating_breakdown
|
|
|
1151 |
"""
|
1152 |
Display the HVAC Loads page in the Streamlit application.
|
1153 |
Checks for existing results in session state before recalculating.
|
1154 |
+
Clears previous results when a new simulation is run.
|
1155 |
"""
|
1156 |
try:
|
1157 |
st.header("HVAC Loads")
|
1158 |
st.markdown("Configure and calculate HVAC loads for the building.")
|
1159 |
|
1160 |
+
# Initialize hvac_loads in project_data if not present
|
1161 |
+
if "hvac_loads" not in st.session_state.project_data:
|
1162 |
+
st.session_state.project_data["hvac_loads"] = {
|
1163 |
+
"cooling": {"hourly": [], "peak": 0, "charts": {}, "breakdown": {}},
|
1164 |
+
"heating": {"hourly": [], "peak": 0, "charts": {}, "breakdown": {}}
|
1165 |
+
}
|
1166 |
+
|
1167 |
# Generate a unique run ID for this session
|
|
|
1168 |
run_id = str(uuid.uuid4())
|
1169 |
|
1170 |
# Check for existing results
|
1171 |
loads = []
|
1172 |
+
if st.session_state.project_data["hvac_loads"]["cooling"]["hourly"] or \
|
1173 |
+
st.session_state.project_data["hvac_loads"]["heating"]["hourly"]:
|
1174 |
+
loads = (
|
1175 |
+
st.session_state.project_data["hvac_loads"]["cooling"]["hourly"] +
|
1176 |
+
st.session_state.project_data["hvac_loads"]["heating"]["hourly"]
|
1177 |
+
)
|
1178 |
# Sort loads by month, day, hour to ensure consistent display
|
1179 |
loads = sorted(loads, key=lambda x: (x["month"], x["day"], x["hour"]))
|
1180 |
if loads:
|
|
|
1567 |
logger.error("HVAC calculation failed: No building components defined")
|
1568 |
return
|
1569 |
else:
|
1570 |
+
# Clear previous HVAC loads before running new simulation
|
1571 |
+
st.session_state.project_data["hvac_loads"] = {
|
1572 |
+
"cooling": {"hourly": [], "peak": 0, "charts": {}, "breakdown": {}},
|
1573 |
+
"heating": {"hourly": [], "peak": 0, "charts": {}, "breakdown": {}}
|
1574 |
+
}
|
1575 |
+
|
1576 |
loads = TFMCalculations.calculate_tfm_loads(
|
1577 |
components=components,
|
1578 |
hourly_data=hourly_data,
|
|
|
1583 |
hvac_settings=hvac_settings
|
1584 |
)
|
1585 |
|
|
|
|
|
|
|
|
|
|
|
|
|
1586 |
# Update session state with new results
|
1587 |
cooling_loads = [load for load in loads if load["total_cooling"] > 0]
|
1588 |
heating_loads = [load for load in loads if load["total_heating"] > 0]
|
|
|
1604 |
"Infiltration Latent": sum(system.get("latent_load", 0.0) for system in st.session_state.project_data["internal_loads"].get("infiltration", []))
|
1605 |
}
|
1606 |
heating_breakdown = {
|
1607 |
+
"Conduction": sum(load["conduction_heating"] for load in heating_loads),
|
1608 |
+
"Ventilation": sum(load["ventilation_heating"] for load in heating_loads),
|
1609 |
+
"Infiltration": sum(load["infiltration_heating"] for load in heating_loads)
|
1610 |
}
|
1611 |
st.session_state.project_data["hvac_loads"]["cooling"]["charts"]["pie_by_component"] = cooling_breakdown
|
1612 |
st.session_state.project_data["hvac_loads"]["heating"]["breakdown"] = heating_breakdown
|