Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,192 +1,161 @@
|
|
| 1 |
-
# Electrical Calculations Software
|
| 2 |
-
# Covering generation, transmission, distribution, load flow, short circuit, cable sizing, transformers, power factor, harmonics
|
| 3 |
-
|
| 4 |
import streamlit as st
|
| 5 |
import numpy as np
|
| 6 |
|
| 7 |
-
# Page
|
| 8 |
-
st.set_page_config(page_title="
|
| 9 |
-
st.title("⚡ Electrical Engineering
|
| 10 |
|
| 11 |
# Sidebar Navigation
|
| 12 |
-
st.sidebar.title("Navigation")
|
| 13 |
-
section = st.sidebar.
|
| 14 |
"Generation",
|
| 15 |
"Transmission",
|
| 16 |
"Distribution",
|
| 17 |
"Power Quality",
|
| 18 |
"Miscellaneous",
|
| 19 |
-
"Standards
|
| 20 |
])
|
| 21 |
|
| 22 |
-
#
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
if section == "Generation":
|
| 28 |
-
st.header("🔋
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
"
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
if gen_calc == "Load Factor":
|
| 37 |
-
avg_load = st.number_input("Average Load (MW)", min_value=0.0)
|
| 38 |
-
peak_load = st.number_input("Peak Load (MW)", min_value=0.1)
|
| 39 |
-
if st.button("Calculate Load Factor"):
|
| 40 |
load_factor = avg_load / peak_load
|
| 41 |
-
st.success(f"Load Factor
|
| 42 |
-
|
| 43 |
-
elif
|
| 44 |
-
actual_output = st.
|
| 45 |
-
max_output = st.
|
| 46 |
-
if
|
| 47 |
-
|
| 48 |
-
st.success(f"Plant Capacity Factor
|
| 49 |
-
|
| 50 |
-
elif
|
| 51 |
-
total_cost = st.
|
| 52 |
-
|
| 53 |
-
if
|
| 54 |
-
|
| 55 |
-
st.success(f"Cost per MWh
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
capacity_mw = st.number_input("Installed Capacity (MW)", min_value=0.0)
|
| 59 |
-
operating_hours = st.number_input("Operating Hours", min_value=0.0)
|
| 60 |
-
if st.button("Calculate Total Energy"):
|
| 61 |
-
total_energy = capacity_mw * operating_hours
|
| 62 |
-
st.success(f"Total Energy Generated = {total_energy:.2f} MWh")
|
| 63 |
-
|
| 64 |
-
# Transmission Section
|
| 65 |
elif section == "Transmission":
|
| 66 |
-
st.header("
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
if area_unit == "Acres":
|
| 93 |
-
m2 = area_value * M2_IN_ACRE
|
| 94 |
-
elif area_unit == "m²":
|
| 95 |
-
m2 = area_value
|
| 96 |
-
elif area_unit == "km²":
|
| 97 |
-
m2 = area_value * M2_IN_KM2
|
| 98 |
-
|
| 99 |
-
km2 = m2 / M2_IN_KM2
|
| 100 |
-
required_mw = km2 * density
|
| 101 |
-
|
| 102 |
-
st.metric("Area (km²)", f"{km2:.2f}")
|
| 103 |
-
st.metric("Required MW", f"{required_mw:.2f}")
|
| 104 |
-
|
| 105 |
-
# Distribution Section
|
| 106 |
elif section == "Distribution":
|
| 107 |
-
st.header("
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
elif dist_calc == "Transformer Sizing":
|
| 131 |
-
connected_load = st.number_input("Connected Load (kW)", min_value=0.0)
|
| 132 |
-
power_factor = st.number_input("Power Factor", min_value=0.1, max_value=1.0)
|
| 133 |
-
if st.button("Calculate Transformer Size"):
|
| 134 |
-
size = connected_load / power_factor
|
| 135 |
-
st.success(f"Transformer Size = {size:.2f} kVA")
|
| 136 |
-
|
| 137 |
-
# Power Quality Section
|
| 138 |
elif section == "Power Quality":
|
| 139 |
-
st.header("
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
])
|
| 167 |
-
|
| 168 |
-
if misc_calc == "Apparent Power":
|
| 169 |
-
real_power = st.number_input("Real Power (W)", min_value=0.0)
|
| 170 |
-
reactive_power = st.number_input("Reactive Power (VAR)", min_value=0.0)
|
| 171 |
-
if st.button("Calculate Apparent Power"):
|
| 172 |
-
apparent = np.sqrt(real_power**2 + reactive_power**2)
|
| 173 |
-
st.success(f"Apparent Power = {apparent:.2f} VA")
|
| 174 |
-
|
| 175 |
-
elif misc_calc == "Resonant Frequency":
|
| 176 |
-
L = st.number_input("Inductance (H)", min_value=0.000001)
|
| 177 |
-
C = st.number_input("Capacitance (F)", min_value=0.000001)
|
| 178 |
-
if st.button("Calculate Resonant Frequency"):
|
| 179 |
-
freq = 1 / (2 * np.pi * np.sqrt(L * C))
|
| 180 |
-
st.success(f"Resonant Frequency = {freq:.2f} Hz")
|
| 181 |
-
|
| 182 |
-
# Standards and Codes Section
|
| 183 |
-
elif section == "Standards & Codes":
|
| 184 |
-
st.header("📚 Electrical Standards and Documents")
|
| 185 |
-
st.info("Upload NEPRA codes, IEEE standards, or IEC guidelines for reference.")
|
| 186 |
-
uploaded_file = st.file_uploader("Upload Document", type=["pdf", "docx", "txt"])
|
| 187 |
if uploaded_file:
|
| 188 |
-
st.success(f"Uploaded
|
| 189 |
-
|
| 190 |
|
| 191 |
-
#
|
| 192 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import numpy as np
|
| 3 |
|
| 4 |
+
# Page Configuration
|
| 5 |
+
st.set_page_config(page_title="Ultimate Electrical Engineering Calculator", layout="wide", page_icon="⚡")
|
| 6 |
+
st.title("⚡ Electrical Engineering Ultimate Calculator")
|
| 7 |
|
| 8 |
# Sidebar Navigation
|
| 9 |
+
st.sidebar.title("🔍 Navigation")
|
| 10 |
+
section = st.sidebar.selectbox("Go to Section", [
|
| 11 |
"Generation",
|
| 12 |
"Transmission",
|
| 13 |
"Distribution",
|
| 14 |
"Power Quality",
|
| 15 |
"Miscellaneous",
|
| 16 |
+
"NEPRA Standards"
|
| 17 |
])
|
| 18 |
|
| 19 |
+
# Utility Functions
|
| 20 |
+
def calculate_area_conversions(area_acres):
|
| 21 |
+
m2 = area_acres * 4046.86
|
| 22 |
+
km2 = area_acres * 0.00404686
|
| 23 |
+
return m2, km2
|
| 24 |
+
|
| 25 |
+
# Formulas Documentation
|
| 26 |
+
formulas = {
|
| 27 |
+
# Generation
|
| 28 |
+
"Load Factor": "Load Factor = Average Load / Peak Load",
|
| 29 |
+
"Plant Capacity Factor": "Plant Capacity Factor = Actual Output / Maximum Possible Output",
|
| 30 |
+
"Cost per MWh": "Cost per MWh = Total Cost / Total Energy Generated",
|
| 31 |
+
|
| 32 |
+
# Transmission
|
| 33 |
+
"Impedance": "Z = √(R² + X²)",
|
| 34 |
+
"Short Circuit Current": "Isc = Voltage / (√3 × Impedance)",
|
| 35 |
+
"Grid Requirements": "Grids = Area × Power Density (MW/km²)",
|
| 36 |
+
|
| 37 |
+
# Distribution
|
| 38 |
+
"Voltage Drop": "Voltage Drop = 2 × Resistance × Current",
|
| 39 |
+
"Cable Size": "Cable Size = Current / Permissible Current Density",
|
| 40 |
+
"Transformer Sizing": "Transformer Size = Connected Load / Power Factor",
|
| 41 |
+
|
| 42 |
+
# Power Quality
|
| 43 |
+
"Apparent Power": "S = √(P² + Q²)",
|
| 44 |
+
"Resonant Frequency": "f = 1 / (2π√(LC))",
|
| 45 |
+
"Harmonic Frequency": "Harmonic Frequency = Base Frequency × Harmonic Order"
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
# Section: Generation
|
| 49 |
if section == "Generation":
|
| 50 |
+
st.header("🔋 Generation Calculations")
|
| 51 |
+
calc_type = st.selectbox("Select Calculation", ["Load Factor", "Plant Capacity Factor", "Cost per MWh"])
|
| 52 |
+
st.markdown(f"**Formula Used:** {formulas[calc_type]}")
|
| 53 |
+
|
| 54 |
+
if calc_type == "Load Factor":
|
| 55 |
+
avg_load = st.slider("Average Load (MW)", 0.0, 500.0, 100.0)
|
| 56 |
+
peak_load = st.slider("Peak Load (MW)", 0.1, 500.0, 120.0)
|
| 57 |
+
if peak_load > 0:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
load_factor = avg_load / peak_load
|
| 59 |
+
st.success(f"Load Factor: {load_factor:.2f} ({load_factor * 100:.2f}%)")
|
| 60 |
+
|
| 61 |
+
elif calc_type == "Plant Capacity Factor":
|
| 62 |
+
actual_output = st.slider("Actual Output (MWh)", 0.0, 10000.0, 5000.0)
|
| 63 |
+
max_output = st.slider("Maximum Output (MWh)", 1.0, 10000.0, 8000.0)
|
| 64 |
+
if max_output > 0:
|
| 65 |
+
capacity_factor = actual_output / max_output
|
| 66 |
+
st.success(f"Plant Capacity Factor: {capacity_factor:.2f} ({capacity_factor * 100:.2f}%)")
|
| 67 |
+
|
| 68 |
+
elif calc_type == "Cost per MWh":
|
| 69 |
+
total_cost = st.slider("Total Cost ($)", 0.0, 500000.0, 100000.0)
|
| 70 |
+
total_energy = st.slider("Total Energy (MWh)", 1.0, 10000.0, 5000.0)
|
| 71 |
+
if total_energy > 0:
|
| 72 |
+
cost_per_mwh = total_cost / total_energy
|
| 73 |
+
st.success(f"Cost per MWh: ${cost_per_mwh:.2f}")
|
| 74 |
+
|
| 75 |
+
# Section: Transmission
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
elif section == "Transmission":
|
| 77 |
+
st.header("🌐 Transmission Calculations")
|
| 78 |
+
calc_type = st.selectbox("Select Calculation", ["Impedance", "Short Circuit Current", "Grid Requirements"])
|
| 79 |
+
st.markdown(f"**Formula Used:** {formulas[calc_type]}")
|
| 80 |
+
|
| 81 |
+
if calc_type == "Impedance":
|
| 82 |
+
resistance = st.slider("Resistance (Ω)", 0.0, 100.0, 10.0)
|
| 83 |
+
reactance = st.slider("Reactance (Ω)", 0.0, 100.0, 5.0)
|
| 84 |
+
impedance = np.sqrt(resistance**2 + reactance**2)
|
| 85 |
+
st.success(f"Total Impedance: {impedance:.2f} Ω")
|
| 86 |
+
|
| 87 |
+
elif calc_type == "Short Circuit Current":
|
| 88 |
+
voltage = st.slider("Voltage (V)", 100.0, 50000.0, 11000.0)
|
| 89 |
+
impedance = st.slider("System Impedance (Ω)", 0.01, 100.0, 5.0)
|
| 90 |
+
isc = voltage / (np.sqrt(3) * impedance)
|
| 91 |
+
st.success(f"Short Circuit Current: {isc:.2f} A")
|
| 92 |
+
|
| 93 |
+
elif calc_type == "Grid Requirements":
|
| 94 |
+
area_acres = st.slider("Area (acres)", 1.0, 10000.0, 100.0)
|
| 95 |
+
power_density = st.slider("Power Density (MW/km²)", 1.0, 10.0, 5.0)
|
| 96 |
+
m2, km2 = calculate_area_conversions(area_acres)
|
| 97 |
+
grids = km2 * power_density
|
| 98 |
+
st.metric("Area (m²)", f"{m2:.2f} m²")
|
| 99 |
+
st.metric("Area (km²)", f"{km2:.4f} km²")
|
| 100 |
+
st.success(f"Estimated Power Generation: {grids:.2f} MW")
|
| 101 |
+
|
| 102 |
+
# Section: Distribution
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
elif section == "Distribution":
|
| 104 |
+
st.header("🏘️ Distribution Calculations")
|
| 105 |
+
calc_type = st.selectbox("Select Calculation", ["Voltage Drop", "Cable Size", "Transformer Sizing"])
|
| 106 |
+
st.markdown(f"**Formula Used:** {formulas[calc_type]}")
|
| 107 |
+
|
| 108 |
+
if calc_type == "Voltage Drop":
|
| 109 |
+
resistance = st.slider("Resistance (Ω)", 0.0, 10.0, 1.0)
|
| 110 |
+
current = st.slider("Current (A)", 0.0, 1000.0, 100.0)
|
| 111 |
+
voltage_drop = 2 * resistance * current
|
| 112 |
+
st.success(f"Voltage Drop: {voltage_drop:.2f} V")
|
| 113 |
+
|
| 114 |
+
elif calc_type == "Cable Size":
|
| 115 |
+
current = st.slider("Current (A)", 0.0, 5000.0, 200.0)
|
| 116 |
+
permissible_density = st.slider("Permissible Current Density (A/mm²)", 1.0, 10.0, 5.0)
|
| 117 |
+
cable_size = current / permissible_density
|
| 118 |
+
st.success(f"Required Cable Size: {cable_size:.2f} mm²")
|
| 119 |
+
|
| 120 |
+
elif calc_type == "Transformer Sizing":
|
| 121 |
+
load = st.slider("Connected Load (kW)", 0.0, 5000.0, 1000.0)
|
| 122 |
+
pf = st.slider("Power Factor", 0.1, 1.0, 0.9)
|
| 123 |
+
transformer_size = load / pf
|
| 124 |
+
st.success(f"Required Transformer Size: {transformer_size:.2f} kVA")
|
| 125 |
+
|
| 126 |
+
# Section: Power Quality
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
elif section == "Power Quality":
|
| 128 |
+
st.header("⚡ Power Quality Calculations")
|
| 129 |
+
calc_type = st.selectbox("Select Calculation", ["Apparent Power", "Resonant Frequency", "Harmonic Frequency"])
|
| 130 |
+
st.markdown(f"**Formula Used:** {formulas[calc_type]}")
|
| 131 |
+
|
| 132 |
+
if calc_type == "Apparent Power":
|
| 133 |
+
real_power = st.slider("Real Power (W)", 0.0, 100000.0, 10000.0)
|
| 134 |
+
reactive_power = st.slider("Reactive Power (VAR)", 0.0, 100000.0, 5000.0)
|
| 135 |
+
apparent_power = np.sqrt(real_power**2 + reactive_power**2)
|
| 136 |
+
st.success(f"Apparent Power: {apparent_power:.2f} VA")
|
| 137 |
+
|
| 138 |
+
elif calc_type == "Resonant Frequency":
|
| 139 |
+
inductance = st.slider("Inductance (H)", 0.0001, 1.0, 0.01)
|
| 140 |
+
capacitance = st.slider("Capacitance (F)", 0.000001, 0.01, 0.00001)
|
| 141 |
+
freq = 1 / (2 * np.pi * np.sqrt(inductance * capacitance))
|
| 142 |
+
st.success(f"Resonant Frequency: {freq:.2f} Hz")
|
| 143 |
+
|
| 144 |
+
elif calc_type == "Harmonic Frequency":
|
| 145 |
+
base_freq = st.slider("Base Frequency (Hz)", 40.0, 70.0, 50.0)
|
| 146 |
+
order = st.slider("Harmonic Order", 1, 50, 3)
|
| 147 |
+
harmonic_freq = base_freq * order
|
| 148 |
+
st.success(f"Harmonic Frequency: {harmonic_freq:.2f} Hz")
|
| 149 |
+
|
| 150 |
+
# Section: NEPRA Standards
|
| 151 |
+
elif section == "NEPRA Standards":
|
| 152 |
+
st.header("📚 NEPRA Standards and Documentation")
|
| 153 |
+
st.info("Upload or download official NEPRA documents here.")
|
| 154 |
+
uploaded_file = st.file_uploader("Upload NEPRA Standard Document", type=["pdf", "docx"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
if uploaded_file:
|
| 156 |
+
st.success(f"Uploaded: {uploaded_file.name}")
|
| 157 |
+
st.download_button(label="Download Sample NEPRA Guidelines", data=b"Sample NEPRA Content", file_name="nepra_sample.docx")
|
| 158 |
|
| 159 |
+
# Footer
|
| 160 |
+
st.markdown("---")
|
| 161 |
+
st.caption("Developed with ❤️ for Electrical Engineers")
|