import streamlit as st import numpy as np from io import BytesIO # Function to calculate load and solar panel requirement def calculate_requirements(equipment, system_type): total_load = 0 # Calculate total load based on counts and wattage for item, values in equipment.items(): total_load += values['wattage'] * values['count'] # Total load in watts total_load_kw = total_load / 1000 # Convert watts to kilowatts # Solar panel estimation (assume 300W per panel for On-Grid) panel_wattage = 550 # Wattage of a single solar panel panels_required = np.ceil(total_load_kw / (panel_wattage / 1000)) # Number of panels required # Battery capacity estimation (for Off-Grid and Hybrid) if system_type in ["Off-Grid", "Hybrid"]: battery_capacity = total_load_kw * 6 # Assuming 6 hours of backup for Off-Grid/Hybrid else: battery_capacity = 0 # No battery needed for On-Grid # Inverter sizing (assumed 1.2 times the total load for safety) inverter_capacity = total_load_kw * 1.2 # DC cable sizing (estimate based on total load and distance) dc_cable_size = 10 # Dummy value, in meters # Average daily electricity production from solar panels avg_daily_production = panels_required * panel_wattage * 5 / 1000 # Assuming 5 hours of sunlight per day return panels_required, battery_capacity, inverter_capacity, dc_cable_size, avg_daily_production # App UI st.title("Solar System Installation Estimator") st.markdown(""" **Welcome to the Solar System Estimator!** Use this app to estimate the requirements for your solar system based on your home appliances and preferences. """) # Collecting user input st.sidebar.header("Enter your details") num_stories = st.sidebar.selectbox("Number of Stories", ["Single Story", "Two Story"]) system_type = st.sidebar.selectbox("System Type", ["On-Grid", "Off-Grid", "Hybrid"]) # Default wattage values and adjustable wattage inputs equipment = { "Fan": {'wattage': 80, 'count': st.sidebar.number_input("Number of Fans", min_value=0, value=2), 'adjustable_wattage': st.sidebar.slider("Fan Wattage (W)", 40, 150, 80)}, "AC": {'wattage': 1500, 'count': st.sidebar.number_input("Number of ACs", min_value=0, value=1), 'adjustable_wattage': st.sidebar.slider("AC Wattage (W)", 1000, 2500, 1500)}, "Fridge": {'wattage': 200, 'count': st.sidebar.number_input("Number of Fridges", min_value=0, value=1), 'adjustable_wattage': st.sidebar.slider("Fridge Wattage (W)", 100, 400, 200)}, "Tube Lights": {'wattage': 40, 'count': st.sidebar.number_input("Number of Tube Lights", min_value=0, value=5), 'adjustable_wattage': st.sidebar.slider("Tube Light Wattage (W)", 20, 100, 40)}, "Iron": {'wattage': 1200, 'count': st.sidebar.number_input("Number of Irons", min_value=0, value=1), 'adjustable_wattage': st.sidebar.slider("Iron Wattage (W)", 800, 2000, 1200)}, "Electric Motor Pump": {'wattage': 500, 'count': st.sidebar.number_input("Number of Electric Motor Pumps", min_value=0, value=1), 'adjustable_wattage': st.sidebar.slider("Motor Pump Wattage (W)", 100, 1000, 500)}, "Energy Saver": {'wattage': 15, 'count': st.sidebar.number_input("Number of Energy Savers", min_value=0, value=5), 'adjustable_wattage': st.sidebar.slider("Energy Saver Wattage (W)", 10, 40, 15)}, "Electric Geyser": {'wattage': 3000, 'count': st.sidebar.number_input("Number of Electric Geysers", min_value=0, value=1), 'adjustable_wattage': st.sidebar.slider("Geyser Wattage (W)", 1000, 5000, 3000)}, } # Adjust wattage of each appliance based on user input for appliance, values in equipment.items(): values['wattage'] = values['adjustable_wattage'] # Button to calculate if st.sidebar.button("Estimate Solar Requirements"): panels, battery, inverter, cable, avg_daily_production = calculate_requirements(equipment, system_type) # Display results st.subheader(f"Estimated Solar System Requirements ({system_type} Solution)") # Display load summary st.write(f"Total Load: {sum([values['wattage'] * values['count'] for values in equipment.values()])} W") # List the components required for installation st.write("### Required Components for Solar Installation:") st.write(f"- **Solar Panels**: {panels} panels (Each panel is 300W)") if system_type != "On-Grid": st.write(f"- **Battery Capacity**: {battery} kWh (for {system_type} system)") else: st.write("- **Battery**: No battery required for On-Grid system") st.write(f"- **Inverter Capacity**: {inverter:.2f} kW") st.write(f"- **DC Cable**: {cable} meters (estimated length)") # Average daily electricity production (kWh) st.write(f"**Average Daily Electricity Production**: {avg_daily_production:.2f} kWh") # Display appliance summary st.write("### Appliance Summary:") for appliance, values in equipment.items(): st.write(f"- {values['count']} {appliance}(s) with {values['wattage']}W each") # Prepare a quotation string quotation = f""" Solar System Quotation ------------------------ System Type: {system_type} Number of Stories: {num_stories} Total Load: {sum([values['wattage'] * values['count'] for values in equipment.values()])} W Solar Panels Required: {panels} panels (550W each) Battery Capacity: {battery} kWh (if Off-Grid/Hybrid) Inverter Capacity: {inverter:.2f} kW DC Cable Length: {cable} meters Average Daily Production: {avg_daily_production:.2f} kWh Appliance Details: ------------------- """ for appliance, values in equipment.items(): quotation += f"{values['count']} {appliance}(s) with {values['wattage']}W each\n" # Convert the string quotation to bytes quotation_bytes = quotation.encode('utf-8') # Provide the download button st.download_button( label="Download Quotation", data=quotation_bytes, file_name="solar_quotation.txt", mime="text/plain" ) # About Section st.sidebar.markdown(""" ## How This App Works: - The app asks for the number of each device (Fans, ACs, Lights, etc.) and their wattage to estimate load. - Based on your inputs, it suggests the number of solar panels, battery capacity, inverter, and DC cable requirement. - Three system types are available: **On-Grid**, **Off-Grid**, and **Hybrid**. - The app takes into account whether your building is a single-story or two-story structure for more accurate recommendations. """)