mabuseif commited on
Commit
70d983b
verified
1 Parent(s): fc68faa

Update app/materials_library.py

Browse files
Files changed (1) hide show
  1. app/materials_library.py +87 -37
app/materials_library.py CHANGED
@@ -78,11 +78,16 @@ class Material:
78
  return 0.0
79
 
80
  class GlazingMaterial:
81
- def __init__(self, name: str, shgc: float, u_value: float, h_o: float, is_library: bool = True):
 
 
82
  self.name = name
83
  self.shgc = shgc
84
  self.u_value = u_value
85
  self.h_o = h_o
 
 
 
86
  self.is_library = is_library
87
 
88
  class MaterialLibrary:
@@ -117,7 +122,10 @@ class MaterialLibrary:
117
  "Name": g.name,
118
  "SHGC": g.shgc,
119
  "U-Value (W/m虏路K)": g.u_value,
120
- "Exterior Conductance (W/m虏路K)": g.h_o
 
 
 
121
  }
122
  for g in project_glazing_materials.values()
123
  ]
@@ -625,36 +633,23 @@ def display_fenestrations_tab(material_library: MaterialLibrary):
625
  if raw_fenestrations:
626
  st.write("Raw fenestration names available in session state:")
627
  st.write(list(raw_fenestrations.keys()))
628
- cols = st.columns([2, 1, 1, 1, 1])
629
  cols[0].write("**Name**")
630
  cols[1].write("**SHGC**")
631
  cols[2].write("**U-Value (W/m虏路K)**")
632
- cols[3].write("**Preview**")
633
- cols[4].write("**Clone**")
 
 
634
  for fenestration in library_fenestrations:
635
- cols = st.columns([2, 1, 1, 1, 1])
636
  cols[0].write(fenestration.name)
637
  cols[1].write(f"{fenestration.shgc:.2f}")
638
  cols[2].write(f"{fenestration.u_value:.3f}")
639
- if cols[3].button("Preview", key=f"preview_lib_fen_{fenestration.name}"):
640
- if st.session_state.get("rerun_trigger") != f"preview_fen_{fenestration.name}":
641
- st.session_state.rerun_trigger = f"preview_fen_{fenestration.name}"
642
- st.session_state.fenestration_editor = {
643
- "name": fenestration.name,
644
- "shgc": fenestration.shgc,
645
- "u_value": fenestration.u_value,
646
- "h_o": fenestration.h_o,
647
- "is_edit": False,
648
- "edit_source": "library"
649
- }
650
- st.session_state.fenestration_form_state = {
651
- "name": fenestration.name,
652
- "shgc": fenestration.shgc,
653
- "u_value": fenestration.u_value,
654
- "h_o": fenestration.h_o
655
- }
656
- st.session_state.active_tab = "Fenestrations"
657
- if cols[4].button("Clone", key=f"copy_lib_fen_{fenestration.name}"):
658
  new_name = f"{fenestration.name}_Project"
659
  counter = 1
660
  while new_name in st.session_state.project_data["fenestrations"]["project"] or new_name in st.session_state.project_data["fenestrations"]["library"]:
@@ -665,6 +660,9 @@ def display_fenestrations_tab(material_library: MaterialLibrary):
665
  shgc=fenestration.shgc,
666
  u_value=fenestration.u_value,
667
  h_o=fenestration.h_o,
 
 
 
668
  is_library=False
669
  )
670
  st.session_state.project_data["fenestrations"]["project"][new_name] = new_fenestration
@@ -674,18 +672,24 @@ def display_fenestrations_tab(material_library: MaterialLibrary):
674
  st.subheader("Project Fenestrations")
675
  with st.container():
676
  if st.session_state.project_data["fenestrations"]["project"]:
677
- cols = st.columns([2, 1, 1, 1, 1])
678
  cols[0].write("**Name**")
679
  cols[1].write("**SHGC**")
680
  cols[2].write("**U-Value (W/m虏路K)**")
681
- cols[3].write("**Edit**")
682
- cols[4].write("**Delete**")
 
 
 
683
  for fenestration in st.session_state.project_data["fenestrations"]["project"].values():
684
- cols = st.columns([2, 1, 1, 1, 1])
685
  cols[0].write(fenestration.name)
686
  cols[1].write(f"{fenestration.shgc:.2f}")
687
  cols[2].write(f"{fenestration.u_value:.3f}")
688
- if cols[3].button("Edit", key=f"edit_fen_{fenestration.name}"):
 
 
 
689
  if st.session_state.get("rerun_trigger") != f"edit_fen_{fenestration.name}":
690
  st.session_state.rerun_trigger = f"edit_fen_{fenestration.name}"
691
  st.session_state.fenestration_editor = {
@@ -693,6 +697,9 @@ def display_fenestrations_tab(material_library: MaterialLibrary):
693
  "shgc": fenestration.shgc,
694
  "u_value": fenestration.u_value,
695
  "h_o": fenestration.h_o,
 
 
 
696
  "is_edit": True,
697
  "edit_source": "project",
698
  "original_name": fenestration.name
@@ -700,11 +707,14 @@ def display_fenestrations_tab(material_library: MaterialLibrary):
700
  st.session_state.fenestration_form_state = {
701
  "name": fenestration.name,
702
  "shgc": fenestration.shgc,
703
- "d": fenestration.u_value,
704
- "h_o": fenestration.h_o
 
 
 
705
  }
706
  st.session_state.active_tab = "Fenestrations"
707
- if cols[4].button("Delete", key=f"delete_fen_{fenestration.name}"):
708
  if any(comp.get("fenestration_material") and comp["fenestration_material"].name == fenestration.name
709
  for comp_list in st.session_state.get("components", {}).values() for comp in comp_list):
710
  st.error(f"Fenestration '{fenestration.name}' is used in components and cannot be deleted.")
@@ -727,7 +737,10 @@ def display_fenestrations_tab(material_library: MaterialLibrary):
727
  "Name": f.name,
728
  "SHGC": f.shgc,
729
  "U-Value (W/m虏路K)": f.u_value,
730
- "Exterior Conductance (W/m虏路K)": f.h_o
 
 
 
731
  }
732
  for f in st.session_state.project_data["fenestrations"]["project"].values()
733
  ]
@@ -751,7 +764,10 @@ def display_fenestrations_tab(material_library: MaterialLibrary):
751
  "name": "",
752
  "shgc": 0.7,
753
  "u_value": 5.0,
754
- "h_o": DEFAULT_WINDOW_PROPERTIES["h_o"]
 
 
 
755
  })
756
  is_edit = editor_state.get("is_edit", False)
757
  original_name = editor_state.get("original_name", "")
@@ -783,6 +799,28 @@ def display_fenestrations_tab(material_library: MaterialLibrary):
783
  help="Exterior surface heat transfer coefficient",
784
  key="fenestration_h_o_input"
785
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
786
 
787
  if st.form_submit_button("Save Fenestration"):
788
  action_id = str(uuid.uuid4())
@@ -792,7 +830,10 @@ def display_fenestrations_tab(material_library: MaterialLibrary):
792
  "name": name,
793
  "shgc": shgc,
794
  "u_value": u_value,
795
- "h_o": h_o
 
 
 
796
  }
797
  if not name or not name.strip():
798
  st.error("Fenestration name cannot be empty.")
@@ -806,10 +847,16 @@ def display_fenestrations_tab(material_library: MaterialLibrary):
806
  shgc=shgc,
807
  u_value=u_value,
808
  h_o=h_o,
 
 
 
809
  is_library=False
810
  )
811
  if is_edit and editor_state.get("edit_source") == "project":
812
  st.session_state.project_data["fenestrations"]["project"][original_name] = new_fenestration
 
 
 
813
  st.success(f"Fenestration '{name}' updated successfully!")
814
  else:
815
  st.session_state.project_data["fenestrations"]["project"][name] = new_fenestration
@@ -819,7 +866,10 @@ def display_fenestrations_tab(material_library: MaterialLibrary):
819
  "name": "",
820
  "shgc": 0.7,
821
  "u_value": 5.0,
822
- "h_o": DEFAULT_WINDOW_PROPERTIES["h_o"]
 
 
 
823
  }
824
  st.session_state.fenestration_action = {"action": None, "id": None}
825
  st.session_state.rerun_trigger = None
 
78
  return 0.0
79
 
80
  class GlazingMaterial:
81
+ def __init__(self, name: str, shgc: float, u_value: float, h_o: float,
82
+ visible_transmittance: float, embodied_carbon: float, price: float,
83
+ is_library: bool = True):
84
  self.name = name
85
  self.shgc = shgc
86
  self.u_value = u_value
87
  self.h_o = h_o
88
+ self.visible_transmittance = visible_transmittance
89
+ self.embodied_carbon = embodied_carbon
90
+ self.price = price
91
  self.is_library = is_library
92
 
93
  class MaterialLibrary:
 
122
  "Name": g.name,
123
  "SHGC": g.shgc,
124
  "U-Value (W/m虏路K)": g.u_value,
125
+ "Exterior Conductance (W/m虏路K)": g.h_o,
126
+ "Visible Transmittance": g.visible_transmittance,
127
+ "Embodied Carbon (kgCO鈧俥/m虏)": g.embodied_carbon,
128
+ "Price (USD/m虏)": g.price
129
  }
130
  for g in project_glazing_materials.values()
131
  ]
 
633
  if raw_fenestrations:
634
  st.write("Raw fenestration names available in session state:")
635
  st.write(list(raw_fenestrations.keys()))
636
+ cols = st.columns([2, 1, 1, 1, 1, 1, 1])
637
  cols[0].write("**Name**")
638
  cols[1].write("**SHGC**")
639
  cols[2].write("**U-Value (W/m虏路K)**")
640
+ cols[3].write("**Vis. Trans.**")
641
+ cols[4].write("**Embodied Carbon**")
642
+ cols[5].write("**Price**")
643
+ cols[6].write("**Clone**")
644
  for fenestration in library_fenestrations:
645
+ cols = st.columns([2, 1, 1, 1, 1, 1, 1])
646
  cols[0].write(fenestration.name)
647
  cols[1].write(f"{fenestration.shgc:.2f}")
648
  cols[2].write(f"{fenestration.u_value:.3f}")
649
+ cols[3].write(f"{fenestration.visible_transmittance:.2f}")
650
+ cols[4].write(f"{fenestration.embodied_carbon:.2f}")
651
+ cols[5].write(f"{fenestration.price:.2f}")
652
+ if cols[6].button("Clone", key=f"copy_lib_fen_{fenestration.name}"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
653
  new_name = f"{fenestration.name}_Project"
654
  counter = 1
655
  while new_name in st.session_state.project_data["fenestrations"]["project"] or new_name in st.session_state.project_data["fenestrations"]["library"]:
 
660
  shgc=fenestration.shgc,
661
  u_value=fenestration.u_value,
662
  h_o=fenestration.h_o,
663
+ visible_transmittance=fenestration.visible_transmittance,
664
+ embodied_carbon=fenestration.embodied_carbon,
665
+ price=fenestration.price,
666
  is_library=False
667
  )
668
  st.session_state.project_data["fenestrations"]["project"][new_name] = new_fenestration
 
672
  st.subheader("Project Fenestrations")
673
  with st.container():
674
  if st.session_state.project_data["fenestrations"]["project"]:
675
+ cols = st.columns([2, 1, 1, 1, 1, 1, 1, 1])
676
  cols[0].write("**Name**")
677
  cols[1].write("**SHGC**")
678
  cols[2].write("**U-Value (W/m虏路K)**")
679
+ cols[3].write("**Vis. Trans.**")
680
+ cols[4].write("**Embodied Carbon**")
681
+ cols[5].write("**Price**")
682
+ cols[6].write("**Edit**")
683
+ cols[7].write("**Delete**")
684
  for fenestration in st.session_state.project_data["fenestrations"]["project"].values():
685
+ cols = st.columns([2, 1, 1, 1, 1, 1, 1, 1])
686
  cols[0].write(fenestration.name)
687
  cols[1].write(f"{fenestration.shgc:.2f}")
688
  cols[2].write(f"{fenestration.u_value:.3f}")
689
+ cols[3].write(f"{fenestration.visible_transmittance:.2f}")
690
+ cols[4].write(f"{fenestration.embodied_carbon:.2f}")
691
+ cols[5].write(f"{fenestration.price:.2f}")
692
+ if cols[6].button("Edit", key=f"edit_fen_{fenestration.name}"):
693
  if st.session_state.get("rerun_trigger") != f"edit_fen_{fenestration.name}":
694
  st.session_state.rerun_trigger = f"edit_fen_{fenestration.name}"
695
  st.session_state.fenestration_editor = {
 
697
  "shgc": fenestration.shgc,
698
  "u_value": fenestration.u_value,
699
  "h_o": fenestration.h_o,
700
+ "visible_transmittance": fenestration.visible_transmittance,
701
+ "embodied_carbon": fenestration.embodied_carbon,
702
+ "price": fenestration.price,
703
  "is_edit": True,
704
  "edit_source": "project",
705
  "original_name": fenestration.name
 
707
  st.session_state.fenestration_form_state = {
708
  "name": fenestration.name,
709
  "shgc": fenestration.shgc,
710
+ "u_value": fenestration.u_value,
711
+ "h_o": fenestration.h_o,
712
+ "visible_transmittance": fenestration.visible_transmittance,
713
+ "embodied_carbon": fenestration.embodied_carbon,
714
+ "price": fenestration.price
715
  }
716
  st.session_state.active_tab = "Fenestrations"
717
+ if cols[7].button("Delete", key=f"delete_fen_{fenestration.name}"):
718
  if any(comp.get("fenestration_material") and comp["fenestration_material"].name == fenestration.name
719
  for comp_list in st.session_state.get("components", {}).values() for comp in comp_list):
720
  st.error(f"Fenestration '{fenestration.name}' is used in components and cannot be deleted.")
 
737
  "Name": f.name,
738
  "SHGC": f.shgc,
739
  "U-Value (W/m虏路K)": f.u_value,
740
+ "Exterior Conductance (W/m虏路K)": f.h_o,
741
+ "Visible Transmittance": f.visible_transmittance,
742
+ "Embodied Carbon (kgCO鈧俥/m虏)": f.embodied_carbon,
743
+ "Price (USD/m虏)": f.price
744
  }
745
  for f in st.session_state.project_data["fenestrations"]["project"].values()
746
  ]
 
764
  "name": "",
765
  "shgc": 0.7,
766
  "u_value": 5.0,
767
+ "h_o": DEFAULT_WINDOW_PROPERTIES["h_o"],
768
+ "visible_transmittance": 0.7,
769
+ "embodied_carbon": 25.0,
770
+ "price": 100.0
771
  })
772
  is_edit = editor_state.get("is_edit", False)
773
  original_name = editor_state.get("original_name", "")
 
799
  help="Exterior surface heat transfer coefficient",
800
  key="fenestration_h_o_input"
801
  )
802
+ visible_transmittance = st.number_input(
803
+ "Visible Transmittance",
804
+ min_value=0.0,
805
+ max_value=1.0,
806
+ value=form_state.get("visible_transmittance", editor_state.get("visible_transmittance", 0.7)),
807
+ help="Fraction of visible light transmitted",
808
+ key="fenestration_visible_transmittance_input"
809
+ )
810
+ embodied_carbon = st.number_input(
811
+ "Embodied Carbon (kgCO鈧俥/m虏)",
812
+ min_value=0.0,
813
+ value=form_state.get("embodied_carbon", editor_state.get("embodied_carbon", 25.0)),
814
+ help="Production carbon emissions per square meter",
815
+ key="fenestration_embodied_carbon_input"
816
+ )
817
+ price = st.number_input(
818
+ "Price (USD/m虏)",
819
+ min_value=0.0,
820
+ value=form_state.get("price", editor_state.get("price", 100.0)),
821
+ help="Cost per area",
822
+ key="fenestration_price_input"
823
+ )
824
 
825
  if st.form_submit_button("Save Fenestration"):
826
  action_id = str(uuid.uuid4())
 
830
  "name": name,
831
  "shgc": shgc,
832
  "u_value": u_value,
833
+ "h_o": h_o,
834
+ "visible_transmittance": visible_transmittance,
835
+ "embodied_carbon": embodied_carbon,
836
+ "price": price
837
  }
838
  if not name or not name.strip():
839
  st.error("Fenestration name cannot be empty.")
 
847
  shgc=shgc,
848
  u_value=u_value,
849
  h_o=h_o,
850
+ visible_transmittance=visible_transmittance,
851
+ embodied_carbon=embodied_carbon,
852
+ price=price,
853
  is_library=False
854
  )
855
  if is_edit and editor_state.get("edit_source") == "project":
856
  st.session_state.project_data["fenestrations"]["project"][original_name] = new_fenestration
857
+ if name != original_name:
858
+ del st.session_state.project_data["fenestrations"]["project"][original_name]
859
+ st.session_state.project_data["fenestrations"]["project"][name] = new_fenestration
860
  st.success(f"Fenestration '{name}' updated successfully!")
861
  else:
862
  st.session_state.project_data["fenestrations"]["project"][name] = new_fenestration
 
866
  "name": "",
867
  "shgc": 0.7,
868
  "u_value": 5.0,
869
+ "h_o": DEFAULT_WINDOW_PROPERTIES["h_o"],
870
+ "visible_transmittance": 0.7,
871
+ "embodied_carbon": 25.0,
872
+ "price": 100.0
873
  }
874
  st.session_state.fenestration_action = {"action": None, "id": None}
875
  st.session_state.rerun_trigger = None