mabuseif commited on
Commit
e607ccc
·
verified ·
1 Parent(s): a675c5f

Update app/component_selection.py

Browse files
Files changed (1) hide show
  1. app/component_selection.py +47 -20
app/component_selection.py CHANGED
@@ -65,7 +65,7 @@ class BuildingComponent:
65
  @dataclass
66
  class Wall(BuildingComponent):
67
  wall_type: str = "Brick"
68
- wall_group: str = "Wall"
69
  absorptivity: float = 0.6
70
  shading_coefficient: float = 1.0
71
  infiltration_rate_cfm: float = 0.0
@@ -79,6 +79,11 @@ class Wall(BuildingComponent):
79
  raise ValueError("Shading coefficient must be between 0 and 1")
80
  if self.infiltration_rate_cfm < 0:
81
  raise ValueError("Infiltration rate cannot be negative")
 
 
 
 
 
82
 
83
  def to_dict(self) -> dict:
84
  base_dict = super().to_dict()
@@ -91,7 +96,7 @@ class Wall(BuildingComponent):
91
  @dataclass
92
  class Roof(BuildingComponent):
93
  roof_type: str = "Concrete"
94
- roof_group: str = "C"
95
  slope: str = "Flat"
96
  absorptivity: float = 0.6
97
 
@@ -102,6 +107,11 @@ class Roof(BuildingComponent):
102
  self.orientation = Orientation.HORIZONTAL
103
  if not 0 <= self.absorptivity <= 1:
104
  raise ValueError("Absorptivity must be between 0 and 1")
 
 
 
 
 
105
 
106
  def to_dict(self) -> dict:
107
  base_dict = super().to_dict()
@@ -185,20 +195,20 @@ class ReferenceData:
185
  "Wood": {"conductivity": 0.15}
186
  },
187
  "wall_types": {
188
- "Brick Wall": {"u_value": 2.0, "absorptivity": 0.6},
189
- "Insulated Brick": {"u_value": 0.5, "absorptivity": 0.6},
190
- "Concrete Block": {"u_value": 1.8, "absorptivity": 0.6},
191
- "Insulated Concrete": {"u_value": 0.4, "absorptivity": 0.6},
192
- "Timber Frame": {"u_value": 0.3, "absorptivity": 0.6},
193
- "Cavity Brick": {"u_value": 0.6, "absorptivity": 0.6},
194
- "Lightweight Panel": {"u_value": 1.0, "absorptivity": 0.6},
195
- "Reinforced Concrete": {"u_value": 1.5, "absorptivity": 0.6},
196
- "SIP": {"u_value": 0.25, "absorptivity": 0.6},
197
- "Custom": {"u_value": 0.5, "absorptivity": 0.6}
198
  },
199
  "roof_types": {
200
- "Concrete Roof": {"u_value": 0.3, "absorptivity": 0.6, "group": "C"},
201
- "Metal Roof": {"u_value": 1.0, "absorptivity": 0.75, "group": "B"}
202
  },
203
  "roof_ventilation_methods": {
204
  "No Ventilation": 0.0,
@@ -331,6 +341,7 @@ class ComponentSelectionInterface:
331
  wall_options = self.reference_data.data["wall_types"]
332
  selected_wall = st.selectbox("Wall Type", options=list(wall_options.keys()))
333
  u_value = st.number_input("U-Value (W/m²·K)", min_value=0.0, value=float(wall_options[selected_wall]["u_value"]), step=0.01)
 
334
  absorptivity = st.selectbox("Solar Absorptivity", ["Light (0.3)", "Light to Medium (0.45)", "Medium (0.6)", "Medium to Dark (0.75)", "Dark (0.9)"], index=2)
335
  shading_coefficient = st.number_input("Shading Coefficient", min_value=0.0, max_value=1.0, value=1.0, step=0.05)
336
  infiltration_rate = st.number_input("Infiltration Rate (CFM)", min_value=0.0, value=0.0, step=0.1)
@@ -341,7 +352,7 @@ class ComponentSelectionInterface:
341
  absorptivity_value = float(absorptivity.split("(")[1].strip(")"))
342
  new_wall = Wall(
343
  name=name, u_value=u_value, area=area, orientation=Orientation(orientation),
344
- wall_type=selected_wall, wall_group="Wall", absorptivity=absorptivity_value,
345
  shading_coefficient=shading_coefficient, infiltration_rate_cfm=infiltration_rate
346
  )
347
  self.component_library.add_component(new_wall)
@@ -358,16 +369,24 @@ class ComponentSelectionInterface:
358
  elif method == "File Upload":
359
  uploaded_file = st.file_uploader("Upload Walls File", type=["csv", "xlsx"], key="wall_upload")
360
  required_cols = ["Name", "Area (m²)", "U-Value (W/m²·K)", "Orientation", "Wall Type", "Wall Group", "Absorptivity", "Shading Coefficient", "Infiltration Rate (CFM)"]
361
- st.download_button(label="Download Wall Template", data=pd.DataFrame(columns=required_cols).to_csv(index=False), file_name="wall_template.csv", mime="text/csv")
 
 
 
362
  if uploaded_file:
363
  df = pd.read_csv(uploaded_file) if uploaded_file.name.endswith('.csv') else pd.read_excel(uploaded_file)
364
  if all(col in df.columns for col in required_cols):
 
365
  for _, row in df.iterrows():
366
  try:
 
 
 
 
367
  new_wall = Wall(
368
  name=str(row["Name"]), u_value=float(row["U-Value (W/m²·K)"]), area=float(row["Area (m²)"]),
369
  orientation=Orientation(row["Orientation"]), wall_type=str(row["Wall Type"]),
370
- wall_group=str(row["Wall Group"]), absorptivity=float(row["Absorptivity"]),
371
  shading_coefficient=float(row["Shading Coefficient"]), infiltration_rate_cfm=float(row["Infiltration Rate (CFM)"])
372
  )
373
  self.component_library.add_component(new_wall)
@@ -406,7 +425,7 @@ class ComponentSelectionInterface:
406
  roof_options = self.reference_data.data["roof_types"]
407
  selected_roof = st.selectbox("Roof Type", options=list(roof_options.keys()))
408
  u_value = st.number_input("U-Value (W/m²·K)", min_value=0.0, value=float(roof_options[selected_roof]["u_value"]), step=0.01)
409
- roof_group = st.selectbox("Roof Group", ["A", "B", "C", "D", "E", "F", "G"], index=2)
410
  slope = st.selectbox("Slope", ["Flat", "Pitched"], index=0)
411
  absorptivity = st.selectbox("Solar Absorptivity", ["Light (0.3)", "Light to Medium (0.45)", "Medium (0.6)", "Medium to Dark (0.75)", "Dark (0.9)"], index=2)
412
 
@@ -432,16 +451,24 @@ class ComponentSelectionInterface:
432
  elif method == "File Upload":
433
  uploaded_file = st.file_uploader("Upload Roofs File", type=["csv", "xlsx"], key="roof_upload")
434
  required_cols = ["Name", "Area (m²)", "U-Value (W/m²·K)", "Orientation", "Roof Type", "Roof Group", "Slope", "Absorptivity"]
435
- st.download_button(label="Download Roof Template", data=pd.DataFrame(columns=required_cols).to_csv(index=False), file_name="roof_template.csv", mime="text/csv")
 
 
 
436
  if uploaded_file:
437
  df = pd.read_csv(uploaded_file) if uploaded_file.name.endswith('.csv') else pd.read_excel(uploaded_file)
438
  if all(col in df.columns for col in required_cols):
 
439
  for _, row in df.iterrows():
440
  try:
 
 
 
 
441
  new_roof = Roof(
442
  name=str(row["Name"]), u_value=float(row["U-Value (W/m²·K)"]), area=float(row["Area (m²)"]),
443
  orientation=Orientation(row["Orientation"]), roof_type=str(row["Roof Type"]),
444
- roof_group=str(row["Roof Group"]), slope=str(row["Slope"]), absorptivity=float(row["Absorptivity"])
445
  )
446
  self.component_library.add_component(new_roof)
447
  session_state.components['roofs'].append(new_roof)
 
65
  @dataclass
66
  class Wall(BuildingComponent):
67
  wall_type: str = "Brick"
68
+ wall_group: str = "A" # Changed default to valid ASHRAE group
69
  absorptivity: float = 0.6
70
  shading_coefficient: float = 1.0
71
  infiltration_rate_cfm: float = 0.0
 
79
  raise ValueError("Shading coefficient must be between 0 and 1")
80
  if self.infiltration_rate_cfm < 0:
81
  raise ValueError("Infiltration rate cannot be negative")
82
+ # Validate wall_group
83
+ VALID_WALL_GROUPS = {"A", "B", "C", "D", "E", "F", "G", "H"}
84
+ if self.wall_group not in VALID_WALL_GROUPS:
85
+ st.warning(f"Invalid wall_group '{self.wall_group}' for wall '{self.name}'. Defaulting to 'A'.")
86
+ self.wall_group = "A"
87
 
88
  def to_dict(self) -> dict:
89
  base_dict = super().to_dict()
 
96
  @dataclass
97
  class Roof(BuildingComponent):
98
  roof_type: str = "Concrete"
99
+ roof_group: str = "1" # Changed default to valid ASHRAE group
100
  slope: str = "Flat"
101
  absorptivity: float = 0.6
102
 
 
107
  self.orientation = Orientation.HORIZONTAL
108
  if not 0 <= self.absorptivity <= 1:
109
  raise ValueError("Absorptivity must be between 0 and 1")
110
+ # Validate roof_group
111
+ VALID_ROOF_GROUPS = {"1", "2", "3", "4", "5", "6", "7", "8"}
112
+ if self.roof_group not in VALID_ROOF_GROUPS:
113
+ st.warning(f"Invalid roof_group '{self.roof_group}' for roof '{self.name}'. Defaulting to '1'.")
114
+ self.roof_group = "1"
115
 
116
  def to_dict(self) -> dict:
117
  base_dict = super().to_dict()
 
195
  "Wood": {"conductivity": 0.15}
196
  },
197
  "wall_types": {
198
+ "Brick Wall": {"u_value": 2.0, "absorptivity": 0.6, "wall_group": "A"},
199
+ "Insulated Brick": {"u_value": 0.5, "absorptivity": 0.6, "wall_group": "B"},
200
+ "Concrete Block": {"u_value": 1.8, "absorptivity": 0.6, "wall_group": "C"},
201
+ "Insulated Concrete": {"u_value": 0.4, "absorptivity": 0.6, "wall_group": "D"},
202
+ "Timber Frame": {"u_value": 0.3, "absorptivity": 0.6, "wall_group": "E"},
203
+ "Cavity Brick": {"u_value": 0.6, "absorptivity": 0.6, "wall_group": "F"},
204
+ "Lightweight Panel": {"u_value": 1.0, "absorptivity": 0.6, "wall_group": "G"},
205
+ "Reinforced Concrete": {"u_value": 1.5, "absorptivity": 0.6, "wall_group": "H"},
206
+ "SIP": {"u_value": 0.25, "absorptivity": 0.6, "wall_group": "A"},
207
+ "Custom": {"u_value": 0.5, "absorptivity": 0.6, "wall_group": "A"}
208
  },
209
  "roof_types": {
210
+ "Concrete Roof": {"u_value": 0.3, "absorptivity": 0.6, "group": "1"},
211
+ "Metal Roof": {"u_value": 1.0, "absorptivity": 0.75, "group": "2"}
212
  },
213
  "roof_ventilation_methods": {
214
  "No Ventilation": 0.0,
 
341
  wall_options = self.reference_data.data["wall_types"]
342
  selected_wall = st.selectbox("Wall Type", options=list(wall_options.keys()))
343
  u_value = st.number_input("U-Value (W/m²·K)", min_value=0.0, value=float(wall_options[selected_wall]["u_value"]), step=0.01)
344
+ wall_group = st.selectbox("Wall Group (ASHRAE)", ["A", "B", "C", "D", "E", "F", "G", "H"], index=0)
345
  absorptivity = st.selectbox("Solar Absorptivity", ["Light (0.3)", "Light to Medium (0.45)", "Medium (0.6)", "Medium to Dark (0.75)", "Dark (0.9)"], index=2)
346
  shading_coefficient = st.number_input("Shading Coefficient", min_value=0.0, max_value=1.0, value=1.0, step=0.05)
347
  infiltration_rate = st.number_input("Infiltration Rate (CFM)", min_value=0.0, value=0.0, step=0.1)
 
352
  absorptivity_value = float(absorptivity.split("(")[1].strip(")"))
353
  new_wall = Wall(
354
  name=name, u_value=u_value, area=area, orientation=Orientation(orientation),
355
+ wall_type=selected_wall, wall_group=wall_group, absorptivity=absorptivity_value,
356
  shading_coefficient=shading_coefficient, infiltration_rate_cfm=infiltration_rate
357
  )
358
  self.component_library.add_component(new_wall)
 
369
  elif method == "File Upload":
370
  uploaded_file = st.file_uploader("Upload Walls File", type=["csv", "xlsx"], key="wall_upload")
371
  required_cols = ["Name", "Area (m²)", "U-Value (W/m²·K)", "Orientation", "Wall Type", "Wall Group", "Absorptivity", "Shading Coefficient", "Infiltration Rate (CFM)"]
372
+ # Provide template with valid wall_group values
373
+ template_data = pd.DataFrame(columns=required_cols)
374
+ template_data.loc[0] = ["Example Wall", 10.0, 2.0, "North", "Brick Wall", "A", 0.6, 1.0, 0.0]
375
+ st.download_button(label="Download Wall Template", data=template_data.to_csv(index=False), file_name="wall_template.csv", mime="text/csv")
376
  if uploaded_file:
377
  df = pd.read_csv(uploaded_file) if uploaded_file.name.endswith('.csv') else pd.read_excel(uploaded_file)
378
  if all(col in df.columns for col in required_cols):
379
+ valid_wall_groups = {"A", "B", "C", "D", "E", "F", "G", "H"}
380
  for _, row in df.iterrows():
381
  try:
382
+ wall_group = str(row["Wall Group"])
383
+ if wall_group not in valid_wall_groups:
384
+ st.warning(f"Invalid Wall Group '{wall_group}' in row '{row['Name']}'. Defaulting to 'A'.")
385
+ wall_group = "A"
386
  new_wall = Wall(
387
  name=str(row["Name"]), u_value=float(row["U-Value (W/m²·K)"]), area=float(row["Area (m²)"]),
388
  orientation=Orientation(row["Orientation"]), wall_type=str(row["Wall Type"]),
389
+ wall_group=wall_group, absorptivity=float(row["Absorptivity"]),
390
  shading_coefficient=float(row["Shading Coefficient"]), infiltration_rate_cfm=float(row["Infiltration Rate (CFM)"])
391
  )
392
  self.component_library.add_component(new_wall)
 
425
  roof_options = self.reference_data.data["roof_types"]
426
  selected_roof = st.selectbox("Roof Type", options=list(roof_options.keys()))
427
  u_value = st.number_input("U-Value (W/m²·K)", min_value=0.0, value=float(roof_options[selected_roof]["u_value"]), step=0.01)
428
+ roof_group = st.selectbox("Roof Group (ASHRAE)", ["1", "2", "3", "4", "5", "6", "7", "8"], index=0)
429
  slope = st.selectbox("Slope", ["Flat", "Pitched"], index=0)
430
  absorptivity = st.selectbox("Solar Absorptivity", ["Light (0.3)", "Light to Medium (0.45)", "Medium (0.6)", "Medium to Dark (0.75)", "Dark (0.9)"], index=2)
431
 
 
451
  elif method == "File Upload":
452
  uploaded_file = st.file_uploader("Upload Roofs File", type=["csv", "xlsx"], key="roof_upload")
453
  required_cols = ["Name", "Area (m²)", "U-Value (W/m²·K)", "Orientation", "Roof Type", "Roof Group", "Slope", "Absorptivity"]
454
+ # Provide template with valid roof_group values
455
+ template_data = pd.DataFrame(columns=required_cols)
456
+ template_data.loc[0] = ["Example Roof", 10.0, 0.3, "Horizontal", "Concrete Roof", "1", "Flat", 0.6]
457
+ st.download_button(label="Download Roof Template", data=template_data.to_csv(index=False), file_name="roof_template.csv", mime="text/csv")
458
  if uploaded_file:
459
  df = pd.read_csv(uploaded_file) if uploaded_file.name.endswith('.csv') else pd.read_excel(uploaded_file)
460
  if all(col in df.columns for col in required_cols):
461
+ valid_roof_groups = {"1", "2", "3", "4", "5", "6", "7", "8"}
462
  for _, row in df.iterrows():
463
  try:
464
+ roof_group = str(row["Roof Group"])
465
+ if roof_group not in valid_roof_groups:
466
+ st.warning(f"Invalid Roof Group '{roof_group}' in row '{row['Name']}'. Defaulting to '1'.")
467
+ roof_group = "1"
468
  new_roof = Roof(
469
  name=str(row["Name"]), u_value=float(row["U-Value (W/m²·K)"]), area=float(row["Area (m²)"]),
470
  orientation=Orientation(row["Orientation"]), roof_type=str(row["Roof Type"]),
471
+ roof_group=roof_group, slope=str(row["Slope"]), absorptivity=float(row["Absorptivity"])
472
  )
473
  self.component_library.add_component(new_roof)
474
  session_state.components['roofs'].append(new_roof)