Spaces:
Sleeping
Sleeping
Update app/components.py
Browse files- app/components.py +21 -15
app/components.py
CHANGED
@@ -15,7 +15,6 @@ import pandas as pd
|
|
15 |
import numpy as np
|
16 |
import json
|
17 |
import logging
|
18 |
-
import uuid
|
19 |
from typing import Dict, List, Any, Optional, Tuple, Union
|
20 |
from app.m_c_data import DEFAULT_WINDOW_PROPERTIES # Import DEFAULT_WINDOW_PROPERTIES
|
21 |
from app.materials_library import GlazingMaterial # Added import for GlazingMaterial
|
@@ -94,8 +93,8 @@ def migrate_component_types():
|
|
94 |
if comp_type != "floors" and "tilt" in component:
|
95 |
component["surface_tilt"] = component.pop("tilt")
|
96 |
logger.info(f"Renamed 'tilt' to 'surface_tilt' for component '{component['name']}'")
|
97 |
-
# Add adiabatic and ground_contact if not present for walls and floors
|
98 |
-
if comp_type in ["walls", "floors"]:
|
99 |
if "adiabatic" not in component:
|
100 |
component["adiabatic"] = False
|
101 |
logger.info(f"Added 'adiabatic' to component '{component['name']}'")
|
@@ -211,8 +210,8 @@ def display_component_tab(comp_type: str):
|
|
211 |
help="Tilt angle of the component relative to horizontal (0° = horizontal, 90° = vertical)."
|
212 |
)
|
213 |
|
214 |
-
# Adiabatic and Ground Contact for walls and floors
|
215 |
-
if comp_type in ["walls", "floors"]:
|
216 |
adiabatic = st.selectbox(
|
217 |
"Adiabatic",
|
218 |
["Yes", "No"],
|
@@ -341,7 +340,7 @@ def display_component_tab(comp_type: str):
|
|
341 |
component_data["surface_azimuth"] = surface_azimuth
|
342 |
component_data["surface_tilt"] = surface_tilt
|
343 |
|
344 |
-
if comp_type in ["walls", "floors"]:
|
345 |
component_data["adiabatic"] = adiabatic == "Yes"
|
346 |
component_data["ground_contact"] = ground_contact == "Yes"
|
347 |
|
@@ -472,15 +471,17 @@ def display_wall_window_table(comp_type: str, components: List[Dict[str, Any]]):
|
|
472 |
def display_roof_skylight_table(comp_type: str, components: List[Dict[str, Any]]):
|
473 |
"""Display a table of roofs or skylights with appropriate columns."""
|
474 |
# Create column headers
|
475 |
-
cols = st.columns([2, 1, 1, 1, 1, 1, 1] if comp_type == "roofs" else [2, 1, 1, 1, 1, 1, 1, 1])
|
476 |
cols[0].write("**Name**")
|
477 |
cols[1].write("**U-Value**")
|
478 |
cols[2].write("**Area (m²)**")
|
479 |
cols[3].write("**Surface Azimuth (°)**")
|
480 |
cols[4].write("**Surface Tilt (°)**")
|
481 |
if comp_type == "roofs":
|
482 |
-
cols[5].write("**
|
483 |
-
cols[6].write("**
|
|
|
|
|
484 |
else: # skylights
|
485 |
cols[5].write("**SC**")
|
486 |
cols[6].write("**Edit**")
|
@@ -488,18 +489,21 @@ def display_roof_skylight_table(comp_type: str, components: List[Dict[str, Any]]
|
|
488 |
|
489 |
# Display each component
|
490 |
for idx, comp in enumerate(components):
|
491 |
-
cols = st.columns([2, 1, 1, 1, 1, 1, 1] if comp_type == "roofs" else [2, 1, 1, 1, 1, 1, 1, 1])
|
492 |
cols[0].write(comp["name"])
|
493 |
cols[1].write(f"{comp.get('u_value', 0.0):.3f}")
|
494 |
cols[2].write(f"{comp['area']:.2f}")
|
495 |
cols[3].write(f"{comp.get('surface_azimuth', 0.0):.0f}")
|
496 |
cols[4].write(f"{comp.get('surface_tilt', 0.0):.0f}")
|
497 |
-
if comp_type == "
|
|
|
|
|
|
|
498 |
cols[5].write(f"{comp.get('shading_coefficient', 1.0):.2f}")
|
499 |
|
500 |
# Edit button
|
501 |
edit_key = f"edit_{comp_type}_{comp['name']}_{idx}"
|
502 |
-
edit_col =
|
503 |
with cols[edit_col].container():
|
504 |
if st.button("Edit", key=edit_key):
|
505 |
editor_data = {
|
@@ -514,6 +518,8 @@ def display_roof_skylight_table(comp_type: str, components: List[Dict[str, Any]]
|
|
514 |
|
515 |
if comp_type == "roofs":
|
516 |
editor_data["construction"] = comp.get("construction", "")
|
|
|
|
|
517 |
else: # skylights
|
518 |
editor_data["fenestration"] = comp.get("fenestration", "")
|
519 |
editor_data["parent_component"] = comp.get("parent_component", "")
|
@@ -526,7 +532,7 @@ def display_roof_skylight_table(comp_type: str, components: List[Dict[str, Any]]
|
|
526 |
|
527 |
# Delete button
|
528 |
delete_key = f"delete_{comp_type}_{comp['name']}_{idx}"
|
529 |
-
delete_col =
|
530 |
with cols[delete_col].container():
|
531 |
if st.button("Delete", key=delete_key):
|
532 |
st.session_state.project_data["components"][comp_type].pop(idx)
|
@@ -688,8 +694,8 @@ def display_components_help():
|
|
688 |
* **Surface Tilt**: Angle of the component relative to horizontal (0° = horizontal, 90° = vertical).
|
689 |
* **Parent Component**: The wall or roof that contains a window or skylight.
|
690 |
* **Shading Coefficient (SC)**: Factor for shading devices on windows/skylights (0.0 to 1.0).
|
691 |
-
* **Adiabatic**: Indicates if a wall or floor has no heat transfer across it (Yes/No).
|
692 |
-
* **Ground Contact**: Indicates if a wall or floor is in contact with the ground (Yes/No).
|
693 |
|
694 |
**Workflow:**
|
695 |
|
|
|
15 |
import numpy as np
|
16 |
import json
|
17 |
import logging
|
|
|
18 |
from typing import Dict, List, Any, Optional, Tuple, Union
|
19 |
from app.m_c_data import DEFAULT_WINDOW_PROPERTIES # Import DEFAULT_WINDOW_PROPERTIES
|
20 |
from app.materials_library import GlazingMaterial # Added import for GlazingMaterial
|
|
|
93 |
if comp_type != "floors" and "tilt" in component:
|
94 |
component["surface_tilt"] = component.pop("tilt")
|
95 |
logger.info(f"Renamed 'tilt' to 'surface_tilt' for component '{component['name']}'")
|
96 |
+
# Add adiabatic and ground_contact if not present for walls, roofs, and floors
|
97 |
+
if comp_type in ["walls", "roofs", "floors"]:
|
98 |
if "adiabatic" not in component:
|
99 |
component["adiabatic"] = False
|
100 |
logger.info(f"Added 'adiabatic' to component '{component['name']}'")
|
|
|
210 |
help="Tilt angle of the component relative to horizontal (0° = horizontal, 90° = vertical)."
|
211 |
)
|
212 |
|
213 |
+
# Adiabatic and Ground Contact for walls, roofs, and floors
|
214 |
+
if comp_type in ["walls", "roofs", "floors"]:
|
215 |
adiabatic = st.selectbox(
|
216 |
"Adiabatic",
|
217 |
["Yes", "No"],
|
|
|
340 |
component_data["surface_azimuth"] = surface_azimuth
|
341 |
component_data["surface_tilt"] = surface_tilt
|
342 |
|
343 |
+
if comp_type in ["walls", "roofs", "floors"]:
|
344 |
component_data["adiabatic"] = adiabatic == "Yes"
|
345 |
component_data["ground_contact"] = ground_contact == "Yes"
|
346 |
|
|
|
471 |
def display_roof_skylight_table(comp_type: str, components: List[Dict[str, Any]]):
|
472 |
"""Display a table of roofs or skylights with appropriate columns."""
|
473 |
# Create column headers
|
474 |
+
cols = st.columns([2, 1, 1, 1, 1, 1, 1, 1, 1] if comp_type == "roofs" else [2, 1, 1, 1, 1, 1, 1, 1])
|
475 |
cols[0].write("**Name**")
|
476 |
cols[1].write("**U-Value**")
|
477 |
cols[2].write("**Area (m²)**")
|
478 |
cols[3].write("**Surface Azimuth (°)**")
|
479 |
cols[4].write("**Surface Tilt (°)**")
|
480 |
if comp_type == "roofs":
|
481 |
+
cols[5].write("**Adiabatic**")
|
482 |
+
cols[6].write("**Ground Contact**")
|
483 |
+
cols[7].write("**Edit**")
|
484 |
+
cols[8].write("**Delete**")
|
485 |
else: # skylights
|
486 |
cols[5].write("**SC**")
|
487 |
cols[6].write("**Edit**")
|
|
|
489 |
|
490 |
# Display each component
|
491 |
for idx, comp in enumerate(components):
|
492 |
+
cols = st.columns([2, 1, 1, 1, 1, 1, 1, 1, 1] if comp_type == "roofs" else [2, 1, 1, 1, 1, 1, 1, 1])
|
493 |
cols[0].write(comp["name"])
|
494 |
cols[1].write(f"{comp.get('u_value', 0.0):.3f}")
|
495 |
cols[2].write(f"{comp['area']:.2f}")
|
496 |
cols[3].write(f"{comp.get('surface_azimuth', 0.0):.0f}")
|
497 |
cols[4].write(f"{comp.get('surface_tilt', 0.0):.0f}")
|
498 |
+
if comp_type == "roofs":
|
499 |
+
cols[5].write("Yes" if comp.get("adiabatic", False) else "No")
|
500 |
+
cols[6].write("Yes" if comp.get("ground_contact", False) else "No")
|
501 |
+
else: # skylights
|
502 |
cols[5].write(f"{comp.get('shading_coefficient', 1.0):.2f}")
|
503 |
|
504 |
# Edit button
|
505 |
edit_key = f"edit_{comp_type}_{comp['name']}_{idx}"
|
506 |
+
edit_col = 7 if comp_type == "roofs" else 6
|
507 |
with cols[edit_col].container():
|
508 |
if st.button("Edit", key=edit_key):
|
509 |
editor_data = {
|
|
|
518 |
|
519 |
if comp_type == "roofs":
|
520 |
editor_data["construction"] = comp.get("construction", "")
|
521 |
+
editor_data["adiabatic"] = comp.get("adiabatic", False)
|
522 |
+
editor_data["ground_contact"] = comp.get("ground_contact", False)
|
523 |
else: # skylights
|
524 |
editor_data["fenestration"] = comp.get("fenestration", "")
|
525 |
editor_data["parent_component"] = comp.get("parent_component", "")
|
|
|
532 |
|
533 |
# Delete button
|
534 |
delete_key = f"delete_{comp_type}_{comp['name']}_{idx}"
|
535 |
+
delete_col = 8 if comp_type == "roofs" else 7
|
536 |
with cols[delete_col].container():
|
537 |
if st.button("Delete", key=delete_key):
|
538 |
st.session_state.project_data["components"][comp_type].pop(idx)
|
|
|
694 |
* **Surface Tilt**: Angle of the component relative to horizontal (0° = horizontal, 90° = vertical).
|
695 |
* **Parent Component**: The wall or roof that contains a window or skylight.
|
696 |
* **Shading Coefficient (SC)**: Factor for shading devices on windows/skylights (0.0 to 1.0).
|
697 |
+
* **Adiabatic**: Indicates if a wall, roof, or floor has no heat transfer across it (Yes/No).
|
698 |
+
* **Ground Contact**: Indicates if a wall, roof, or floor is in contact with the ground (Yes/No).
|
699 |
|
700 |
**Workflow:**
|
701 |
|