Update app.py
Browse files
app.py
CHANGED
|
@@ -28,11 +28,50 @@ def set_background(image_file):
|
|
| 28 |
"""
|
| 29 |
st.markdown(page_bg, unsafe_allow_html=True)
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
# EV Connection Logic
|
| 32 |
def manage_ev_connection():
|
| 33 |
global feeders
|
| 34 |
|
| 35 |
-
# Check available slots in other feeders
|
| 36 |
for feeder, data in feeders.items():
|
| 37 |
available_slots = data["max_evs"] - data["connected_evs"]
|
| 38 |
if available_slots > 0:
|
|
@@ -53,6 +92,10 @@ def display_grid_info():
|
|
| 53 |
|
| 54 |
manage_ev_connection()
|
| 55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
# Main function
|
| 57 |
def main():
|
| 58 |
st.sidebar.title("EV Grid Load Optimization")
|
|
|
|
| 28 |
"""
|
| 29 |
st.markdown(page_bg, unsafe_allow_html=True)
|
| 30 |
|
| 31 |
+
# Calculate grid load based on time and dataset
|
| 32 |
+
def calculate_grid_load(df, current_time):
|
| 33 |
+
current_hour = current_time.hour
|
| 34 |
+
hourly_load = df[df["Time"].dt.hour == current_hour]["Grid Load (kW)"].mean()
|
| 35 |
+
return hourly_load
|
| 36 |
+
|
| 37 |
+
# Create a gauge chart for grid load status
|
| 38 |
+
def create_gauge(load_value):
|
| 39 |
+
ranges = [0, 2000, 3000, 4000]
|
| 40 |
+
colors = ['lightgreen', 'green', 'red']
|
| 41 |
+
labels = ['Low', 'Normal', 'High']
|
| 42 |
+
|
| 43 |
+
if load_value < 2000:
|
| 44 |
+
color = colors[0]
|
| 45 |
+
range_label = labels[0]
|
| 46 |
+
elif load_value < 3000:
|
| 47 |
+
color = colors[1]
|
| 48 |
+
range_label = labels[1]
|
| 49 |
+
else:
|
| 50 |
+
color = colors[2]
|
| 51 |
+
range_label = labels[2]
|
| 52 |
+
|
| 53 |
+
fig = go.Figure(go.Indicator(
|
| 54 |
+
mode="gauge+number+delta",
|
| 55 |
+
value=load_value,
|
| 56 |
+
domain={'x': [0, 1], 'y': [0, 1]},
|
| 57 |
+
gauge={
|
| 58 |
+
'axis': {'range': [0, 5000]},
|
| 59 |
+
'bar': {'color': color},
|
| 60 |
+
'steps': [
|
| 61 |
+
{'range': [0, 2000], 'color': 'lightgreen'},
|
| 62 |
+
{'range': [2000, 3000], 'color': 'green'},
|
| 63 |
+
{'range': [3000, 5000], 'color': 'red'}
|
| 64 |
+
],
|
| 65 |
+
},
|
| 66 |
+
title={'text': f"Grid Load Status: {range_label}"},
|
| 67 |
+
delta={'reference': 2000}
|
| 68 |
+
))
|
| 69 |
+
return fig
|
| 70 |
+
|
| 71 |
# EV Connection Logic
|
| 72 |
def manage_ev_connection():
|
| 73 |
global feeders
|
| 74 |
|
|
|
|
| 75 |
for feeder, data in feeders.items():
|
| 76 |
available_slots = data["max_evs"] - data["connected_evs"]
|
| 77 |
if available_slots > 0:
|
|
|
|
| 92 |
|
| 93 |
manage_ev_connection()
|
| 94 |
|
| 95 |
+
# Display the gauge chart based on load value
|
| 96 |
+
grid_load = sum([data["rated_load"] for data in feeders.values()])
|
| 97 |
+
st.plotly_chart(create_gauge(grid_load), use_container_width=True)
|
| 98 |
+
|
| 99 |
# Main function
|
| 100 |
def main():
|
| 101 |
st.sidebar.title("EV Grid Load Optimization")
|