mabuseif commited on
Commit
f079b6d
verified
1 Parent(s): 6e9262a

Update app/materials_library.py

Browse files
Files changed (1) hide show
  1. app/materials_library.py +38 -27
app/materials_library.py CHANGED
@@ -2,7 +2,7 @@
2
  BuildSustain - Material Library Module
3
 
4
  This module handles the material library functionality of the BuildSustain application,
5
- allowing users to manage building materials and fenestrations (windows/skylights, doors).
6
  It provides both predefined library materials and the ability to create project-specific materials.
7
 
8
  Developed by: Dr Majed Abuseif, Deakin University
@@ -17,6 +17,8 @@ import logging
17
  import uuid
18
  from typing import Dict, List, Any, Optional, Tuple, Union
19
  from enum import Enum
 
 
20
  from app.m_c_data import SAMPLE_MATERIALS, SAMPLE_FENESTRATIONS, DEFAULT_MATERIAL_PROPERTIES, DEFAULT_WINDOW_PROPERTIES
21
 
22
  # Configure logging
@@ -238,8 +240,9 @@ def display_materials_page():
238
  emissivity=m.get("emissivity", DEFAULT_MATERIAL_PROPERTIES["emissivity"]),
239
  is_library=True
240
  )
241
- except KeyError as e:
242
- logger.error(f"Error processing material {k}: Missing key {e}")
 
243
  continue
244
 
245
  material_library.library_glazing_materials = {}
@@ -252,6 +255,7 @@ def display_materials_page():
252
  h_o=f.get("h_o", DEFAULT_WINDOW_PROPERTIES["h_o"]),
253
  is_library=True
254
  )
 
255
  except KeyError as e:
256
  logger.error(f"Error processing fenestration {k}: Missing key {e}")
257
  continue
@@ -281,11 +285,13 @@ def initialize_materials_and_fenestrations():
281
  "library": dict(SAMPLE_MATERIALS),
282
  "project": {}
283
  }
 
284
  if "fenestrations" not in st.session_state.project_data:
285
  st.session_state.project_data["fenestrations"] = {
286
  "library": dict(SAMPLE_FENESTRATIONS),
287
  "project": {}
288
  }
 
289
 
290
  def display_materials_tab(material_library: MaterialLibrary):
291
  """Display the materials tab content with two-column layout."""
@@ -299,6 +305,8 @@ def display_materials_tab(material_library: MaterialLibrary):
299
  st.subheader("Library Materials")
300
  with st.container():
301
  library_materials = list(material_library.library_materials.values())
 
 
302
  if category == "None":
303
  library_materials = []
304
  elif category != "All":
@@ -589,18 +597,18 @@ def display_materials_tab(material_library: MaterialLibrary):
589
  "embodied_carbon": 0.5,
590
  "absorptivity": DEFAULT_MATERIAL_PROPERTIES["absorptivity"],
591
  "price": 50.0,
592
- "emissivity": DEFAULT_PROPERTIES["emissivity"]
593
- },
594
- st.session_state.material_action = {"action": None, "material_action_id": None}
595
  st.session_state.rerun_trigger = None
596
  st.session_state.materials_rerun_pending = True
597
  else:
598
  st.error(f"Failed to save material: {message}")
599
  except Exception as e:
600
- st.error("Error saving material: {str(e)}")
601
 
602
  def display_fenestrations_tab(material_library: MaterialLibrary):
603
- """Display the fenestrations tab with two-column layout."""
604
  col1, col2 = st.columns([3, 2])
605
  with col1:
606
  st.subheader("Fenestrations")
@@ -610,14 +618,17 @@ def display_fenestrations_tab(material_library: MaterialLibrary):
610
  st.subheader("Library Fenestrations")
611
  with st.container():
612
  library_fenestrations = list(material_library.library_glazing_materials.values())
613
- if st.session_state["fenestration_filter"] == "None":
 
 
614
  library_fenestrations = []
615
  elif fenestration_filter != "All":
616
- # Map fenestration types for filtering
617
  fen_type = "window" if fenestration_filter == "Window/Skylight" else "door"
618
- library_fenestrations = [f for f in library_fenestrations if
619
- st.session_state.project_data["fenestrations"]["library"][f.name]["type"] == fen_type]
620
- cols = st.columns([2, cols, 1, 1, 1, 1])
 
 
621
  cols[0].write("**Name**")
622
  cols[1].write("**SHGC**")
623
  cols[2].write("**U-Value (W/m虏路K)**")
@@ -626,31 +637,31 @@ def display_fenestrations_tab(material_library: MaterialLibrary):
626
  for fenestration in library_fenestrations:
627
  cols = st.columns([2, 1, 1, 1, 1])
628
  cols[0].write(fenestration.name)
629
- cols[1].write(f"{fenestration_shgc:.2f}")
630
- cols[2].write(f"{fenestration_data.u_value:.3f}")
631
- if cols[3].button("Preview", key=f"preview_fen_btn_{fenestration.name}"):
632
  if st.session_state.get("rerun_trigger") != f"preview_fen_{fenestration.name}":
633
  st.session_state.rerun_trigger = f"preview_fen_{fenestration.name}"
634
  st.session_state.fenestration_editor = {
635
- "name": fenestration_name,
636
- "shgc": fenestration_shgc,
637
  "u_value": fenestration.u_value,
638
- "shgc": fenestration_h_o,
639
  "is_edit": False,
640
- "edit": "library"
641
- },
642
  st.session_state.fenestration_form_state = {
643
  "name": fenestration.name,
644
- "shgc": fenestration_shgc,
645
  "u_value": fenestration.u_value,
646
- "shgc": fenestration_h_o
647
- },
648
  st.session_state.active_tab = "Fenestrations"
649
- if cols[4].button("Clone", key=f"copy_fen_btn_{fenestration.name}"):
650
- new_name = f"{fenestration_name}_Project"
651
  counter = 1
652
  while new_name in st.session_state.project_data["fenestrations"]["project"] or new_name in st.session_state.project_data["fenestrations"]["library"]:
653
- new_name = f"{fenestration_name}_Project_{counter}"
654
  counter += 1
655
  new_fenestration = GlazingMaterial(
656
  name=new_name,
 
2
  BuildSustain - Material Library Module
3
 
4
  This module handles the material library functionality of the BuildSustain application,
5
+ allowing users to manage building materials and fenestrations (windows, skylights, doors).
6
  It provides both predefined library materials and the ability to create project-specific materials.
7
 
8
  Developed by: Dr Majed Abuseif, Deakin University
 
17
  import uuid
18
  from typing import Dict, List, Any, Optional, Tuple, Union
19
  from enum import Enum
20
+
21
+ # Import default data and constants from centralized module
22
  from app.m_c_data import SAMPLE_MATERIALS, SAMPLE_FENESTRATIONS, DEFAULT_MATERIAL_PROPERTIES, DEFAULT_WINDOW_PROPERTIES
23
 
24
  # Configure logging
 
240
  emissivity=m.get("emissivity", DEFAULT_MATERIAL_PROPERTIES["emissivity"]),
241
  is_library=True
242
  )
243
+ logger.debug(f"Loaded material: {k}, Category: {m['category']}")
244
+ except (KeyError, ValueError) as e:
245
+ logger.error(f"Error processing material {k}: {str(e)}")
246
  continue
247
 
248
  material_library.library_glazing_materials = {}
 
255
  h_o=f.get("h_o", DEFAULT_WINDOW_PROPERTIES["h_o"]),
256
  is_library=True
257
  )
258
+ logger.debug(f"Loaded fenestration: {k}, Type: {f['type']}")
259
  except KeyError as e:
260
  logger.error(f"Error processing fenestration {k}: Missing key {e}")
261
  continue
 
285
  "library": dict(SAMPLE_MATERIALS),
286
  "project": {}
287
  }
288
+ logger.info("Initialized materials in session state with SAMPLE_MATERIALS")
289
  if "fenestrations" not in st.session_state.project_data:
290
  st.session_state.project_data["fenestrations"] = {
291
  "library": dict(SAMPLE_FENESTRATIONS),
292
  "project": {}
293
  }
294
+ logger.info("Initialized fenestrations in session state with SAMPLE_FENESTRATIONS")
295
 
296
  def display_materials_tab(material_library: MaterialLibrary):
297
  """Display the materials tab content with two-column layout."""
 
305
  st.subheader("Library Materials")
306
  with st.container():
307
  library_materials = list(material_library.library_materials.values())
308
+ if not library_materials:
309
+ st.warning("No library materials loaded. Check data initialization.")
310
  if category == "None":
311
  library_materials = []
312
  elif category != "All":
 
597
  "embodied_carbon": 0.5,
598
  "absorptivity": DEFAULT_MATERIAL_PROPERTIES["absorptivity"],
599
  "price": 50.0,
600
+ "emissivity": DEFAULT_MATERIAL_PROPERTIES["emissivity"]
601
+ }
602
+ st.session_state.material_action = {"action": None, "id": None}
603
  st.session_state.rerun_trigger = None
604
  st.session_state.materials_rerun_pending = True
605
  else:
606
  st.error(f"Failed to save material: {message}")
607
  except Exception as e:
608
+ st.error(f"Error saving material: {str(e)}")
609
 
610
  def display_fenestrations_tab(material_library: MaterialLibrary):
611
+ """Display the fenestrations tab content with two-column layout."""
612
  col1, col2 = st.columns([3, 2])
613
  with col1:
614
  st.subheader("Fenestrations")
 
618
  st.subheader("Library Fenestrations")
619
  with st.container():
620
  library_fenestrations = list(material_library.library_glazing_materials.values())
621
+ if not library_fenestrations:
622
+ st.warning("No library fenestrations loaded. Check data initialization.")
623
+ if fenestration_filter == "None":
624
  library_fenestrations = []
625
  elif fenestration_filter != "All":
 
626
  fen_type = "window" if fenestration_filter == "Window/Skylight" else "door"
627
+ library_fenestrations = [
628
+ f for f in library_fenestrations
629
+ if st.session_state.project_data["fenestrations"]["library"][f.name]["type"] == fen_type
630
+ ]
631
+ cols = st.columns([2, 1, 1, 1, 1])
632
  cols[0].write("**Name**")
633
  cols[1].write("**SHGC**")
634
  cols[2].write("**U-Value (W/m虏路K)**")
 
637
  for fenestration in library_fenestrations:
638
  cols = st.columns([2, 1, 1, 1, 1])
639
  cols[0].write(fenestration.name)
640
+ cols[1].write(f"{fenestration.shgc:.2f}")
641
+ cols[2].write(f"{fenestration.u_value:.3f}")
642
+ if cols[3].button("Preview", key=f"preview_lib_fen_{fenestration.name}"):
643
  if st.session_state.get("rerun_trigger") != f"preview_fen_{fenestration.name}":
644
  st.session_state.rerun_trigger = f"preview_fen_{fenestration.name}"
645
  st.session_state.fenestration_editor = {
646
+ "name": fenestration.name,
647
+ "shgc": fenestration.shgc,
648
  "u_value": fenestration.u_value,
649
+ "h_o": fenestration.h_o,
650
  "is_edit": False,
651
+ "edit_source": "library"
652
+ }
653
  st.session_state.fenestration_form_state = {
654
  "name": fenestration.name,
655
+ "shgc": fenestration.shgc,
656
  "u_value": fenestration.u_value,
657
+ "h_o": fenestration.h_o
658
+ }
659
  st.session_state.active_tab = "Fenestrations"
660
+ if cols[4].button("Clone", key=f"copy_lib_fen_{fenestration.name}"):
661
+ new_name = f"{fenestration.name}_Project"
662
  counter = 1
663
  while new_name in st.session_state.project_data["fenestrations"]["project"] or new_name in st.session_state.project_data["fenestrations"]["library"]:
664
+ new_name = f"{fenestration.name}_Project_{counter}"
665
  counter += 1
666
  new_fenestration = GlazingMaterial(
667
  name=new_name,