mabuseif commited on
Commit
a796694
verified
1 Parent(s): a5a7e63

Update app/construction.py

Browse files
Files changed (1) hide show
  1. app/construction.py +60 -2
app/construction.py CHANGED
@@ -196,14 +196,72 @@ def display_constructions_tables(construction_library: ConstructionLibrary):
196
  """Display library and project constructions tables."""
197
  st.subheader("Library Constructions")
198
  with st.container():
199
- library_constructions = list(construction_library.library_constructions.items())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200
  cols = st.columns([2, 1, 1, 1, 1])
201
  cols[0].write("**Name**")
202
  cols[1].write("**Thermal Mass Category**")
203
  cols[2].write("**U-Value (W/m虏路K)**")
204
  cols[3].write("**Copy**")
205
  cols[4].write("**Preview**")
206
- for name, construction in library_constructions:
207
  cols = st.columns([2, 1, 1, 1, 1])
208
  cols[0].write(name)
209
  cols[1].write(construction.get("thermal_mass_category", "Low"))
 
196
  """Display library and project constructions tables."""
197
  st.subheader("Library Constructions")
198
  with st.container():
199
+ # Prepare material objects for library materials
200
+ material_objects = {name: m for name, m in get_available_materials().items() if isinstance(m, Material)}
201
+ for name, mat_dict in st.session_state.project_data["materials"]["library"].items():
202
+ if name not in material_objects:
203
+ if "thermal_properties" not in mat_dict:
204
+ st.error(f"Material '{name}' is missing thermal properties")
205
+ logger.error(f"Missing thermal properties for material: {name}")
206
+ continue
207
+ category_str = mat_dict["category"].upper().replace("-", "_")
208
+ if category_str not in MaterialCategory.__members__:
209
+ st.error(f"Invalid category for material {name}: {mat_dict['category']}")
210
+ logger.error(f"Invalid category for material {name}: {mat_dict['category']}")
211
+ continue
212
+ try:
213
+ material_objects[name] = Material(
214
+ name=name,
215
+ category=MaterialCategory[category_str],
216
+ conductivity=mat_dict["thermal_properties"]["conductivity"],
217
+ density=mat_dict["thermal_properties"]["density"],
218
+ specific_heat=mat_dict["thermal_properties"]["specific_heat"],
219
+ default_thickness=mat_dict["thickness_range"]["default"],
220
+ embodied_carbon=mat_dict["embodied_carbon"],
221
+ absorptivity=mat_dict.get("absorptivity", 0.6),
222
+ price=mat_dict["cost"]["material"],
223
+ emissivity=mat_dict.get("emissivity", 0.9),
224
+ is_library=True
225
+ )
226
+ except Exception as e:
227
+ st.error(f"Failed to convert material '{name}' to Material object: {str(e)}")
228
+ logger.error(f"Error converting material {name}: {str(e)}")
229
+ continue
230
+
231
+ # Recalculate properties for library constructions
232
+ display_constructions = {}
233
+ for name, construction in construction_library.library_constructions.items():
234
+ try:
235
+ layers = [{"material": layer["material"], "thickness": layer["thickness"]} for layer in construction["layers"]]
236
+ properties = calculate_construction_properties(layers, material_objects)
237
+ display_constructions[name] = {
238
+ **construction,
239
+ "u_value": properties["u_value"],
240
+ "r_value": properties["r_value"],
241
+ "thermal_mass": properties["thermal_mass"],
242
+ "thermal_mass_category": properties["thermal_mass_category"],
243
+ "embodied_carbon": properties["embodied_carbon"],
244
+ "cost": properties["cost"]
245
+ }
246
+ logger.debug(
247
+ f"Library construction {name}: Static U={construction.get('u_value', 0.0):.3f}, "
248
+ f"Calculated U={properties['u_value']:.3f}, "
249
+ f"Static Thermal Mass Category={construction.get('thermal_mass_category', 'Low')}, "
250
+ f"Calculated Thermal Mass={properties['thermal_mass']:.1f} ({properties['thermal_mass_category']})"
251
+ )
252
+ except Exception as e:
253
+ st.error(f"Error calculating properties for library construction '{name}': {str(e)}")
254
+ logger.error(f"Error calculating properties for {name}: {str(e)}")
255
+ display_constructions[name] = construction # Fallback to original data
256
+
257
+ # Display library constructions
258
  cols = st.columns([2, 1, 1, 1, 1])
259
  cols[0].write("**Name**")
260
  cols[1].write("**Thermal Mass Category**")
261
  cols[2].write("**U-Value (W/m虏路K)**")
262
  cols[3].write("**Copy**")
263
  cols[4].write("**Preview**")
264
+ for name, construction in display_constructions.items():
265
  cols = st.columns([2, 1, 1, 1, 1])
266
  cols[0].write(name)
267
  cols[1].write(construction.get("thermal_mass_category", "Low"))