Spaces:
Sleeping
Sleeping
Update app/construction.py
Browse files- app/construction.py +24 -24
app/construction.py
CHANGED
@@ -205,41 +205,41 @@ def display_constructions_tables(construction_library: ConstructionLibrary):
|
|
205 |
|
206 |
st.subheader("Library Constructions")
|
207 |
with st.container():
|
208 |
-
library_constructions = list(construction_library.library_constructions.
|
209 |
if construction_filter != "All":
|
210 |
-
library_constructions = [c for c in library_constructions if c["type"] == construction_filter]
|
211 |
cols = st.columns([2, 1, 1, 1, 1])
|
212 |
cols[0].write("**Name**")
|
213 |
cols[1].write("**Thermal Mass**")
|
214 |
cols[2].write("**U-Value (W/m虏路K)**")
|
215 |
cols[3].write("**Preview**")
|
216 |
cols[4].write("**Copy**")
|
217 |
-
for construction in library_constructions:
|
218 |
cols = st.columns([2, 1, 1, 1, 1])
|
219 |
-
cols[0].write(name)
|
220 |
cols[1].write(f"{construction.get('thermal_mass', 0.0):.1f}")
|
221 |
cols[2].write(f"{construction.get('u_value', 0.0):.3f}")
|
222 |
-
if cols[3].button("Preview", key=f"preview_lib_cons_{
|
223 |
-
if st.session_state.get("rerun_trigger") != f"preview_cons_{
|
224 |
-
st.session_state.rerun_trigger = f"preview_cons_{
|
225 |
st.session_state.construction_editor = {
|
226 |
-
"name":
|
227 |
"component_type": construction["type"],
|
228 |
"layers": [{"material_name": layer["material"], "thickness": layer["thickness"]} for layer in construction["layers"]],
|
229 |
"is_edit": False
|
230 |
}
|
231 |
st.session_state.construction_form_state = {
|
232 |
-
"name":
|
233 |
"component_type": construction["type"],
|
234 |
"num_layers": len(construction["layers"]),
|
235 |
"layers": [{"material_name": layer["material"], "thickness": layer["thickness"]} for layer in construction["layers"]]
|
236 |
}
|
237 |
st.session_state.construction_rerun_pending = True
|
238 |
-
if cols[4].button("Copy", key=f"copy_lib_cons_{
|
239 |
-
new_name = f"{
|
240 |
counter = 1
|
241 |
while new_name in st.session_state.project_data["constructions"]["project"] or new_name in construction_library.library_constructions:
|
242 |
-
new_name = f"{
|
243 |
counter += 1
|
244 |
new_layers = []
|
245 |
material_library = st.session_state.get("material_library", None)
|
@@ -298,9 +298,9 @@ def display_constructions_tables(construction_library: ConstructionLibrary):
|
|
298 |
|
299 |
st.subheader("Project Constructions")
|
300 |
with st.container():
|
301 |
-
project_constructions = list(st.session_state.project_data["constructions"]["project"].
|
302 |
if construction_filter != "All":
|
303 |
-
project_constructions = [c for c in project_constructions if c["type"] == construction_filter]
|
304 |
if project_constructions:
|
305 |
cols = st.columns([2, 1, 1, 1, 1])
|
306 |
cols[0].write("**Name**")
|
@@ -308,31 +308,31 @@ def display_constructions_tables(construction_library: ConstructionLibrary):
|
|
308 |
cols[2].write("**U-Value (W/m虏路K)**")
|
309 |
cols[3].write("**Edit**")
|
310 |
cols[4].write("**Delete**")
|
311 |
-
for construction in project_constructions:
|
312 |
cols = st.columns([2, 1, 1, 1, 1])
|
313 |
-
cols[0].write(name)
|
314 |
cols[1].write(f"{construction.get('thermal_mass', 0.0):.1f}")
|
315 |
cols[2].write(f"{construction.get('u_value', 0.0):.3f}")
|
316 |
-
if cols[3].button("Edit", key=f"edit_proj_cons_{
|
317 |
-
if st.session_state.get("rerun_trigger") != f"edit_cons_{
|
318 |
-
st.session_state.rerun_trigger = f"edit_cons_{
|
319 |
st.session_state.construction_editor = {
|
320 |
-
"name":
|
321 |
"component_type": construction["type"],
|
322 |
"layers": [{"material_name": layer["material"], "thickness": layer["thickness"]} for layer in construction["layers"]],
|
323 |
"is_edit": True,
|
324 |
-
"original_name":
|
325 |
}
|
326 |
st.session_state.construction_form_state = {
|
327 |
-
"name":
|
328 |
"component_type": construction["type"],
|
329 |
"num_layers": len(construction["layers"]),
|
330 |
"layers": [{"material_name": layer["material"], "thickness": layer["thickness"]} for layer in construction["layers"]]
|
331 |
}
|
332 |
st.session_state.construction_rerun_pending = True
|
333 |
-
if cols[4].button("Delete", key=f"delete_proj_cons_{
|
334 |
success, message = construction_library.delete_project_construction(
|
335 |
-
|
336 |
)
|
337 |
if success:
|
338 |
st.success(message)
|
|
|
205 |
|
206 |
st.subheader("Library Constructions")
|
207 |
with st.container():
|
208 |
+
library_constructions = list(construction_library.library_constructions.items()) # Changed to .items()
|
209 |
if construction_filter != "All":
|
210 |
+
library_constructions = [(name, c) for name, c in library_constructions if c["type"] == construction_filter]
|
211 |
cols = st.columns([2, 1, 1, 1, 1])
|
212 |
cols[0].write("**Name**")
|
213 |
cols[1].write("**Thermal Mass**")
|
214 |
cols[2].write("**U-Value (W/m虏路K)**")
|
215 |
cols[3].write("**Preview**")
|
216 |
cols[4].write("**Copy**")
|
217 |
+
for name, construction in library_constructions: # Changed to unpack name and construction
|
218 |
cols = st.columns([2, 1, 1, 1, 1])
|
219 |
+
cols[0].write(name) # Use name directly
|
220 |
cols[1].write(f"{construction.get('thermal_mass', 0.0):.1f}")
|
221 |
cols[2].write(f"{construction.get('u_value', 0.0):.3f}")
|
222 |
+
if cols[3].button("Preview", key=f"preview_lib_cons_{name}"):
|
223 |
+
if st.session_state.get("rerun_trigger") != f"preview_cons_{name}":
|
224 |
+
st.session_state.rerun_trigger = f"preview_cons_{name}"
|
225 |
st.session_state.construction_editor = {
|
226 |
+
"name": name,
|
227 |
"component_type": construction["type"],
|
228 |
"layers": [{"material_name": layer["material"], "thickness": layer["thickness"]} for layer in construction["layers"]],
|
229 |
"is_edit": False
|
230 |
}
|
231 |
st.session_state.construction_form_state = {
|
232 |
+
"name": name,
|
233 |
"component_type": construction["type"],
|
234 |
"num_layers": len(construction["layers"]),
|
235 |
"layers": [{"material_name": layer["material"], "thickness": layer["thickness"]} for layer in construction["layers"]]
|
236 |
}
|
237 |
st.session_state.construction_rerun_pending = True
|
238 |
+
if cols[4].button("Copy", key=f"copy_lib_cons_{name}"):
|
239 |
+
new_name = f"{name}_Project"
|
240 |
counter = 1
|
241 |
while new_name in st.session_state.project_data["constructions"]["project"] or new_name in construction_library.library_constructions:
|
242 |
+
new_name = f"{name}_Project_{counter}"
|
243 |
counter += 1
|
244 |
new_layers = []
|
245 |
material_library = st.session_state.get("material_library", None)
|
|
|
298 |
|
299 |
st.subheader("Project Constructions")
|
300 |
with st.container():
|
301 |
+
project_constructions = list(st.session_state.project_data["constructions"]["project"].items()) # Changed to .items()
|
302 |
if construction_filter != "All":
|
303 |
+
project_constructions = [(name, c) for name, c in project_constructions if c["type"] == construction_filter]
|
304 |
if project_constructions:
|
305 |
cols = st.columns([2, 1, 1, 1, 1])
|
306 |
cols[0].write("**Name**")
|
|
|
308 |
cols[2].write("**U-Value (W/m虏路K)**")
|
309 |
cols[3].write("**Edit**")
|
310 |
cols[4].write("**Delete**")
|
311 |
+
for name, construction in project_constructions: # Changed to unpack name and construction
|
312 |
cols = st.columns([2, 1, 1, 1, 1])
|
313 |
+
cols[0].write(name) # Use name directly
|
314 |
cols[1].write(f"{construction.get('thermal_mass', 0.0):.1f}")
|
315 |
cols[2].write(f"{construction.get('u_value', 0.0):.3f}")
|
316 |
+
if cols[3].button("Edit", key=f"edit_proj_cons_{name}"):
|
317 |
+
if st.session_state.get("rerun_trigger") != f"edit_cons_{name}":
|
318 |
+
st.session_state.rerun_trigger = f"edit_cons_{name}"
|
319 |
st.session_state.construction_editor = {
|
320 |
+
"name": name,
|
321 |
"component_type": construction["type"],
|
322 |
"layers": [{"material_name": layer["material"], "thickness": layer["thickness"]} for layer in construction["layers"]],
|
323 |
"is_edit": True,
|
324 |
+
"original_name": name
|
325 |
}
|
326 |
st.session_state.construction_form_state = {
|
327 |
+
"name": name,
|
328 |
"component_type": construction["type"],
|
329 |
"num_layers": len(construction["layers"]),
|
330 |
"layers": [{"material_name": layer["material"], "thickness": layer["thickness"]} for layer in construction["layers"]]
|
331 |
}
|
332 |
st.session_state.construction_rerun_pending = True
|
333 |
+
if cols[4].button("Delete", key=f"delete_proj_cons_{name}"):
|
334 |
success, message = construction_library.delete_project_construction(
|
335 |
+
name, st.session_state.project_data["constructions"]["project"], st.session_state.project_data.get("components", {})
|
336 |
)
|
337 |
if success:
|
338 |
st.success(message)
|