Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,44 +1,51 @@
|
|
1 |
import streamlit as st
|
2 |
|
3 |
# Function for calculations
|
4 |
-
def calculate_solar_requirements(
|
5 |
-
#
|
6 |
-
|
|
|
7 |
|
8 |
-
#
|
9 |
-
|
|
|
10 |
|
11 |
-
#
|
12 |
-
|
|
|
|
|
|
|
13 |
|
14 |
-
|
15 |
-
battery_capacity = 0
|
16 |
-
if battery_backup > 0:
|
17 |
-
battery_capacity = daily_energy * battery_backup
|
18 |
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
# Streamlit App
|
22 |
st.title("Solar Panel Calculator")
|
23 |
st.sidebar.header("User Input")
|
24 |
|
25 |
# User Inputs
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
|
32 |
# Calculate
|
33 |
if st.sidebar.button("Calculate"):
|
34 |
-
daily_energy,
|
35 |
-
|
36 |
)
|
37 |
|
38 |
# Display Results
|
39 |
st.subheader("Results")
|
40 |
-
st.write(f"
|
41 |
-
st.write(f"
|
42 |
-
st.write(f"
|
43 |
-
|
44 |
-
|
|
|
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.")
|