import streamlit as st import math import itertools # Title st.title("⚡ Three-Phase Power Calculator - Reactive Power Compensation Panel") # Sidebar st.sidebar.header("🔧 Input Parameters") voltage = st.sidebar.number_input("Enter Voltage (V)", min_value=0.0, step=0.1) current = st.sidebar.number_input("Enter Current (A)", min_value=0.0, step=0.1) power_factor = st.sidebar.slider("Power Factor (optional, default = 1)", 0.0, 1.0, 1.0, step=0.01) frequency = st.sidebar.selectbox("Select Frequency", [50, 60], index=0) # Frequency in Hz # Available Capacitor Units (kVAR) available_capacitors = [25, 20, 15, 10, 5, 2.5, 1.5, 1] # Main Tabs tab1, tab2, tab3 = st.tabs(["📊 Calculation", "🧮 Capacitor Bank Design", "📋 About"]) with tab1: st.header("📊 Electrical Calculation") if st.button("Calculate Power Parameters"): if voltage > 0 and current > 0: # Apparent Power (VA) for Three-Phase apparent_power = math.sqrt(3) * voltage * current # Real Power (kW) real_power = apparent_power * power_factor / 1000 # W to kW # Reactive Power (kVAR) try: reactive_power = math.sqrt((apparent_power / 1000)**2 - real_power**2) except ValueError: reactive_power = 0.0 # Calculated PF calculated_pf = real_power * 1000 / apparent_power if apparent_power > 0 else 0 st.subheader("🔎 Results:") st.success(f"Apparent Power: **{round(apparent_power, 2)} VA**") st.success(f"Real Power: **{round(real_power, 2)} kW**") st.success(f"Reactive Power: **{round(reactive_power, 2)} kVAR**") st.info(f"Calculated Power Factor: **{round(calculated_pf, 2)}**") st.session_state['reactive_power'] = reactive_power else: st.warning("⚠️ Please enter valid Voltage and Current!") with tab2: st.header("🧮 Capacitor Bank Designer") if 'reactive_power' in st.session_state and st.session_state['reactive_power'] > 0: reactive_power = st.session_state['reactive_power'] st.success(f"Target Compensation: **{round(reactive_power,2)} kVAR**") num_caps = st.number_input("How many capacitors do you want to use?", min_value=1, step=1) if num_caps > 0: if st.button("Find Capacitor Combination"): # Try to find a combination found = False best_combo = None min_error = float('inf') # Generate combinations with repetition for combo in itertools.combinations_with_replacement(available_capacitors, int(num_caps)): total = sum(combo) error = abs(total - reactive_power) # Find the combination closest to the required reactive power if error < min_error: min_error = error best_combo = combo if error == 0: break # exact match found if best_combo: st.subheader("🛠️ Suggested Capacitor Sizes:") for idx, cap in enumerate(best_combo, start=1): st.write(f"🔹 Capacitor {idx}: **{cap} kVAR**") total_kvar = sum(best_combo) st.success(f"✅ Total Compensation: **{round(total_kvar,2)} kVAR**") if abs(total_kvar - reactive_power) > 0.5: st.warning("⚠️ Small mismatch detected. Fine-tuning may be required.") else: st.error("❌ Could not find a suitable combination with the given number of capacitors.") else: st.info("Please first calculate in 📊 Calculation tab.") with tab3: st.header("📋 About This Tool") st.markdown(""" This app is designed for engineers and manufacturers to: - Calculate three-phase system parameters - Estimate reactive power - Design capacitor banks based on user preferences --- **Developed by:** Muhendis & ChatGPT 🚀 """)