mabuseif commited on
Commit
7a9e3aa
·
verified ·
1 Parent(s): 93506b3

Update app/main.py

Browse files
Files changed (1) hide show
  1. app/main.py +34 -70
app/main.py CHANGED
@@ -25,8 +25,8 @@ from data.reference_data import ReferenceData
25
  from data.climate_data import ClimateData
26
  from data.ashrae_tables import ASHRAETables
27
  from data.building_components import Wall as WallModel, Roof as RoofModel
28
- from utils.cooling_load import CoolingLoadCalculator
29
- from utils.heating_load import HeatingLoadCalculator
30
 
31
  # Import utility modules
32
  from utils.u_value_calculator import UValueCalculator
@@ -169,50 +169,31 @@ class HVACCalculator:
169
  'summer_outdoor_rh': 50.0,
170
  'ground_temperature': 20.0,
171
  'design_month': 'Jul',
172
- 'latitude': '40N'
 
173
  }
174
  st.warning("No climate data provided. Using default values.")
175
 
176
- # Default conditions
177
- outdoor_conditions = {
178
- 'temperature': climate_data.get('summer_outdoor_db', 35.0),
179
- 'relative_humidity': climate_data.get('summer_outdoor_rh', 50.0),
180
- 'ground_temperature': climate_data.get('ground_temperature', 20.0),
181
- 'month': climate_data.get('design_month', 'Jul'),
182
- 'latitude': climate_data.get('latitude', '40N'),
183
  'daily_range_c': climate_data.get('daily_range_c', 11.0)
184
  }
185
- indoor_conditions = {
186
- 'temperature': building_info.get('indoor_temp', 24.0),
187
- 'relative_humidity': building_info.get('indoor_rh', 50.0)
188
- }
189
 
190
- # Format internal loads for CoolingLoadCalculator
191
  formatted_internal_loads = {
192
- 'people': {
193
- 'number': sum(load['num_people'] for load in internal_loads.get('people', [])),
194
- 'activity_level': internal_loads.get('people', [{}])[0].get('activity_level', 'Seated/Resting'),
195
- 'hours_occupancy': f"{internal_loads.get('people', [{}])[0].get('hours_in_operation', 8)}h"
196
- },
197
- 'lights': {
198
- 'power': sum(load['power'] for load in internal_loads.get('lighting', [])),
199
- 'use_factor': internal_loads.get('lighting', [{}])[0].get('usage_factor', 0.8),
200
- 'special_allowance': 0.1,
201
- 'hours_operation': f"{internal_loads.get('lighting', [{}])[0].get('hours_in_operation', 8)}h"
202
- },
203
- 'equipment': {
204
- 'power': sum(load['power'] for load in internal_loads.get('equipment', [])),
205
- 'use_factor': internal_loads.get('equipment', [{}])[0].get('usage_factor', 0.7),
206
- 'radiation_factor': internal_loads.get('equipment', [{}])[0].get('radiation_fraction', 0.3),
207
- 'hours_operation': f"{internal_loads.get('equipment', [{}])[0].get('hours_in_operation', 8)}h"
208
- },
209
- 'infiltration': {'flow_rate': building_info.get('infiltration_rate', 0.05)},
210
- 'ventilation': {'flow_rate': building_info.get('ventilation_rate', 0.1)}
211
  }
212
 
213
- # Initialize calculator with building_info, components, and climate_data
214
- calculator = CoolingLoadCalculator(building_info, building_components, outdoor_conditions)
215
- cooling_loads = calculator.calculate_cooling_load()
216
 
217
  # Format results for results_display.py
218
  floor_area = building_info.get('floor_area', 100.0) or 100.0
@@ -261,39 +242,25 @@ class HVACCalculator:
261
  }
262
  st.warning("No climate data provided. Using default values.")
263
 
264
- # Default conditions
265
- outdoor_conditions = {
266
- 'design_temperature': climate_data.get('winter_outdoor_db', -10.0),
267
- 'design_relative_humidity': climate_data.get('winter_outdoor_rh', 80.0),
268
- 'ground_temperature': climate_data.get('ground_temperature', 10.0)
269
- }
270
- indoor_conditions = {
271
- 'temperature': building_info.get('indoor_temp', 21.0),
272
- 'relative_humidity': building_info.get('indoor_rh', 40.0)
273
  }
274
 
275
  # Format internal loads
276
  formatted_internal_loads = {
277
- 'people': {
278
- 'number': sum(load['num_people'] for load in internal_loads.get('people', [])),
279
- 'sensible_gain': 70
280
- },
281
- 'lights': {
282
- 'power': sum(load['power'] for load in internal_loads.get('lighting', [])),
283
- 'use_factor': internal_loads.get('lighting', [{}])[0].get('usage_factor', 0.8)
284
- },
285
- 'equipment': {
286
- 'power': sum(load['power'] for load in internal_loads.get('equipment', [])),
287
- 'use_factor': internal_loads.get('equipment', [{}])[0].get('usage_factor', 0.7)
288
- },
289
- 'infiltration': {'flow_rate': building_info.get('infiltration_rate', 0.05)},
290
- 'ventilation': {'flow_rate': building_info.get('ventilation_rate', 0.1)},
291
- 'usage_factor': 0.7
292
  }
293
 
294
- # Initialize calculator
295
- calculator = HeatingLoadCalculator(building_info, building_components, outdoor_conditions)
296
- heating_loads = calculator.calculate_heating_load()
297
 
298
  # Format results
299
  floor_area = building_info.get('floor_area', 100.0) or 100.0
@@ -419,7 +386,7 @@ class HVACCalculator:
419
  def display_people_loads(self):
420
  st.subheader("People")
421
 
422
- with st.form("people_load_form"):
423
  col1, col2 = st.columns(2)
424
 
425
  with col1:
@@ -452,7 +419,6 @@ class HVACCalculator:
452
 
453
  st.session_state.internal_loads['people'].append(people_load)
454
  st.success(f"Added {name} with {num_people} people")
455
- st.rerun()
456
 
457
  if st.session_state.internal_loads['people']:
458
  st.subheader("Existing People Loads")
@@ -497,7 +463,7 @@ class HVACCalculator:
497
  def display_lighting_loads(self):
498
  st.subheader("Lighting")
499
 
500
- with st.form("lighting_load_form"):
501
  col1, col2 = st.columns(2)
502
 
503
  with col1:
@@ -527,7 +493,6 @@ class HVACCalculator:
527
 
528
  st.session_state.internal_loads['lighting'].append(lighting_load)
529
  st.success(f"Added {name} with {power} W")
530
- st.rerun()
531
 
532
  if st.session_state.internal_loads['lighting']:
533
  st.subheader("Existing Lighting Loads")
@@ -572,7 +537,7 @@ class HVACCalculator:
572
  def display_equipment_loads(self):
573
  st.subheader("Equipment")
574
 
575
- with st.form("equipment_load_form"):
576
  col1, col2 = st.columns(2)
577
 
578
  with col1:
@@ -605,7 +570,6 @@ class HVACCalculator:
605
 
606
  st.session_state.internal_loads['equipment'].append(equipment_load)
607
  st.success(f"Added {name} with {power} W")
608
- st.rerun()
609
 
610
  if st.session_state.internal_loads['equipment']:
611
  st.subheader("Existing Equipment Loads")
 
25
  from data.climate_data import ClimateData
26
  from data.ashrae_tables import ASHRAETables
27
  from data.building_components import Wall as WallModel, Roof as RoofModel
28
+ from data.cooling_load_updated import CoolingLoadCalculator
29
+ from data.heating_load_updated import HeatingLoadCalculator
30
 
31
  # Import utility modules
32
  from utils.u_value_calculator import UValueCalculator
 
169
  'summer_outdoor_rh': 50.0,
170
  'ground_temperature': 20.0,
171
  'design_month': 'Jul',
172
+ 'latitude': '40N',
173
+ 'daily_range_c': 11.0
174
  }
175
  st.warning("No climate data provided. Using default values.")
176
 
177
+ # Format climate data for calculator
178
+ climate_conditions = {
179
+ 'outdoor_temp_c': climate_data.get('summer_outdoor_db', 35.0),
180
+ 'indoor_temp_c': building_info.get('indoor_temp', 24.0),
181
+ 'latitude': float(climate_data.get('latitude', '40N').replace('N', '')),
 
 
182
  'daily_range_c': climate_data.get('daily_range_c', 11.0)
183
  }
 
 
 
 
184
 
185
+ # Format internal loads (simplified for cooling_load_updated.py)
186
  formatted_internal_loads = {
187
+ 'people': sum(load['num_people'] for load in internal_loads.get('people', [])) * 100, # W/person
188
+ 'lighting': sum(load['power'] * load['usage_factor'] for load in internal_loads.get('lighting', [])), # W
189
+ 'equipment': sum(load['power'] * load['usage_factor'] for load in internal_loads.get('equipment', [])), # W
190
+ 'infiltration': building_info.get('infiltration_rate', 0.05) * building_info.get('floor_area', 100.0), # m³/s
191
+ 'ventilation': building_info.get('ventilation_rate', 0.1) * building_info.get('floor_area', 100.0) # m³/s
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
  }
193
 
194
+ # Initialize calculator and calculate
195
+ calculator = CoolingLoadCalculator()
196
+ cooling_loads = calculator.calculate_cooling_load(building_info, building_components, climate_conditions, formatted_internal_loads)
197
 
198
  # Format results for results_display.py
199
  floor_area = building_info.get('floor_area', 100.0) or 100.0
 
242
  }
243
  st.warning("No climate data provided. Using default values.")
244
 
245
+ # Format climate data
246
+ climate_conditions = {
247
+ 'outdoor_temp_c': climate_data.get('winter_outdoor_db', -10.0),
248
+ 'indoor_temp_c': building_info.get('indoor_temp', 21.0),
249
+ 'ground_temperature_c': climate_data.get('ground_temperature', 10.0)
 
 
 
 
250
  }
251
 
252
  # Format internal loads
253
  formatted_internal_loads = {
254
+ 'people': sum(load['num_people'] for load in internal_loads.get('people', [])) * 70, # W/person
255
+ 'lighting': sum(load['power'] * load['usage_factor'] for load in internal_loads.get('lighting', [])), # W
256
+ 'equipment': sum(load['power'] * load['usage_factor'] for load in internal_loads.get('equipment', [])), # W
257
+ 'infiltration': building_info.get('infiltration_rate', 0.05) * building_info.get('floor_area', 100.0), # m³/s
258
+ 'ventilation': building_info.get('ventilation_rate', 0.1) * building_info.get('floor_area', 100.0) # m³/s
 
 
 
 
 
 
 
 
 
 
259
  }
260
 
261
+ # Initialize calculator and calculate
262
+ calculator = HeatingLoadCalculator()
263
+ heating_loads = calculator.calculate_heating_load(building_info, building_components, climate_conditions, formatted_internal_loads)
264
 
265
  # Format results
266
  floor_area = building_info.get('floor_area', 100.0) or 100.0
 
386
  def display_people_loads(self):
387
  st.subheader("People")
388
 
389
+ with st.form("people_load_form", clear_on_submit=True):
390
  col1, col2 = st.columns(2)
391
 
392
  with col1:
 
419
 
420
  st.session_state.internal_loads['people'].append(people_load)
421
  st.success(f"Added {name} with {num_people} people")
 
422
 
423
  if st.session_state.internal_loads['people']:
424
  st.subheader("Existing People Loads")
 
463
  def display_lighting_loads(self):
464
  st.subheader("Lighting")
465
 
466
+ with st.form("lighting_load_form", clear_on_submit=True):
467
  col1, col2 = st.columns(2)
468
 
469
  with col1:
 
493
 
494
  st.session_state.internal_loads['lighting'].append(lighting_load)
495
  st.success(f"Added {name} with {power} W")
 
496
 
497
  if st.session_state.internal_loads['lighting']:
498
  st.subheader("Existing Lighting Loads")
 
537
  def display_equipment_loads(self):
538
  st.subheader("Equipment")
539
 
540
+ with st.form("equipment_load_form", clear_on_submit=True):
541
  col1, col2 = st.columns(2)
542
 
543
  with col1:
 
570
 
571
  st.session_state.internal_loads['equipment'].append(equipment_load)
572
  st.success(f"Added {name} with {power} W")
 
573
 
574
  if st.session_state.internal_loads['equipment']:
575
  st.subheader("Existing Equipment Loads")