Navyia commited on
Commit
995c6aa
·
verified ·
1 Parent(s): 5b3b4d6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +142 -173
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 config
8
- st.set_page_config(page_title="Comprehensive Electrical Engineering Calculator", layout="wide")
9
- st.title("⚡ Electrical Engineering Mega Calculator")
10
 
11
  # Sidebar Navigation
12
- st.sidebar.title("Navigation")
13
- section = st.sidebar.radio("Select Section", [
14
  "Generation",
15
  "Transmission",
16
  "Distribution",
17
  "Power Quality",
18
  "Miscellaneous",
19
- "Standards & Codes"
20
  ])
21
 
22
- # Constants for unit conversions
23
- M2_IN_ACRE = 4046.86
24
- M2_IN_KM2 = 1_000_000
25
-
26
- # Generation Section
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  if section == "Generation":
28
- st.header("🔋 Power Generation Calculations")
29
- gen_calc = st.selectbox("Choose Calculation", [
30
- "Load Factor",
31
- "Plant Capacity Factor",
32
- "Cost per MWh",
33
- "Energy Generation"
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 = {load_factor:.2f} ({load_factor*100:.2f}%)")
42
-
43
- elif gen_calc == "Plant Capacity Factor":
44
- actual_output = st.number_input("Actual Energy Output (MWh)", min_value=0.0)
45
- max_output = st.number_input("Maximum Possible Output (MWh)", min_value=0.1)
46
- if st.button("Calculate Plant Capacity Factor"):
47
- pcf = actual_output / max_output
48
- st.success(f"Plant Capacity Factor = {pcf:.2f} ({pcf*100:.2f}%)")
49
-
50
- elif gen_calc == "Cost per MWh":
51
- total_cost = st.number_input("Total Generation Cost (USD)", min_value=0.0)
52
- energy_generated = st.number_input("Energy Generated (MWh)", min_value=0.1)
53
- if st.button("Calculate Cost/MWh"):
54
- cost_mwh = total_cost / energy_generated
55
- st.success(f"Cost per MWh = ${cost_mwh:.2f}")
56
-
57
- elif gen_calc == "Energy Generation":
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("🚧 Transmission System Calculations")
67
- trans_calc = st.selectbox("Choose Calculation", [
68
- "Impedance Calculation",
69
- "Short Circuit Current",
70
- "Grid Requirement"
71
- ])
72
-
73
- if trans_calc == "Impedance Calculation":
74
- resistance = st.number_input("Resistance (Ohms)", min_value=0.0)
75
- reactance = st.number_input("Reactance (Ohms)", min_value=0.0)
76
- if st.button("Calculate Impedance"):
77
- impedance = np.sqrt(resistance**2 + reactance**2)
78
- st.success(f"Impedance = {impedance:.4f} Ω")
79
-
80
- elif trans_calc == "Short Circuit Current":
81
- voltage = st.number_input("System Voltage (V)", min_value=0.1)
82
- impedance = st.number_input("Impedance (Ohms)", min_value=0.01)
83
- if st.button("Calculate Isc"):
84
- isc = voltage / (np.sqrt(3) * impedance)
85
- st.success(f"Short Circuit Current = {isc:.2f} A")
86
-
87
- elif trans_calc == "Grid Requirement":
88
- area_unit = st.selectbox("Area Unit", ["Acres", "m²", "km²"])
89
- area_value = st.number_input(f"Area ({area_unit})", min_value=0.1)
90
- density = st.slider("Power Density (MW/km²)", 5.0, 100.0, 30.0)
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("🏙️ Distribution System Calculations")
108
- dist_calc = st.selectbox("Choose Calculation", [
109
- "Cable Sizing",
110
- "Voltage Drop",
111
- "Transformer Sizing"
112
- ])
113
-
114
- if dist_calc == "Cable Sizing":
115
- current = st.number_input("Current (A)", min_value=0.0)
116
- density = st.number_input("Permissible Current Density (A/mm²)", min_value=0.01)
117
- if st.button("Calculate Cable Size"):
118
- cable_area = current / density
119
- st.success(f"Required Cable Area = {cable_area:.2f} mm²")
120
-
121
- elif dist_calc == "Voltage Drop":
122
- resistance = st.number_input("Resistance per phase (Ohms)", min_value=0.0)
123
- current = st.number_input("Current (A)", min_value=0.0)
124
- system_voltage = st.number_input("System Voltage (V)", min_value=0.1)
125
- if st.button("Calculate Voltage Drop"):
126
- vd = 2 * resistance * current
127
- percentage = (vd / system_voltage) * 100
128
- st.success(f"Voltage Drop = {vd:.2f} V ({percentage:.2f}%)")
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("🎯 Power Quality Calculations")
140
- quality_calc = st.selectbox("Choose Calculation", [
141
- "Power Factor Correction",
142
- "Harmonic Frequency"
143
- ])
144
-
145
- if quality_calc == "Power Factor Correction":
146
- existing_pf = st.number_input("Existing Power Factor", min_value=0.1, max_value=1.0)
147
- desired_pf = st.number_input("Desired Power Factor", min_value=0.1, max_value=1.0)
148
- load_kw = st.number_input("Load (kW)", min_value=0.0)
149
- if st.button("Calculate Required kVAR"):
150
- kvar_needed = load_kw * (np.tan(np.arccos(existing_pf)) - np.tan(np.arccos(desired_pf)))
151
- st.success(f"Reactive Power (kVAR) needed = {kvar_needed:.2f}")
152
-
153
- elif quality_calc == "Harmonic Frequency":
154
- base_freq = st.number_input("Base Frequency (Hz)", value=50)
155
- harmonic_order = st.number_input("Harmonic Order", value=3)
156
- if st.button("Calculate Harmonic Frequency"):
157
- harmonic_freq = base_freq * harmonic_order
158
- st.success(f"Harmonic Frequency = {harmonic_freq:.2f} Hz")
159
-
160
- # Miscellaneous Section
161
- elif section == "Miscellaneous":
162
- st.header("📈 Other Useful Calculations")
163
- misc_calc = st.selectbox("Choose Calculation", [
164
- "Apparent Power",
165
- "Resonant Frequency"
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 file: {uploaded_file.name}")
189
- st.download_button("Download File", uploaded_file, file_name=uploaded_file.name)
190
 
191
- # End of Code
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} ")
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")