mabuseif commited on
Commit
43c9a20
·
verified ·
1 Parent(s): 887386e

Update app/building_info_form.py

Browse files
Files changed (1) hide show
  1. app/building_info_form.py +38 -18
app/building_info_form.py CHANGED
@@ -66,7 +66,6 @@ class BuildingInfoForm:
66
  if key not in session_state["building_info"]:
67
  session_state["building_info"][key] = default_value
68
 
69
- # Track if data is saved
70
  if "data_saved" not in session_state:
71
  session_state["data_saved"] = False
72
 
@@ -131,6 +130,8 @@ class BuildingInfoForm:
131
  help="Enter the total floor area of the building in square meters (optional if width and depth provided)"
132
  )
133
 
 
 
134
  col1, col2 = st.columns(2)
135
  with col1:
136
  session_state["building_info"]["width"] = st.number_input(
@@ -149,6 +150,7 @@ class BuildingInfoForm:
149
  help="Enter the building's depth in meters (optional if area provided)"
150
  )
151
 
 
152
  session_state["building_info"]["orientation"] = st.selectbox(
153
  "Building Orientation",
154
  ["NORTH", "NORTHEAST", "EAST", "SOUTHEAST", "SOUTH", "SOUTHWEST", "WEST", "NORTHWEST"],
@@ -156,6 +158,7 @@ class BuildingInfoForm:
156
  help="Select the direction of the building's main facade"
157
  )
158
 
 
159
  session_state["building_info"]["operating_hours"] = st.text_input(
160
  "Operating Hours",
161
  value=session_state["building_info"]["operating_hours"],
@@ -165,26 +168,44 @@ class BuildingInfoForm:
165
  submitted = st.form_submit_button("Save Building Information")
166
 
167
  if submitted:
168
- # Logic for handling dimensions
169
- if session_state["building_info"]["width"] > 0 and session_state["building_info"]["depth"] > 0:
170
- calculated_area = session_state["building_info"]["width"] * session_state["building_info"]["depth"]
171
- # If no area provided or area is 0, use calculated area
172
- if session_state["building_info"]["floor_area"] == 0:
173
- session_state["building_info"]["floor_area"] = calculated_area
174
- # If area is provided, keep it (overrides calculated)
175
-
176
- total_volume = session_state["building_info"]["floor_area"] * session_state["building_info"]["building_height"]
177
-
178
- st.success("Building information saved successfully!")
179
- st.info(f"Total Floor Area: {session_state['building_info']['floor_area']:.1f} m²")
180
- st.info(f"Total Building Volume: {total_volume:.1f} m³")
181
- session_state["data_saved"] = True
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
 
183
- # Separate proceed button outside form
184
  if session_state["data_saved"]:
185
  if st.button("Proceed to Climate Data"):
186
  session_state["page"] = "Climate Data"
187
- session_state["data_saved"] = False # Reset for next use
 
 
 
188
 
189
  @staticmethod
190
  def validate_building_info(building_info: Dict[str, Any]) -> Tuple[bool, List[str]]:
@@ -198,7 +219,6 @@ class BuildingInfoForm:
198
  valid = False
199
  errors.append(f"Missing required field: {field}")
200
 
201
- # Must have either area or both width and depth
202
  if building_info.get("floor_area", 0) <= 0 and (building_info.get("width", 0) <= 0 or building_info.get("depth", 0) <= 0):
203
  valid = False
204
  errors.append("Must provide either floor area or both width and depth dimensions")
 
66
  if key not in session_state["building_info"]:
67
  session_state["building_info"][key] = default_value
68
 
 
69
  if "data_saved" not in session_state:
70
  session_state["data_saved"] = False
71
 
 
130
  help="Enter the total floor area of the building in square meters (optional if width and depth provided)"
131
  )
132
 
133
+ st.markdown("OR") # Added OR between area and width/depth
134
+
135
  col1, col2 = st.columns(2)
136
  with col1:
137
  session_state["building_info"]["width"] = st.number_input(
 
150
  help="Enter the building's depth in meters (optional if area provided)"
151
  )
152
 
153
+ st.subheader("Building Orientation") # Changed to subheader
154
  session_state["building_info"]["orientation"] = st.selectbox(
155
  "Building Orientation",
156
  ["NORTH", "NORTHEAST", "EAST", "SOUTHEAST", "SOUTH", "SOUTHWEST", "WEST", "NORTHWEST"],
 
158
  help="Select the direction of the building's main facade"
159
  )
160
 
161
+ st.subheader("Operating Hours") # Changed to subheader
162
  session_state["building_info"]["operating_hours"] = st.text_input(
163
  "Operating Hours",
164
  value=session_state["building_info"]["operating_hours"],
 
168
  submitted = st.form_submit_button("Save Building Information")
169
 
170
  if submitted:
171
+ # Validate before saving
172
+ valid, errors = self.validate_building_info(session_state["building_info"])
173
+ if not valid:
174
+ for error in errors:
175
+ st.error(error)
176
+ else:
177
+ # Logic for handling dimensions
178
+ if session_state["building_info"]["width"] > 0 and session_state["building_info"]["depth"] > 0:
179
+ calculated_area = session_state["building_info"]["width"] * session_state["building_info"]["depth"]
180
+ # If no area provided or area is 0, use calculated area
181
+ if session_state["building_info"]["floor_area"] == 0:
182
+ session_state["building_info"]["floor_area"] = calculated_area
183
+ # If area is provided, keep it
184
+
185
+ total_volume = session_state["building_info"]["floor_area"] * session_state["building_info"]["building_height"]
186
+
187
+ # Store results in session state to persist across rerenders
188
+ session_state["save_results"] = {
189
+ "success": "Building information saved successfully!",
190
+ "area": f"Total Floor Area: {session_state['building_info']['floor_area']:.1f} m²",
191
+ "volume": f"Total Building Volume: {total_volume:.1f} m³"
192
+ }
193
+ session_state["data_saved"] = True
194
+
195
+ # Display saved results if they exist
196
+ if "save_results" in session_state and session_state["data_saved"]:
197
+ st.success(session_state["save_results"]["success"])
198
+ st.info(session_state["save_results"]["area"])
199
+ st.info(session_state["save_results"]["volume"])
200
 
201
+ # Separate proceed button
202
  if session_state["data_saved"]:
203
  if st.button("Proceed to Climate Data"):
204
  session_state["page"] = "Climate Data"
205
+ # Clear saved state to reset form
206
+ if "save_results" in session_state:
207
+ del session_state["save_results"]
208
+ session_state["data_saved"] = False
209
 
210
  @staticmethod
211
  def validate_building_info(building_info: Dict[str, Any]) -> Tuple[bool, List[str]]:
 
219
  valid = False
220
  errors.append(f"Missing required field: {field}")
221
 
 
222
  if building_info.get("floor_area", 0) <= 0 and (building_info.get("width", 0) <= 0 or building_info.get("depth", 0) <= 0):
223
  valid = False
224
  errors.append("Must provide either floor area or both width and depth dimensions")