Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,11 +9,13 @@ st.markdown("- Apparent Power (VA)")
|
|
| 9 |
st.markdown("- Real Power (kW)")
|
| 10 |
st.markdown("- Power Factor")
|
| 11 |
st.markdown("- Reactive Power (kVAR)")
|
|
|
|
| 12 |
|
| 13 |
# Inputs
|
| 14 |
voltage = st.number_input("Enter Voltage (V)", min_value=0.0, step=0.1)
|
| 15 |
current = st.number_input("Enter Current (A)", min_value=0.0, step=0.1)
|
| 16 |
power_factor = st.slider("Power Factor (optional, default = 1)", 0.0, 1.0, 1.0, step=0.01)
|
|
|
|
| 17 |
|
| 18 |
# Calculate button
|
| 19 |
if st.button("Calculate"):
|
|
@@ -33,14 +35,32 @@ if st.button("Calculate"):
|
|
| 33 |
# Calculated PF (just for verification)
|
| 34 |
calculated_pf = real_power * 1000 / apparent_power if apparent_power > 0 else 0
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
# Display results
|
| 37 |
st.subheader("Results (Single-Phase):")
|
| 38 |
st.write(f"π Apparent Power: **{round(apparent_power, 2)} VA**")
|
| 39 |
st.write(f"β‘ Real Power: **{round(real_power, 2)} kW**")
|
| 40 |
st.write(f"π Power Factor: **{round(calculated_pf, 2)}**")
|
| 41 |
st.write(f"βοΈ Reactive Power: **{round(reactive_power, 2)} kVAR**")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
else:
|
| 43 |
st.warning("Please enter valid voltage and current values.")
|
| 44 |
|
| 45 |
|
| 46 |
|
|
|
|
|
|
| 9 |
st.markdown("- Real Power (kW)")
|
| 10 |
st.markdown("- Power Factor")
|
| 11 |
st.markdown("- Reactive Power (kVAR)")
|
| 12 |
+
st.markdown("- Capacitor Rating Recommendation to Compensate Reactive Power")
|
| 13 |
|
| 14 |
# Inputs
|
| 15 |
voltage = st.number_input("Enter Voltage (V)", min_value=0.0, step=0.1)
|
| 16 |
current = st.number_input("Enter Current (A)", min_value=0.0, step=0.1)
|
| 17 |
power_factor = st.slider("Power Factor (optional, default = 1)", 0.0, 1.0, 1.0, step=0.01)
|
| 18 |
+
frequency = st.selectbox("Select Frequency", [50, 60], index=0) # Frequency in Hz
|
| 19 |
|
| 20 |
# Calculate button
|
| 21 |
if st.button("Calculate"):
|
|
|
|
| 35 |
# Calculated PF (just for verification)
|
| 36 |
calculated_pf = real_power * 1000 / apparent_power if apparent_power > 0 else 0
|
| 37 |
|
| 38 |
+
# Capacitor sizing formula: Q_c = V^2 * (2 * pi * f * C) / 1000
|
| 39 |
+
# Rearranged to solve for C: C = Q_c * 1000 / (V^2 * 2 * pi * f)
|
| 40 |
+
if reactive_power > 0:
|
| 41 |
+
required_capacitance = reactive_power * 1000 / (voltage**2 * 2 * math.pi * frequency)
|
| 42 |
+
required_capacitance_uF = required_capacitance * 1e6 # Convert to microfarads (uF)
|
| 43 |
+
else:
|
| 44 |
+
required_capacitance_uF = 0.0
|
| 45 |
+
|
| 46 |
# Display results
|
| 47 |
st.subheader("Results (Single-Phase):")
|
| 48 |
st.write(f"π Apparent Power: **{round(apparent_power, 2)} VA**")
|
| 49 |
st.write(f"β‘ Real Power: **{round(real_power, 2)} kW**")
|
| 50 |
st.write(f"π Power Factor: **{round(calculated_pf, 2)}**")
|
| 51 |
st.write(f"βοΈ Reactive Power: **{round(reactive_power, 2)} kVAR**")
|
| 52 |
+
|
| 53 |
+
# Display the capacitor recommendation
|
| 54 |
+
if reactive_power > 0:
|
| 55 |
+
st.subheader("Recommended Capacitor Size:")
|
| 56 |
+
st.write(f"To compensate the **{round(reactive_power, 2)} kVAR** of reactive power:")
|
| 57 |
+
st.write(f"π‘ Required Capacitor Size: **{round(required_capacitance_uF, 2)} Β΅F**")
|
| 58 |
+
else:
|
| 59 |
+
st.write("No compensation needed as reactive power is zero or negative.")
|
| 60 |
+
|
| 61 |
else:
|
| 62 |
st.warning("Please enter valid voltage and current values.")
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
+
|