Spaces:
Sleeping
Sleeping
import streamlit as st | |
# Title of the app | |
st.title("Solar Energy Calculator") | |
# Input Section: User inputs for energy usage, costs, etc. | |
st.header("Input your energy usage and system parameters:") | |
# Average Monthly Usage in kWh | |
monthly_usage = st.number_input("Enter your average monthly energy usage (kWh):", min_value=0.0) | |
# Peak Demand | |
peak_demand = st.number_input("Enter your peak demand (kW):", min_value=0.0) | |
# Solar Panel Efficiency | |
solar_panel_efficiency = st.number_input("Enter the efficiency of your solar panels (0 to 100):", min_value=0.0, max_value=100.0) | |
# Cost of electricity per kWh (user input or fixed) | |
cost_per_kwh = st.number_input("Enter the cost per kWh (in your local currency):", min_value=0.0) | |
# Solar panel cost (in local currency per panel or total cost) | |
solar_panel_cost = st.number_input("Enter the cost of installing solar panels (in your local currency):", min_value=0.0) | |
# Average Sunlight Hours per Day | |
sunlight_hours = st.number_input("Enter the average sunlight hours per day:", min_value=0.0) | |
# Solar Panel Output | |
solar_panel_output = st.number_input("Enter the solar panel output (in watts, W):", min_value=0) | |
# Avoid ZeroDivisionError by checking input values | |
if solar_panel_output > 0 and sunlight_hours > 0: | |
# Calculations | |
# Determine Annual Energy Consumption (in kWh) | |
annual_energy_consumption = monthly_usage * 12 | |
# Calculate Daily Energy Requirement (in kWh) | |
daily_energy_requirement = annual_energy_consumption / 365 | |
# Solar Panel Output in kWh (daily) | |
solar_panel_output_kwh = (solar_panel_output / 1000) * sunlight_hours # Convert from watts to kWh | |
# Calculate number of solar panels required to meet daily energy requirement | |
num_panels_required = daily_energy_requirement / solar_panel_output_kwh | |
# Cost Calculations | |
total_solar_cost = num_panels_required * solar_panel_cost | |
# Payback Period (years) | |
annual_savings = annual_energy_consumption * cost_per_kwh | |
payback_period = total_solar_cost / annual_savings | |
# Output Section: Display results | |
st.header("Results:") | |
# Display annual energy consumption | |
st.subheader(f"Annual Energy Consumption: {annual_energy_consumption:.2f} kWh") | |
# Display daily energy requirement | |
st.subheader(f"Daily Energy Requirement: {daily_energy_requirement:.2f} kWh") | |
# Display solar panel output | |
st.subheader(f"Solar Panel Output per day: {solar_panel_output_kwh:.2f} kWh") | |
# Display number of panels required | |
st.subheader(f"Number of Solar Panels Required: {num_panels_required:.2f} panels") | |
# Display total solar system cost | |
st.subheader(f"Total Solar Panel Installation Cost: {total_solar_cost:.2f} local currency") | |
# Display payback period | |
st.subheader(f"Payback Period: {payback_period:.2f} years") | |
else: | |
st.warning("Please ensure that both solar panel output and sunlight hours are greater than 0.") | |
# Show tips for improving the app or using it effectively | |
st.markdown(""" | |
- Make sure to input accurate data to get the most reliable results. | |
- You can adjust the efficiency, cost, and solar panel output to simulate different scenarios. | |
- The payback period assumes the energy savings are constant each year. | |
""") | |