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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -46
app.py CHANGED
@@ -1,51 +1,22 @@
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.")
 
1
  import streamlit as st
2
 
3
+ # Title of the app
4
+ st.title('Solar Panel Calculator')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
+ # Input fields for user to enter data
7
+ avg_monthly_usage = st.number_input('Average Monthly Usage (kWh)', min_value=0.0, step=1.0)
8
+ peak_demand = st.number_input('Peak Demand (kW)', min_value=0.0, step=0.1)
9
+ solar_panel_efficiency = st.number_input('Solar Panel Efficiency (%)', min_value=0.0, max_value=100.0, step=1.0)
10
 
11
+ # Calculations
12
+ annual_energy_consumption = avg_monthly_usage * 12
13
+ daily_energy_requirement = annual_energy_consumption / 365
14
+ solar_panel_output = daily_energy_requirement / solar_panel_efficiency
 
 
15
 
16
+ # Display results
17
+ st.write('### Calculated Results:')
18
+ st.write(f'- Annual Energy Consumption: {annual_energy_consumption} kWh')
19
+ st.write(f'- Daily Energy Requirement: {daily_energy_requirement} kWh')
20
+ st.write(f'- Solar Panel Output: {solar_panel_output} kWh')
21
+
22
+ # Cost calculations and payback period can be added here based on the specific formula you have in mind