mabuseif commited on
Commit
4d8209f
·
verified ·
1 Parent(s): f277e7e

Update app/internal_loads.py

Browse files
Files changed (1) hide show
  1. app/internal_loads.py +22 -7
app/internal_loads.py CHANGED
@@ -406,9 +406,10 @@ def display_equipment_tab():
406
  if "equipment_action" not in st.session_state:
407
  st.session_state.equipment_action = {"action": None, "id": None}
408
 
409
- # Get building type for default values
410
  building_type = st.session_state.project_data["building_info"].get("building_type")
411
- default_equipment_data = DEFAULT_BUILDING_INTERNALS.get(building_type, DEFAULT_BUILDING_INTERNALS["Other"])["equipment_heat_gains"]
 
412
 
413
  # Display the editor form
414
  with st.form("equipment_editor_form", clear_on_submit=True):
@@ -432,6 +433,16 @@ def display_equipment_tab():
432
  help="Floor area served by this equipment."
433
  )
434
 
 
 
 
 
 
 
 
 
 
 
435
  # Heat gains
436
  st.write("**Heat Gains (W/m²):**")
437
  col_sens, col_lat = st.columns(2)
@@ -441,7 +452,7 @@ def display_equipment_tab():
441
  "Sensible Heat Gain",
442
  min_value=0.0,
443
  max_value=200.0,
444
- value=float(editor_state.get("sensible_gain", default_equipment_data["sensible"])),
445
  format="%.2f",
446
  help="Sensible heat gain in watts per square meter."
447
  )
@@ -451,7 +462,7 @@ def display_equipment_tab():
451
  "Latent Heat Gain",
452
  min_value=0.0,
453
  max_value=200.0,
454
- value=float(editor_state.get("latent_gain", default_equipment_data["latent"])),
455
  format="%.2f",
456
  help="Latent heat gain in watts per square meter."
457
  )
@@ -465,7 +476,7 @@ def display_equipment_tab():
465
  "Radiative Fraction",
466
  min_value=0.0,
467
  max_value=1.0,
468
- value=float(editor_state.get("radiative_fraction", 0.5)),
469
  format="%.2f",
470
  help="Fraction of sensible heat released as radiation."
471
  )
@@ -475,7 +486,7 @@ def display_equipment_tab():
475
  "Convective Fraction",
476
  min_value=0.0,
477
  max_value=1.0,
478
- value=float(editor_state.get("convective_fraction", 0.5)),
479
  format="%.2f",
480
  help="Fraction of sensible heat released as convection."
481
  )
@@ -485,7 +496,7 @@ def display_equipment_tab():
485
  schedule = st.selectbox(
486
  "Schedule",
487
  available_schedules,
488
- index=available_schedules.index(editor_state.get("schedule", available_schedules[0])) if editor_state.get("schedule") in available_schedules else 0,
489
  help="Select the equipment schedule."
490
  )
491
 
@@ -507,6 +518,9 @@ def display_equipment_tab():
507
  if abs(radiative_fraction + convective_fraction - 1.0) > 0.01:
508
  st.error("Radiative and convective fractions must sum to 1.0")
509
  return
 
 
 
510
  # Check for unique name
511
  existing_names = [system["name"] for system in equipment_systems if not (is_edit and system["name"] == editor_state.get("name"))]
512
  if name.strip() in existing_names:
@@ -518,6 +532,7 @@ def display_equipment_tab():
518
  "id": str(uuid.uuid4()),
519
  "name": name.strip(),
520
  "area": area,
 
521
  "sensible_gain": sensible_gain,
522
  "latent_gain": latent_gain,
523
  "total_sensible_power": area * sensible_gain,
 
406
  if "equipment_action" not in st.session_state:
407
  st.session_state.equipment_action = {"action": None, "id": None}
408
 
409
+ # Get building type and corresponding schedule type for default values
410
  building_type = st.session_state.project_data["building_info"].get("building_type")
411
+ schedule_type = DEFAULT_BUILDING_INTERNALS.get(building_type, DEFAULT_BUILDING_INTERNALS["Other"])["schedule_type"]
412
+ default_equipment_data = DEFAULT_EQUIPMENT_LOADS.get(schedule_type, DEFAULT_EQUIPMENT_LOADS["default"])
413
 
414
  # Display the editor form
415
  with st.form("equipment_editor_form", clear_on_submit=True):
 
433
  help="Floor area served by this equipment."
434
  )
435
 
436
+ # Equipment load
437
+ equipment_load = st.number_input(
438
+ "Equipment Load (W/m²)",
439
+ min_value=0.0,
440
+ max_value=200.0,
441
+ value=float(editor_state.get("equipment_load", default_equipment_data["equipment_load_w_m2"])),
442
+ format="%.2f",
443
+ help="Total equipment load in watts per square meter."
444
+ )
445
+
446
  # Heat gains
447
  st.write("**Heat Gains (W/m²):**")
448
  col_sens, col_lat = st.columns(2)
 
452
  "Sensible Heat Gain",
453
  min_value=0.0,
454
  max_value=200.0,
455
+ value=float(editor_state.get("sensible_gain", default_equipment_data["equipment_load_w_m2"] * (default_equipment_data["sensible_percent"] / 100))),
456
  format="%.2f",
457
  help="Sensible heat gain in watts per square meter."
458
  )
 
462
  "Latent Heat Gain",
463
  min_value=0.0,
464
  max_value=200.0,
465
+ value=float(editor_state.get("latent_gain", default_equipment_data["equipment_load_w_m2"] * (default_equipment_data["latent_percent"] / 100))),
466
  format="%.2f",
467
  help="Latent heat gain in watts per square meter."
468
  )
 
476
  "Radiative Fraction",
477
  min_value=0.0,
478
  max_value=1.0,
479
+ value=float(editor_state.get("radiative_fraction", default_equipment_data["radiant_percent"] / 100)),
480
  format="%.2f",
481
  help="Fraction of sensible heat released as radiation."
482
  )
 
486
  "Convective Fraction",
487
  min_value=0.0,
488
  max_value=1.0,
489
+ value=float(editor_state.get("convective_fraction", default_equipment_data["convective_percent"] / 100)),
490
  format="%.2f",
491
  help="Fraction of sensible heat released as convection."
492
  )
 
496
  schedule = st.selectbox(
497
  "Schedule",
498
  available_schedules,
499
+ index=available_schedules.index(editor_state.get("schedule", schedule_type)) if editor_state.get("schedule") in available_schedules else available_schedules.index(schedule_type) if schedule_type in available_schedules else 0,
500
  help="Select the equipment schedule."
501
  )
502
 
 
518
  if abs(radiative_fraction + convective_fraction - 1.0) > 0.01:
519
  st.error("Radiative and convective fractions must sum to 1.0")
520
  return
521
+ if abs(sensible_gain + latent_gain - equipment_load) > 0.01:
522
+ st.error("Sensible and latent heat gains must sum to the equipment load.")
523
+ return
524
  # Check for unique name
525
  existing_names = [system["name"] for system in equipment_systems if not (is_edit and system["name"] == editor_state.get("name"))]
526
  if name.strip() in existing_names:
 
532
  "id": str(uuid.uuid4()),
533
  "name": name.strip(),
534
  "area": area,
535
+ "equipment_load": equipment_load,
536
  "sensible_gain": sensible_gain,
537
  "latent_gain": latent_gain,
538
  "total_sensible_power": area * sensible_gain,