import streamlit as st import numpy as np # Page Configuration st.set_page_config(page_title="Ultimate Electrical Engineering Calculator", layout="wide", page_icon="⚡") st.title("⚡ Electrical Engineering Ultimate Calculator") # Sidebar Navigation st.sidebar.title("🔍 Navigation") section = st.sidebar.selectbox("Go to Section", [ "Generation", "Transmission", "Distribution", "Power Quality", "Miscellaneous", "NEPRA Standards" ]) # Utility Functions def calculate_area_conversions(area_acres): m2 = area_acres * 4046.86 km2 = area_acres * 0.00404686 return m2, km2 # Formulas Documentation formulas = { # Generation "Load Factor": "Load Factor = Average Load / Peak Load", "Plant Capacity Factor": "Plant Capacity Factor = Actual Output / Maximum Possible Output", "Cost per MWh": "Cost per MWh = Total Cost / Total Energy Generated", # Transmission "Impedance": "Z = √(R² + X²)", "Short Circuit Current": "Isc = Voltage / (√3 × Impedance)", "Grid Requirements": "Grids = Area × Power Density (MW/km²)", # Distribution "Voltage Drop": "Voltage Drop = 2 × Resistance × Current", "Cable Size": "Cable Size = Current / Permissible Current Density", "Transformer Sizing": "Transformer Size = Connected Load / Power Factor", # Power Quality "Apparent Power": "S = √(P² + Q²)", "Resonant Frequency": "f = 1 / (2π√(LC))", "Harmonic Frequency": "Harmonic Frequency = Base Frequency × Harmonic Order" } # Section: Generation if section == "Generation": st.header("🔋 Generation Calculations") calc_type = st.selectbox("Select Calculation", ["Load Factor", "Plant Capacity Factor", "Cost per MWh"]) st.markdown(f"**Formula Used:** {formulas[calc_type]}") if calc_type == "Load Factor": avg_load = st.slider("Average Load (MW)", 0.0, 500.0, 100.0) peak_load = st.slider("Peak Load (MW)", 0.1, 500.0, 120.0) if peak_load > 0: load_factor = avg_load / peak_load st.success(f"Load Factor: {load_factor:.2f} ({load_factor * 100:.2f}%)") elif calc_type == "Plant Capacity Factor": actual_output = st.slider("Actual Output (MWh)", 0.0, 10000.0, 5000.0) max_output = st.slider("Maximum Output (MWh)", 1.0, 10000.0, 8000.0) if max_output > 0: capacity_factor = actual_output / max_output st.success(f"Plant Capacity Factor: {capacity_factor:.2f} ({capacity_factor * 100:.2f}%)") elif calc_type == "Cost per MWh": total_cost = st.slider("Total Cost ($)", 0.0, 500000.0, 100000.0) total_energy = st.slider("Total Energy (MWh)", 1.0, 10000.0, 5000.0) if total_energy > 0: cost_per_mwh = total_cost / total_energy st.success(f"Cost per MWh: ${cost_per_mwh:.2f}") # Section: Transmission elif section == "Transmission": st.header("🌐 Transmission Calculations") calc_type = st.selectbox("Select Calculation", ["Impedance", "Short Circuit Current", "Grid Requirements"]) st.markdown(f"**Formula Used:** {formulas[calc_type]}") if calc_type == "Impedance": resistance = st.slider("Resistance (Ω)", 0.0, 100.0, 10.0) reactance = st.slider("Reactance (Ω)", 0.0, 100.0, 5.0) impedance = np.sqrt(resistance**2 + reactance**2) st.success(f"Total Impedance: {impedance:.2f} Ω") elif calc_type == "Short Circuit Current": voltage = st.slider("Voltage (V)", 100.0, 50000.0, 11000.0) impedance = st.slider("System Impedance (Ω)", 0.01, 100.0, 5.0) isc = voltage / (np.sqrt(3) * impedance) st.success(f"Short Circuit Current: {isc:.2f} A") elif calc_type == "Grid Requirements": area_acres = st.slider("Area (acres)", 1.0, 10000.0, 100.0) power_density = st.slider("Power Density (MW/km²)", 1.0, 10.0, 5.0) m2, km2 = calculate_area_conversions(area_acres) grids = km2 * power_density st.metric("Area (m²)", f"{m2:.2f} m²") st.metric("Area (km²)", f"{km2:.4f} km²") st.success(f"Estimated Power Generation: {grids:.2f} MW") # Section: Distribution elif section == "Distribution": st.header("🏘️ Distribution Calculations") calc_type = st.selectbox("Select Calculation", ["Voltage Drop", "Cable Size", "Transformer Sizing"]) st.markdown(f"**Formula Used:** {formulas[calc_type]}") if calc_type == "Voltage Drop": resistance = st.slider("Resistance (Ω)", 0.0, 10.0, 1.0) current = st.slider("Current (A)", 0.0, 1000.0, 100.0) voltage_drop = 2 * resistance * current st.success(f"Voltage Drop: {voltage_drop:.2f} V") elif calc_type == "Cable Size": current = st.slider("Current (A)", 0.0, 5000.0, 200.0) permissible_density = st.slider("Permissible Current Density (A/mm²)", 1.0, 10.0, 5.0) cable_size = current / permissible_density st.success(f"Required Cable Size: {cable_size:.2f} mm²") elif calc_type == "Transformer Sizing": load = st.slider("Connected Load (kW)", 0.0, 5000.0, 1000.0) pf = st.slider("Power Factor", 0.1, 1.0, 0.9) transformer_size = load / pf st.success(f"Required Transformer Size: {transformer_size:.2f} kVA") # Section: Power Quality elif section == "Power Quality": st.header("⚡ Power Quality Calculations") calc_type = st.selectbox("Select Calculation", ["Apparent Power", "Resonant Frequency", "Harmonic Frequency"]) st.markdown(f"**Formula Used:** {formulas[calc_type]}") if calc_type == "Apparent Power": real_power = st.slider("Real Power (W)", 0.0, 100000.0, 10000.0) reactive_power = st.slider("Reactive Power (VAR)", 0.0, 100000.0, 5000.0) apparent_power = np.sqrt(real_power**2 + reactive_power**2) st.success(f"Apparent Power: {apparent_power:.2f} VA") elif calc_type == "Resonant Frequency": inductance = st.slider("Inductance (H)", 0.0001, 1.0, 0.01) capacitance = st.slider("Capacitance (F)", 0.000001, 0.01, 0.00001) freq = 1 / (2 * np.pi * np.sqrt(inductance * capacitance)) st.success(f"Resonant Frequency: {freq:.2f} Hz") elif calc_type == "Harmonic Frequency": base_freq = st.slider("Base Frequency (Hz)", 40.0, 70.0, 50.0) order = st.slider("Harmonic Order", 1, 50, 3) harmonic_freq = base_freq * order st.success(f"Harmonic Frequency: {harmonic_freq:.2f} Hz") # Section: NEPRA Standards elif section == "NEPRA Standards": st.header("📚 NEPRA Standards and Documentation") st.info("Upload or download official NEPRA documents here.") uploaded_file = st.file_uploader("Upload NEPRA Standard Document", type=["pdf", "docx"]) if uploaded_file: st.success(f"Uploaded: {uploaded_file.name}") st.download_button(label="Download Sample NEPRA Guidelines", data=b"Sample NEPRA Content", file_name="nepra_sample.docx") # Footer st.markdown("---") st.caption("Developed with ❤️ for Electrical Engineers")