File size: 3,137 Bytes
81e5bd0
883cf00
81e5bd0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
883cf00
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81e5bd0
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import streamlit as st
import matplotlib.pyplot as plt

# Constants
VOLTAGE_LEVELS = [220, 380, 440]
CABLE_SIZES = {10: 1.5, 20: 2.5, 40: 4, 60: 6, 80: 10, 100: 16}
TRANSFORMER_SIZES = [25, 50, 100, 200, 400, 630, 1000]  # kVA

# Sidebar
st.set_page_config(page_title="Electrical Load Calculator", layout="wide")
st.sidebar.title("Electrical Load Calculation")
st.sidebar.markdown("### Input Parameters")

# Input: Load Details
total_load_kw = st.sidebar.number_input("Enter total load (kW)", min_value=0.0, step=0.1, value=0.0)
power_factor = st.sidebar.slider("Power Factor", 0.5, 1.0, 0.9, 0.01)
voltage_level = st.sidebar.selectbox("Select Voltage Level (V)", VOLTAGE_LEVELS)

# Input: Cable Sizing
distance_meters = st.sidebar.number_input("Enter distance to load (meters)", min_value=1, step=1, value=10)
st.sidebar.markdown("---")

# Columns for Input and Results
col1, col2 = st.columns(2)

# Input Parameters Display
with col1:
    st.header("Input Parameters")
    st.write(f"**Total Load (kW):** {total_load_kw} kW")
    st.write(f"**Power Factor:** {power_factor}")
    st.write(f"**Voltage Level:** {voltage_level} V")
    st.write(f"**Distance to Load:** {distance_meters} meters")

# Calculations
total_load_kva = total_load_kw / power_factor
current_ampere = (total_load_kva * 1000) / voltage_level
recommended_cable_size = next((size for amp, size in CABLE_SIZES.items() if current_ampere <= amp), None)
transformer_size = next((size for size in TRANSFORMER_SIZES if total_load_kva <= size), None)

# Results Display
with col2:
    st.header("Calculation Results")
    st.write(f"**Total Load (kVA):** {total_load_kva:.2f} kVA")
    st.write(f"**Current (Amps):** {current_ampere:.2f} A")
    if recommended_cable_size:
        st.write(f"**Recommended Cable Size:** {recommended_cable_size} mm²")
    else:
        st.error("No suitable cable size found. Increase input voltage or reduce load.")
    if transformer_size:
        st.write(f"**Recommended Transformer Size:** {transformer_size} kVA")
    else:
        st.error("No suitable transformer size found.")

# Visualization
st.markdown("---")
st.header("Visual Representation")
col3, col4 = st.columns(2)

with col3:
    st.subheader("Load vs Transformer Capacity")
    st.bar_chart([total_load_kva, transformer_size if transformer_size else 0])

with col4:
    st.subheader("Load Distribution (kVA)")
    if transformer_size:
        # Pie chart with Matplotlib
        labels = ["Used Load", "Remaining Capacity"]
        sizes = [total_load_kva, max(transformer_size - total_load_kva, 0)]
        colors = ["#FF9999", "#66B3FF"]
        explode = (0.1, 0)  # Highlight the "Used Load" slice

        fig, ax = plt.subplots()
        ax.pie(
            sizes, explode=explode, labels=labels, colors=colors, autopct="%1.1f%%", startangle=140
        )
        ax.axis("equal")  # Equal aspect ratio ensures the pie chart is circular.
        st.pyplot(fig)
    else:
        st.warning("No transformer selected. Unable to display load distribution.")

# Footer
st.sidebar.markdown("---")
st.sidebar.markdown("Developed with ❤️ for Electrical Engineers")