hamzaherry commited on
Commit
c83f986
·
verified ·
1 Parent(s): 301aab4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -37
app.py CHANGED
@@ -1,81 +1,79 @@
1
  import streamlit as st
2
 
3
  # Title of the app
4
- st.title("Solar Energy Calculator")
5
 
6
  # Input Section: User inputs for energy usage, costs, etc.
7
- st.header("Input your energy usage and system parameters:")
8
 
9
  # Average Monthly Usage in kWh
10
  monthly_usage = st.number_input("Enter your average monthly energy usage (kWh):", min_value=0.0)
11
 
12
- # Peak Demand
13
  peak_demand = st.number_input("Enter your peak demand (kW):", min_value=0.0)
14
 
15
  # Solar Panel Efficiency
16
  solar_panel_efficiency = st.number_input("Enter the efficiency of your solar panels (0 to 100):", min_value=0.0, max_value=100.0)
17
 
18
- # Cost of electricity per kWh (user input or fixed)
19
- cost_per_kwh = st.number_input("Enter the cost per kWh (in your local currency):", min_value=0.0)
20
 
21
- # Solar panel cost (in local currency per panel or total cost)
22
- solar_panel_cost = st.number_input("Enter the cost of installing solar panels (in your local currency):", min_value=0.0)
 
 
 
23
 
24
  # Average Sunlight Hours per Day
25
  sunlight_hours = st.number_input("Enter the average sunlight hours per day:", min_value=0.0)
26
 
27
- # Solar Panel Output
28
- solar_panel_output = st.number_input("Enter the solar panel output (in watts, W):", min_value=0)
29
-
30
- # Avoid ZeroDivisionError by checking input values
31
- if solar_panel_output > 0 and sunlight_hours > 0:
32
- # Calculations
33
-
34
  # Determine Annual Energy Consumption (in kWh)
35
  annual_energy_consumption = monthly_usage * 12
36
 
37
  # Calculate Daily Energy Requirement (in kWh)
38
  daily_energy_requirement = annual_energy_consumption / 365
39
 
40
- # Solar Panel Output in kWh (daily)
41
- solar_panel_output_kwh = (solar_panel_output / 1000) * sunlight_hours # Convert from watts to kWh
42
 
43
- # Calculate number of solar panels required to meet daily energy requirement
44
  num_panels_required = daily_energy_requirement / solar_panel_output_kwh
45
 
 
 
 
46
  # Cost Calculations
47
- total_solar_cost = num_panels_required * solar_panel_cost
 
 
 
 
48
 
49
- # Payback Period (years)
50
- annual_savings = annual_energy_consumption * cost_per_kwh
51
- payback_period = total_solar_cost / annual_savings
52
 
53
- # Output Section: Display results
54
  st.header("Results:")
55
 
56
- # Display annual energy consumption
57
  st.subheader(f"Annual Energy Consumption: {annual_energy_consumption:.2f} kWh")
58
-
59
- # Display daily energy requirement
60
  st.subheader(f"Daily Energy Requirement: {daily_energy_requirement:.2f} kWh")
61
-
62
- # Display solar panel output
63
  st.subheader(f"Solar Panel Output per day: {solar_panel_output_kwh:.2f} kWh")
64
-
65
- # Display number of panels required
66
- st.subheader(f"Number of Solar Panels Required: {num_panels_required:.2f} panels")
67
-
68
- # Display total solar system cost
69
- st.subheader(f"Total Solar Panel Installation Cost: {total_solar_cost:.2f} local currency")
70
-
71
- # Display payback period
72
  st.subheader(f"Payback Period: {payback_period:.2f} years")
 
73
  else:
74
  st.warning("Please ensure that both solar panel output and sunlight hours are greater than 0.")
75
 
76
  # Show tips for improving the app or using it effectively
77
  st.markdown("""
78
  - Make sure to input accurate data to get the most reliable results.
79
- - You can adjust the efficiency, cost, and solar panel output to simulate different scenarios.
80
- - The payback period assumes the energy savings are constant each year.
81
  """)
 
1
  import streamlit as st
2
 
3
  # Title of the app
4
+ st.title("Complete Solar Energy Calculator")
5
 
6
  # Input Section: User inputs for energy usage, costs, etc.
7
+ st.header("Enter your energy usage and system parameters:")
8
 
9
  # Average Monthly Usage in kWh
10
  monthly_usage = st.number_input("Enter your average monthly energy usage (kWh):", min_value=0.0)
11
 
12
+ # Peak Demand in kW
13
  peak_demand = st.number_input("Enter your peak demand (kW):", min_value=0.0)
14
 
15
  # Solar Panel Efficiency
16
  solar_panel_efficiency = st.number_input("Enter the efficiency of your solar panels (0 to 100):", min_value=0.0, max_value=100.0)
17
 
18
+ # Panel Output in Watts (W)
19
+ panel_output_watts = st.number_input("Enter the solar panel output (in watts, W):", min_value=0)
20
 
21
+ # Inverter Cost (per inverter)
22
+ inverter_cost = st.number_input("Enter the cost of the inverter (in your local currency):", min_value=0.0)
23
+
24
+ # Cost per Solar Panel
25
+ panel_cost = st.number_input("Enter the cost per solar panel (in your local currency):", min_value=0.0)
26
 
27
  # Average Sunlight Hours per Day
28
  sunlight_hours = st.number_input("Enter the average sunlight hours per day:", min_value=0.0)
29
 
30
+ # Calculations Section
31
+ if panel_output_watts > 0 and sunlight_hours > 0:
 
 
 
 
 
32
  # Determine Annual Energy Consumption (in kWh)
33
  annual_energy_consumption = monthly_usage * 12
34
 
35
  # Calculate Daily Energy Requirement (in kWh)
36
  daily_energy_requirement = annual_energy_consumption / 365
37
 
38
+ # Solar Panel Output in kWh per day (considering the sunlight hours)
39
+ solar_panel_output_kwh = (panel_output_watts / 1000) * sunlight_hours # Convert watts to kWh
40
 
41
+ # Calculate the number of panels required
42
  num_panels_required = daily_energy_requirement / solar_panel_output_kwh
43
 
44
+ # Inverter Capacity (based on peak demand)
45
+ inverter_capacity = peak_demand * 1.2 # Inverter capacity should be around 1.2 times the peak demand for efficiency
46
+
47
  # Cost Calculations
48
+ total_solar_cost = num_panels_required * panel_cost
49
+ total_inverter_cost = inverter_cost
50
+
51
+ # Total Solar System Installation Cost
52
+ total_installation_cost = total_solar_cost + total_inverter_cost
53
 
54
+ # Payback Period Calculation
55
+ annual_savings = annual_energy_consumption * (cost_per_kwh := st.number_input("Enter the cost per kWh of electricity:", min_value=0.0))
56
+ payback_period = total_installation_cost / annual_savings if annual_savings > 0 else float('inf')
57
 
58
+ # Display Results
59
  st.header("Results:")
60
 
 
61
  st.subheader(f"Annual Energy Consumption: {annual_energy_consumption:.2f} kWh")
 
 
62
  st.subheader(f"Daily Energy Requirement: {daily_energy_requirement:.2f} kWh")
 
 
63
  st.subheader(f"Solar Panel Output per day: {solar_panel_output_kwh:.2f} kWh")
64
+ st.subheader(f"Number of Panels Required: {num_panels_required:.2f} panels")
65
+ st.subheader(f"Inverter Capacity Required: {inverter_capacity:.2f} kW")
66
+ st.subheader(f"Total Solar Panel Cost: {total_solar_cost:.2f} local currency")
67
+ st.subheader(f"Total Inverter Cost: {total_inverter_cost:.2f} local currency")
68
+ st.subheader(f"Total Installation Cost: {total_installation_cost:.2f} local currency")
 
 
 
69
  st.subheader(f"Payback Period: {payback_period:.2f} years")
70
+
71
  else:
72
  st.warning("Please ensure that both solar panel output and sunlight hours are greater than 0.")
73
 
74
  # Show tips for improving the app or using it effectively
75
  st.markdown("""
76
  - Make sure to input accurate data to get the most reliable results.
77
+ - The inverter capacity is calculated based on your peak demand.
78
+ - Payback period assumes that energy savings will remain constant each year.
79
  """)