Spaces:
Sleeping
Sleeping
Update app/hvac_loads.py
Browse files- app/hvac_loads.py +20 -22
app/hvac_loads.py
CHANGED
@@ -1150,7 +1150,7 @@ def display_hvac_results_ui(loads: List[Dict[str, Any]], run_id: str = "default"
|
|
1150 |
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")
|
@@ -1160,20 +1160,18 @@ def display_hvac_loads_page():
|
|
1160 |
import uuid
|
1161 |
run_id = str(uuid.uuid4())
|
1162 |
|
1163 |
-
#
|
1164 |
-
if "hvac_loads" not in st.session_state.project_data:
|
1165 |
-
st.session_state.project_data["hvac_loads"] = {}
|
1166 |
-
|
1167 |
-
# Check for existing results for the current run_id
|
1168 |
loads = []
|
1169 |
-
if
|
1170 |
-
|
1171 |
-
|
|
|
1172 |
loads.extend(cooling_loads)
|
1173 |
loads.extend(heating_loads)
|
|
|
1174 |
loads = sorted(loads, key=lambda x: (x["month"], x["day"], x["hour"]))
|
1175 |
if loads:
|
1176 |
-
st.info("Displaying previously calculated HVAC load results
|
1177 |
display_hvac_results_ui(loads, run_id=run_id)
|
1178 |
|
1179 |
# Location Information
|
@@ -1542,7 +1540,7 @@ def display_hvac_loads_page():
|
|
1542 |
st.info("No ground-contact components detected. Ground temperature configuration is not required.")
|
1543 |
|
1544 |
# Calculate HVAC Loads
|
1545 |
-
if st.button("Calculate HVAC Loads"
|
1546 |
try:
|
1547 |
with st.spinner("Running simulation... this may take up to a minute depending on data size."):
|
1548 |
components = st.session_state.project_data["components"]
|
@@ -1572,8 +1570,8 @@ def display_hvac_loads_page():
|
|
1572 |
hvac_settings=hvac_settings
|
1573 |
)
|
1574 |
|
1575 |
-
#
|
1576 |
-
st.session_state.project_data["hvac_loads"]
|
1577 |
"cooling": {"hourly": [], "peak": 0, "charts": {}, "breakdown": {}},
|
1578 |
"heating": {"hourly": [], "peak": 0, "charts": {}, "breakdown": {}}
|
1579 |
}
|
@@ -1581,12 +1579,12 @@ def display_hvac_loads_page():
|
|
1581 |
# Update session state with new results
|
1582 |
cooling_loads = [load for load in loads if load["total_cooling"] > 0]
|
1583 |
heating_loads = [load for load in loads if load["total_heating"] > 0]
|
1584 |
-
st.session_state.project_data["hvac_loads"][
|
1585 |
-
st.session_state.project_data["hvac_loads"][
|
1586 |
-
st.session_state.project_data["hvac_loads"][
|
1587 |
-
st.session_state.project_data["hvac_loads"][
|
1588 |
-
st.session_state.project_data["hvac_loads"][
|
1589 |
-
st.session_state.project_data["hvac_loads"][
|
1590 |
|
1591 |
# Store breakdown
|
1592 |
cooling_breakdown = {
|
@@ -1603,14 +1601,14 @@ def display_hvac_loads_page():
|
|
1603 |
"ventilation": sum(load["ventilation_heating"] for load in heating_loads),
|
1604 |
"infiltration": sum(load["infiltration_heating"] for load in heating_loads)
|
1605 |
}
|
1606 |
-
st.session_state.project_data["hvac_loads"][
|
1607 |
-
st.session_state.project_data["hvac_loads"][
|
1608 |
|
1609 |
# Display Results UI with unique run_id
|
1610 |
display_hvac_results_ui(loads, run_id=run_id)
|
1611 |
|
1612 |
st.success("HVAC loads calculated successfully.")
|
1613 |
-
logger.info(
|
1614 |
|
1615 |
except Exception as e:
|
1616 |
st.error(f"Error calculating HVAC loads: {str(e)}")
|
|
|
1150 |
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")
|
|
|
1160 |
import uuid
|
1161 |
run_id = str(uuid.uuid4())
|
1162 |
|
1163 |
+
# Check for existing results
|
|
|
|
|
|
|
|
|
1164 |
loads = []
|
1165 |
+
if (st.session_state.project_data.get("hvac_loads", {}).get("cooling", {}).get("hourly") or
|
1166 |
+
st.session_state.project_data.get("hvac_loads", {}).get("heating", {}).get("hourly")):
|
1167 |
+
cooling_loads = st.session_state.project_data["hvac_loads"]["cooling"].get("hourly", [])
|
1168 |
+
heating_loads = st.session_state.project_data["hvac_loads"]["heating"].get("hourly", [])
|
1169 |
loads.extend(cooling_loads)
|
1170 |
loads.extend(heating_loads)
|
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:
|
1174 |
+
st.info("Displaying previously calculated HVAC load results.")
|
1175 |
display_hvac_results_ui(loads, run_id=run_id)
|
1176 |
|
1177 |
# Location Information
|
|
|
1540 |
st.info("No ground-contact components detected. Ground temperature configuration is not required.")
|
1541 |
|
1542 |
# Calculate HVAC Loads
|
1543 |
+
if st.button("Calculate HVAC Loads"):
|
1544 |
try:
|
1545 |
with st.spinner("Running simulation... this may take up to a minute depending on data size."):
|
1546 |
components = st.session_state.project_data["components"]
|
|
|
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 |
}
|
|
|
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]
|
1582 |
+
st.session_state.project_data["hvac_loads"]["cooling"]["hourly"] = cooling_loads
|
1583 |
+
st.session_state.project_data["hvac_loads"]["heating"]["hourly"] = heating_loads
|
1584 |
+
st.session_state.project_data["hvac_loads"]["cooling"]["peak"] = max([load["total_cooling"] for load in cooling_loads], default=0)
|
1585 |
+
st.session_state.project_data["hvac_loads"]["heating"]["peak"] = max([load["total_heating"] for load in heating_loads], default=0)
|
1586 |
+
st.session_state.project_data["hvac_loads"]["cooling"]["charts"] = {}
|
1587 |
+
st.session_state.project_data["hvac_loads"]["heating"]["charts"] = {}
|
1588 |
|
1589 |
# Store breakdown
|
1590 |
cooling_breakdown = {
|
|
|
1601 |
"ventilation": sum(load["ventilation_heating"] for load in heating_loads),
|
1602 |
"infiltration": sum(load["infiltration_heating"] for load in heating_loads)
|
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
|
1606 |
|
1607 |
# Display Results UI with unique run_id
|
1608 |
display_hvac_results_ui(loads, run_id=run_id)
|
1609 |
|
1610 |
st.success("HVAC loads calculated successfully.")
|
1611 |
+
logger.info("HVAC loads calculated and stored in session state")
|
1612 |
|
1613 |
except Exception as e:
|
1614 |
st.error(f"Error calculating HVAC loads: {str(e)}")
|