mabuseif commited on
Commit
87ad425
·
verified ·
1 Parent(s): 2ba7782

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +52 -8
main.py CHANGED
@@ -26,7 +26,7 @@ sys.path.append(os.path.dirname(os.path.abspath(__file__)))
26
  from app.intro import display_intro_page
27
  from app.building_information import display_building_info_page
28
  from app.climate_data import display_climate_page
29
- from app.materials_library import display_materials_page
30
  from app.construction import display_construction_page
31
  from app.components import display_components_page
32
  from app.internal_loads import display_internal_loads_page
@@ -73,6 +73,46 @@ class BuildSustain:
73
 
74
  # Initialize project data structure if not set
75
  if 'project_data' not in st.session_state:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  st.session_state.project_data = {
77
  "project_name": "",
78
  "building_info": {
@@ -88,11 +128,11 @@ class BuildSustain:
88
  },
89
  "climate_data": {},
90
  "materials": {
91
- "library": dict(SAMPLE_MATERIALS),
92
  "project": {}
93
  },
94
  "fenestrations": {
95
- "library": dict(SAMPLE_FENESTRATIONS),
96
  "project": {}
97
  },
98
  "constructions": {
@@ -247,12 +287,17 @@ class BuildSustain:
247
  """
248
  # Clear materials library specific states when leaving that page
249
  if previous_page == "Material Library":
250
- # Only clear materials library editor states
251
  keys_to_clear = [
252
- "material_editor",
253
  "fenestration_editor",
254
- "material_saved",
255
- "fenestration_saved"
 
 
 
 
 
256
  ]
257
  for key in keys_to_clear:
258
  if key in st.session_state:
@@ -331,5 +376,4 @@ if __name__ == "__main__":
331
  st.error(f"An error occurred: {str(e)}")
332
  logger.exception("Application error")
333
 
334
-
335
  sys.path.append(os.path.join(os.path.dirname(__file__), 'data'))
 
26
  from app.intro import display_intro_page
27
  from app.building_information import display_building_info_page
28
  from app.climate_data import display_climate_page
29
+ from app.materials_library import display_materials_page, Material, GlazingMaterial, MaterialCategory
30
  from app.construction import display_construction_page
31
  from app.components import display_components_page
32
  from app.internal_loads import display_internal_loads_page
 
73
 
74
  # Initialize project data structure if not set
75
  if 'project_data' not in st.session_state:
76
+ # Initialize materials library with Material objects
77
+ materials_library = {}
78
+ for k, m in SAMPLE_MATERIALS.items():
79
+ try:
80
+ category_str = m["category"].upper().replace("-", "_")
81
+ if category_str not in MaterialCategory.__members__:
82
+ logger.error(f"Invalid category for material {k}: {category_str}")
83
+ continue
84
+ materials_library[k] = Material(
85
+ name=k,
86
+ category=MaterialCategory[category_str],
87
+ conductivity=m["thermal_properties"]["conductivity"],
88
+ density=m["thermal_properties"]["density"],
89
+ specific_heat=m["thermal_properties"]["specific_heat"],
90
+ default_thickness=m["thickness_range"]["default"],
91
+ embodied_carbon=m["embodied_carbon"],
92
+ absorptivity=m.get("absorptivity", DEFAULT_MATERIAL_PROPERTIES["absorptivity"]),
93
+ price=m["cost"]["material"],
94
+ emissivity=m.get("emissivity", DEFAULT_MATERIAL_PROPERTIES["emissivity"]),
95
+ is_library=True
96
+ )
97
+ except (KeyError, ValueError) as e:
98
+ logger.error(f"Error processing material {k}: {str(e)}")
99
+ continue
100
+
101
+ # Initialize fenestrations library with GlazingMaterial objects
102
+ fenestrations_library = {}
103
+ for k, f in SAMPLE_FENESTRATIONS.items():
104
+ try:
105
+ fenestrations_library[k] = GlazingMaterial(
106
+ name=k,
107
+ shgc=f["performance"]["shgc"],
108
+ u_value=f["performance"]["u_value"],
109
+ h_o=f.get("h_o", DEFAULT_WINDOW_PROPERTIES["h_o"]),
110
+ is_library=True
111
+ )
112
+ except KeyError as e:
113
+ logger.error(f"Error processing fenestration {k}: Missing key {e}")
114
+ continue
115
+
116
  st.session_state.project_data = {
117
  "project_name": "",
118
  "building_info": {
 
128
  },
129
  "climate_data": {},
130
  "materials": {
131
+ "library": materials_library,
132
  "project": {}
133
  },
134
  "fenestrations": {
135
+ "library": fenestrations_library,
136
  "project": {}
137
  },
138
  "constructions": {
 
287
  """
288
  # Clear materials library specific states when leaving that page
289
  if previous_page == "Material Library":
290
+ # Clear materials and fenestrations editor states
291
  keys_to_clear = [
292
+ "material_editor",
293
  "fenestration_editor",
294
+ "material_form_state",
295
+ "fenestration_form_state",
296
+ "material_action",
297
+ "fenestration_action",
298
+ "materials_rerun_pending",
299
+ "rerun_trigger",
300
+ "active_tab"
301
  ]
302
  for key in keys_to_clear:
303
  if key in st.session_state:
 
376
  st.error(f"An error occurred: {str(e)}")
377
  logger.exception("Application error")
378
 
 
379
  sys.path.append(os.path.join(os.path.dirname(__file__), 'data'))