mabuseif commited on
Commit
9e6373d
·
verified ·
1 Parent(s): b8bf292

Update app/main.py

Browse files
Files changed (1) hide show
  1. app/main.py +13 -17
app/main.py CHANGED
@@ -201,23 +201,29 @@ class HVACCalculator:
201
  if not any(components.get(key, []) for key in ['walls', 'roofs', 'windows', 'skylights']):
202
  return False, "At least one wall, roof, window, or skylight must be defined."
203
 
204
- # Validate climate data using climate_data.py
205
  if not climate_data:
206
  return False, "Climate data is missing."
207
  if not self.climate_data.validate_climate_data(climate_data):
208
  return False, "Invalid climate data format or values."
209
 
210
- # Fix stale components with invalid groups
211
  for component_type in ['walls', 'roofs']:
212
  for comp in components.get(component_type, []):
213
  if component_type == 'walls':
214
- if getattr(comp, 'wall_group', '') not in VALID_WALL_GROUPS:
215
- st.warning(f"Invalid wall group '{comp.wall_group}' for {comp.name}. Setting to 'A'.")
 
216
  comp.wall_group = 'A'
 
 
217
  if component_type == 'roofs':
218
- if getattr(comp, 'roof_group', '') not in VALID_ROOF_GROUPS:
219
- st.warning(f"Invalid roof group '{comp.roof_group}' for {comp.name}. Setting to 'A'.")
 
220
  comp.roof_group = 'A'
 
 
221
 
222
  # Validate components
223
  for component_type in ['walls', 'roofs', 'windows', 'doors', 'floors', 'skylights']:
@@ -226,17 +232,14 @@ class HVACCalculator:
226
  return False, f"Invalid area for {component_type}: {comp.name}"
227
  if comp.u_value <= 0:
228
  return False, f"Invalid U-value for {component_type}: {comp.name}"
229
- # Validate ground temperature for floors
230
  if component_type == 'floors' and getattr(comp, 'ground_contact', False):
231
  if not -10 <= comp.ground_temperature_c <= 40:
232
  return False, f"Ground temperature for {comp.name} must be between -10°C and 40°C"
233
  if getattr(comp, 'perimeter', 0) < 0:
234
  return False, f"Perimeter for {comp.name} cannot be negative"
235
- # Validate solar absorptivity for walls and roofs
236
  if component_type in ['walls', 'roofs']:
237
  if not 0.1 <= getattr(comp, 'solar_absorptivity', 0.6) <= 1.0:
238
  return False, f"Invalid solar absorptivity for {component_type}: {comp.name} (must be 0.1-1.0)"
239
- # Validate enhanced window/skylight properties
240
  if component_type in ['windows', 'skylights']:
241
  if getattr(comp, 'shgc', 0) <= 0:
242
  return False, f"Invalid SHGC for {component_type}: {comp.name}"
@@ -244,13 +247,6 @@ class HVACCalculator:
244
  return False, f"Glazing type missing for {component_type}: {comp.name}"
245
  if getattr(comp, 'frame_type', None) is None:
246
  return False, f"Frame type missing for {component_type}: {comp.name}"
247
- # Validate wall and roof groups
248
- if component_type == 'walls':
249
- if getattr(comp, 'wall_group', '') not in VALID_WALL_GROUPS:
250
- return False, f"Invalid wall group '{comp.wall_group}' for {comp.name}. Valid groups: {', '.join(VALID_WALL_GROUPS)}"
251
- if component_type == 'roofs':
252
- if getattr(comp, 'roof_group', '') not in VALID_ROOF_GROUPS:
253
- return False, f"Invalid roof group '{comp.roof_group}' for {comp.name}. Valid groups: {', '.join(VALID_ROOF_GROUPS)}"
254
 
255
  # Validate ventilation rate
256
  if building_info.get('ventilation_rate', 0) < 0:
@@ -258,7 +254,7 @@ class HVACCalculator:
258
  if building_info.get('zone_type', '') == 'Custom' and building_info.get('ventilation_rate', 0) == 0:
259
  return False, "Custom ventilation rate must be specified"
260
 
261
- # Validate new inputs from Plan.txt
262
  if not -50 <= building_info.get('winter_temp', -10) <= 20:
263
  return False, "Winter design temperature must be -50 to 20°C"
264
  if not 0 <= building_info.get('outdoor_rh', 50) <= 100:
 
201
  if not any(components.get(key, []) for key in ['walls', 'roofs', 'windows', 'skylights']):
202
  return False, "At least one wall, roof, window, or skylight must be defined."
203
 
204
+ # Validate climate data
205
  if not climate_data:
206
  return False, "Climate data is missing."
207
  if not self.climate_data.validate_climate_data(climate_data):
208
  return False, "Invalid climate data format or values."
209
 
210
+ # Validate and fix component groups
211
  for component_type in ['walls', 'roofs']:
212
  for comp in components.get(component_type, []):
213
  if component_type == 'walls':
214
+ wall_group = str(getattr(comp, 'wall_group', 'A')).upper()
215
+ if wall_group not in VALID_WALL_GROUPS:
216
+ st.warning(f"Invalid wall group '{wall_group}' for {comp.name}. Setting to 'A'.")
217
  comp.wall_group = 'A'
218
+ if st.session_state.get('debug_mode', False):
219
+ st.write(f"Debug: Wall {comp.name} group set to {comp.wall_group}")
220
  if component_type == 'roofs':
221
+ roof_group = str(getattr(comp, 'roof_group', 'A')).upper()
222
+ if roof_group not in VALID_ROOF_GROUPS:
223
+ st.warning(f"Invalid roof group '{roof_group}' for {comp.name}. Setting to 'A'.")
224
  comp.roof_group = 'A'
225
+ if st.session_state.get('debug_mode', False):
226
+ st.write(f"Debug: Roof {comp.name} group set to {comp.roof_group}")
227
 
228
  # Validate components
229
  for component_type in ['walls', 'roofs', 'windows', 'doors', 'floors', 'skylights']:
 
232
  return False, f"Invalid area for {component_type}: {comp.name}"
233
  if comp.u_value <= 0:
234
  return False, f"Invalid U-value for {component_type}: {comp.name}"
 
235
  if component_type == 'floors' and getattr(comp, 'ground_contact', False):
236
  if not -10 <= comp.ground_temperature_c <= 40:
237
  return False, f"Ground temperature for {comp.name} must be between -10°C and 40°C"
238
  if getattr(comp, 'perimeter', 0) < 0:
239
  return False, f"Perimeter for {comp.name} cannot be negative"
 
240
  if component_type in ['walls', 'roofs']:
241
  if not 0.1 <= getattr(comp, 'solar_absorptivity', 0.6) <= 1.0:
242
  return False, f"Invalid solar absorptivity for {component_type}: {comp.name} (must be 0.1-1.0)"
 
243
  if component_type in ['windows', 'skylights']:
244
  if getattr(comp, 'shgc', 0) <= 0:
245
  return False, f"Invalid SHGC for {component_type}: {comp.name}"
 
247
  return False, f"Glazing type missing for {component_type}: {comp.name}"
248
  if getattr(comp, 'frame_type', None) is None:
249
  return False, f"Frame type missing for {component_type}: {comp.name}"
 
 
 
 
 
 
 
250
 
251
  # Validate ventilation rate
252
  if building_info.get('ventilation_rate', 0) < 0:
 
254
  if building_info.get('zone_type', '') == 'Custom' and building_info.get('ventilation_rate', 0) == 0:
255
  return False, "Custom ventilation rate must be specified"
256
 
257
+ # Validate new inputs
258
  if not -50 <= building_info.get('winter_temp', -10) <= 20:
259
  return False, "Winter design temperature must be -50 to 20°C"
260
  if not 0 <= building_info.get('outdoor_rh', 50) <= 100: