mabuseif commited on
Commit
59f681c
·
verified ·
1 Parent(s): f5a16fc

Update app/main.py

Browse files
Files changed (1) hide show
  1. app/main.py +54 -18
app/main.py CHANGED
@@ -346,7 +346,7 @@ class HVACCalculator:
346
  "Select Equipment Loads to Delete",
347
  [load['id'] for load in st.session_state.internal_loads['equipment']]
348
  )
349
- if st.button("Delete Selected Equipment Loads"): # Fixed typo
350
  st.session_state.internal_loads['equipment'] = [
351
  load for load in st.session_state.internal_loads['equipment']
352
  if load['id'] not in selected_equipment
@@ -375,6 +375,7 @@ class HVACCalculator:
375
  # Gather inputs
376
  building_components = st.session_state.get('components', {})
377
  internal_loads = st.session_state.get('internal_loads', {})
 
378
  building_info = st.session_state.get('building_info', {})
379
 
380
  # Validate inputs
@@ -382,25 +383,48 @@ class HVACCalculator:
382
  return False, "Floor area is missing in building information.", {}
383
  if not building_components.get('walls') and not building_components.get('roofs') and not building_components.get('windows'):
384
  return False, "No building components defined. Please add walls, roofs, or windows.", {}
 
 
385
 
386
- # Extract climate data using ClimateData.get_location_by_id
 
 
 
 
 
 
 
 
 
 
387
  climate_id = f"{building_info.get('country', 'XX')[:2].upper()}-{building_info.get('city', 'XXX')[:3].upper()}"
388
- location = self.climate_data.get_location_by_id(climate_id, st.session_state)
389
  if not location:
390
  return False, f"No climate data found for {climate_id}. Please provide valid climate data.", {}
391
 
392
  # Validate climate data
393
- if not all(k in location for k in ['summer_design_temp_db', 'summer_design_temp_wb', 'monthly_temps', 'latitude']):
394
- return False, f"Invalid climate data for {climate_id}. Missing required fields.", {}
 
 
 
 
 
 
 
 
 
 
 
395
 
396
  # Format conditions
397
  outdoor_conditions = {
398
- 'temperature': location['summer_design_temp_db'],
399
- 'relative_humidity': location['monthly_humidity'].get('Jul', 50.0),
400
- 'ground_temperature': location['monthly_temps'].get('Jul', 20.0),
401
  'month': 'Jul',
402
- 'latitude': f"{location['latitude']}N" if location['latitude'] >= 0 else f"{abs(location['latitude'])}S",
403
- 'wind_speed': 4.0, # Default as not provided in climate data
404
  'day_of_year': 204 # Approx. July 23
405
  }
406
  indoor_conditions = {
@@ -664,6 +688,7 @@ class HVACCalculator:
664
  # Gather inputs
665
  building_components = st.session_state.get('components', {})
666
  internal_loads = st.session_state.get('internal_loads', {})
 
667
  building_info = st.session_state.get('building_info', {})
668
 
669
  # Validate inputs
@@ -671,23 +696,34 @@ class HVACCalculator:
671
  return False, "Floor area is missing in building information.", {}
672
  if not building_components.get('walls') and not building_components.get('roofs') and not building_components.get('windows'):
673
  return False, "No building components defined. Please add walls, roofs, or windows.", {}
 
 
 
 
 
 
 
 
 
 
 
 
674
 
675
- # Extract climate data using ClimateData.get_location_by_id
676
  climate_id = f"{building_info.get('country', 'XX')[:2].upper()}-{building_info.get('city', 'XXX')[:3].upper()}"
677
- location = self.climate_data.get_location_by_id(climate_id, st.session_state)
678
  if not location:
679
  return False, f"No climate data found for {climate_id}. Please provide valid climate data.", {}
680
 
681
  # Validate climate data
682
- if not all(k in location for k in ['winter_design_temp', 'monthly_temps', 'monthly_humidity']):
683
- return False, f"Invalid climate data for {climate_id}. Missing required fields.", {}
684
 
685
  # Format conditions
686
  outdoor_conditions = {
687
- 'design_temperature': location['winter_design_temp'],
688
- 'design_relative_humidity': location['monthly_humidity'].get('Jan', 80.0),
689
- 'ground_temperature': location['monthly_temps'].get('Jan', 10.0),
690
- 'wind_speed': 4.0 # Default as not provided in climate data
691
  }
692
  indoor_conditions = {
693
  'temperature': building_info.get('indoor_temp', 21.0),
 
346
  "Select Equipment Loads to Delete",
347
  [load['id'] for load in st.session_state.internal_loads['equipment']]
348
  )
349
+ if st.button("Delete Selected Equipment Loads"):
350
  st.session_state.internal_loads['equipment'] = [
351
  load for load in st.session_state.internal_loads['equipment']
352
  if load['id'] not in selected_equipment
 
375
  # Gather inputs
376
  building_components = st.session_state.get('components', {})
377
  internal_loads = st.session_state.get('internal_loads', {})
378
+ climate_data = st.session_state.get('climate_data', {})
379
  building_info = st.session_state.get('building_info', {})
380
 
381
  # Validate inputs
 
383
  return False, "Floor area is missing in building information.", {}
384
  if not building_components.get('walls') and not building_components.get('roofs') and not building_components.get('windows'):
385
  return False, "No building components defined. Please add walls, roofs, or windows.", {}
386
+ if not climate_data:
387
+ return False, "No climate data provided. Please specify climate data.", {}
388
 
389
+ # Validate wall_group and roof_group
390
+ for wall in building_components.get('walls', []):
391
+ if not hasattr(wall, 'wall_group') or wall.wall_group not in WallModel.VALID_WALL_GROUPS:
392
+ st.warning(f"Invalid wall_group '{getattr(wall, 'wall_group', None)}' for wall '{wall.name}'. Defaulting to 'A'.")
393
+ wall.wall_group = "A"
394
+ for roof in building_components.get('roofs', []):
395
+ if not hasattr(roof, 'roof_group') or roof.roof_group not in RoofModel.VALID_ROOF_GROUPS:
396
+ st.warning(f"Invalid roof_group '{getattr(roof, 'roof_group', None)}' for roof '{roof.name}'. Defaulting to 'A'.")
397
+ roof.roof_group = "A"
398
+
399
+ # Extract climate data
400
  climate_id = f"{building_info.get('country', 'XX')[:2].upper()}-{building_info.get('city', 'XXX')[:3].upper()}"
401
+ location = climate_data.get(climate_id, None)
402
  if not location:
403
  return False, f"No climate data found for {climate_id}. Please provide valid climate data.", {}
404
 
405
  # Validate climate data
406
+ if not hasattr(location, 'summer_design_temp_db') or not hasattr(location, 'summer_design_temp_wb'):
407
+ return False, f"Invalid climate data for {climate_id}. Missing summer design temperatures.", {}
408
+
409
+ # Validate and map latitude
410
+ valid_latitudes = ['24N', '36N', '48N']
411
+ try:
412
+ lat_value = float(location.latitude)
413
+ differences = [abs(lat_value - float(lat[:-1])) for lat in valid_latitudes]
414
+ nearest_idx = differences.index(min(differences))
415
+ latitude = valid_latitudes[nearest_idx]
416
+ except (ValueError, TypeError):
417
+ st.warning(f"Invalid latitude '{location.latitude}'. Defaulting to '24N'.")
418
+ latitude = '24N'
419
 
420
  # Format conditions
421
  outdoor_conditions = {
422
+ 'temperature': location.summer_design_temp_db,
423
+ 'relative_humidity': location.summer_design_temp_wb,
424
+ 'ground_temperature': location.monthly_temps.get('Jul', 20.0),
425
  'month': 'Jul',
426
+ 'latitude': latitude,
427
+ 'wind_speed': climate_data.get('wind_speed', 4.0),
428
  'day_of_year': 204 # Approx. July 23
429
  }
430
  indoor_conditions = {
 
688
  # Gather inputs
689
  building_components = st.session_state.get('components', {})
690
  internal_loads = st.session_state.get('internal_loads', {})
691
+ climate_data = st.session_state.get('climate_data', {})
692
  building_info = st.session_state.get('building_info', {})
693
 
694
  # Validate inputs
 
696
  return False, "Floor area is missing in building information.", {}
697
  if not building_components.get('walls') and not building_components.get('roofs') and not building_components.get('windows'):
698
  return False, "No building components defined. Please add walls, roofs, or windows.", {}
699
+ if not climate_data:
700
+ return False, "No climate data provided. Please specify climate data.", {}
701
+
702
+ # Validate wall_group and roof_group
703
+ for wall in building_components.get('walls', []):
704
+ if not hasattr(wall, 'wall_group') or wall.wall_group not in WallModel.VALID_WALL_GROUPS:
705
+ st.warning(f"Invalid wall_group '{getattr(wall, 'wall_group', None)}' for wall '{wall.name}'. Defaulting to 'A'.")
706
+ wall.wall_group = "A"
707
+ for roof in building_components.get('roofs', []):
708
+ if not hasattr(roof, 'roof_group') or roof.roof_group not in RoofModel.VALID_ROOF_GROUPS:
709
+ st.warning(f"Invalid roof_group '{getattr(roof, 'roof_group', None)}' for roof '{roof.name}'. Defaulting to 'A'.")
710
+ roof.roof_group = "A"
711
 
712
+ # Extract climate data
713
  climate_id = f"{building_info.get('country', 'XX')[:2].upper()}-{building_info.get('city', 'XXX')[:3].upper()}"
714
+ location = climate_data.get(climate_id, None)
715
  if not location:
716
  return False, f"No climate data found for {climate_id}. Please provide valid climate data.", {}
717
 
718
  # Validate climate data
719
+ if not hasattr(location, 'winter_design_temp'):
720
+ return False, f"Invalid climate data for {climate_id}. Missing winter design temperature.", {}
721
 
722
  # Format conditions
723
  outdoor_conditions = {
724
+ 'design_temperature': location.winter_design_temp,
725
+ 'design_relative_humidity': location.monthly_humidity.get('Jan', 80.0),
726
+ 'ground_temperature': location.monthly_temps.get('Jan', 10.0)
 
727
  }
728
  indoor_conditions = {
729
  'temperature': building_info.get('indoor_temp', 21.0),