hamzaherry commited on
Commit
3f8ca5a
·
verified ·
1 Parent(s): 949d1e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -24
app.py CHANGED
@@ -1,44 +1,51 @@
1
  import streamlit as st
2
 
3
  # Function for calculations
4
- def calculate_solar_requirements(total_load, sun_hours, panel_wattage, efficiency_loss, battery_backup):
5
- # Energy needs per day (in kWh)
6
- daily_energy = total_load * efficiency_loss / 1000
 
7
 
8
- # Required solar generation (kW)
9
- solar_capacity_needed = daily_energy / sun_hours
 
10
 
11
- # Number of panels
12
- num_panels = solar_capacity_needed * 1000 / panel_wattage
 
 
 
13
 
14
- # Battery capacity (kWh)
15
- battery_capacity = 0
16
- if battery_backup > 0:
17
- battery_capacity = daily_energy * battery_backup
18
 
19
- return daily_energy, solar_capacity_needed, num_panels, battery_capacity
 
 
 
 
 
20
 
21
  # Streamlit App
22
  st.title("Solar Panel Calculator")
23
  st.sidebar.header("User Input")
24
 
25
  # User Inputs
26
- total_load = st.sidebar.number_input("Total Load (W)", min_value=100, max_value=100000, value=5000)
27
- sun_hours = st.sidebar.number_input("Sun Hours (Hours/day)", min_value=1.0, max_value=12.0, value=5.0)
28
- panel_wattage = st.sidebar.number_input("Panel Wattage (W)", min_value=100, max_value=1000, value=300)
29
- efficiency_loss = st.sidebar.slider("Efficiency Loss (%)", min_value=0, max_value=30, value=15)
30
- battery_backup = st.sidebar.number_input("Battery Backup Hours (optional)", min_value=0, max_value=24, value=0)
31
 
32
  # Calculate
33
  if st.sidebar.button("Calculate"):
34
- daily_energy, solar_capacity_needed, num_panels, battery_capacity = calculate_solar_requirements(
35
- total_load, sun_hours, panel_wattage, efficiency_loss, battery_backup
36
  )
37
 
38
  # Display Results
39
  st.subheader("Results")
40
- st.write(f"Daily Energy Consumption: {daily_energy:.2f} kWh")
41
- st.write(f"Solar Capacity Needed: {solar_capacity_needed:.2f} kW")
42
- st.write(f"Number of Panels Required: {num_panels:.0f}")
43
- if battery_backup > 0:
44
- st.write(f"Battery Capacity Required: {battery_capacity:.2f} kWh")
 
1
  import streamlit as st
2
 
3
  # Function for calculations
4
+ def calculate_solar_requirements(monthly_usage, roof_direction, inclination_angle, panel_efficiency, peak_factor):
5
+ # Constants
6
+ SUN_HOURS = 5 # Average daily sun hours (adjustable)
7
+ LOSS_FACTOR = 0.85 # 15% loss due to shading, weather, etc.
8
 
9
+ # Annual and daily energy calculations
10
+ annual_energy = monthly_usage * 12
11
+ daily_energy = annual_energy / 365
12
 
13
+ # Panel output adjustment based on direction and inclination
14
+ if roof_direction in ["south", "southeast", "southwest"]:
15
+ direction_factor = 1.0
16
+ else:
17
+ direction_factor = 0.8 # Example: less optimal directions
18
 
19
+ inclination_factor = max(0.9 - abs(inclination_angle - 30) * 0.01, 0.5) # Ideal angle ~30 degrees
 
 
 
20
 
21
+ panel_output_per_day = SUN_HOURS * (panel_efficiency / 100) * LOSS_FACTOR * direction_factor * inclination_factor
22
+
23
+ # Total panels required
24
+ num_panels = (daily_energy * peak_factor) / panel_output_per_day
25
+
26
+ return annual_energy, daily_energy, panel_output_per_day, num_panels
27
 
28
  # Streamlit App
29
  st.title("Solar Panel Calculator")
30
  st.sidebar.header("User Input")
31
 
32
  # User Inputs
33
+ monthly_usage = st.sidebar.number_input("Average Monthly Usage (kWh)", min_value=100, max_value=5000, value=500)
34
+ roof_direction = st.sidebar.selectbox("Roof Direction", ["south", "southeast", "southwest", "east", "west", "north"])
35
+ inclination_angle = st.sidebar.number_input("Roof Inclination Angle (degrees)", min_value=0, max_value=90, value=30)
36
+ panel_efficiency = st.sidebar.slider("Solar Panel Efficiency (%)", min_value=10, max_value=25, value=20)
37
+ peak_factor = st.sidebar.slider("Peak Usage Factor (e.g., summer demand multiplier)", min_value=1.0, max_value=2.0, value=1.2)
38
 
39
  # Calculate
40
  if st.sidebar.button("Calculate"):
41
+ annual_energy, daily_energy, panel_output_per_day, num_panels = calculate_solar_requirements(
42
+ monthly_usage, roof_direction, inclination_angle, panel_efficiency, peak_factor
43
  )
44
 
45
  # Display Results
46
  st.subheader("Results")
47
+ st.write(f"**Annual Energy Consumption:** {annual_energy:.2f} kWh")
48
+ st.write(f"**Daily Energy Requirement:** {daily_energy:.2f} kWh")
49
+ st.write(f"**Solar Panel Output (per panel/day):** {panel_output_per_day:.2f} kWh")
50
+ st.write(f"**Number of Panels Required:** {num_panels:.0f}")
51
+ st.write("Note: These estimates account for real-world losses and adjustments for roof orientation and angle.")