Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,9 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import datetime
|
|
|
|
| 4 |
from difflib import get_close_matches
|
|
|
|
| 5 |
|
| 6 |
# Function to standardize and find the closest column name
|
| 7 |
def get_closest_column(columns, target, threshold=0.6):
|
|
@@ -61,12 +63,36 @@ def calculate_predicted_grid_load(df, current_time, grid_load_col):
|
|
| 61 |
st.warning("No data found for the current hour. Using default value.")
|
| 62 |
return 0 # Default to 0 if no data is found for the given hour
|
| 63 |
|
| 64 |
-
# Display
|
| 65 |
def display_clock():
|
| 66 |
current_time = datetime.datetime.now()
|
| 67 |
st.sidebar.markdown(f"### π {current_time.strftime('%Y-%m-%d %H:%M:%S')}")
|
| 68 |
return current_time
|
| 69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
# Main app
|
| 71 |
def main():
|
| 72 |
st.title("Optimized EV Charging and Grid Management")
|
|
@@ -95,13 +121,19 @@ def main():
|
|
| 95 |
if predicted_grid_load is not None:
|
| 96 |
st.write(f"### Predicted Grid Load at {current_time.strftime('%H:%M:%S')}: **{predicted_grid_load:.2f} kW**")
|
| 97 |
|
|
|
|
|
|
|
|
|
|
| 98 |
# Evaluate grid status based on the predicted load
|
| 99 |
if predicted_grid_load > 3400:
|
| 100 |
st.error("Grid is Overloaded! EV Charging Disallowed")
|
| 101 |
st.write("π« Red Light: EV Charging is Disconnected.")
|
| 102 |
-
|
| 103 |
st.success("Grid is Stable! EV Charging Allowed")
|
| 104 |
st.write("β
Green Light: EV Charging is Active.")
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
# Calculate available EV slots
|
| 107 |
available_capacity = 3400 - predicted_grid_load
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import datetime
|
| 4 |
+
import plotly.graph_objects as go
|
| 5 |
from difflib import get_close_matches
|
| 6 |
+
import time
|
| 7 |
|
| 8 |
# Function to standardize and find the closest column name
|
| 9 |
def get_closest_column(columns, target, threshold=0.6):
|
|
|
|
| 63 |
st.warning("No data found for the current hour. Using default value.")
|
| 64 |
return 0 # Default to 0 if no data is found for the given hour
|
| 65 |
|
| 66 |
+
# Display live clock
|
| 67 |
def display_clock():
|
| 68 |
current_time = datetime.datetime.now()
|
| 69 |
st.sidebar.markdown(f"### π {current_time.strftime('%Y-%m-%d %H:%M:%S')}")
|
| 70 |
return current_time
|
| 71 |
|
| 72 |
+
# Create Gauge meter
|
| 73 |
+
def create_gauge(value):
|
| 74 |
+
fig = go.Figure(go.Indicator(
|
| 75 |
+
mode="gauge+number",
|
| 76 |
+
value=value,
|
| 77 |
+
title={'text': "Grid Load (kW)"},
|
| 78 |
+
gauge={
|
| 79 |
+
'axis': {'range': [0, 5000]},
|
| 80 |
+
'bar': {'color': "lightgray"},
|
| 81 |
+
'steps': [
|
| 82 |
+
{'range': [0, 1700], 'color': "lightcoral"},
|
| 83 |
+
{'range': [1700, 3400], 'color': "lightgreen"},
|
| 84 |
+
{'range': [3400, 5000], 'color': "red"}
|
| 85 |
+
],
|
| 86 |
+
'threshold': {
|
| 87 |
+
'line': {'color': "black", 'width': 4},
|
| 88 |
+
'thickness': 0.75,
|
| 89 |
+
'value': value
|
| 90 |
+
}
|
| 91 |
+
}
|
| 92 |
+
))
|
| 93 |
+
fig.update_layout(margin={'l': 0, 'r': 0, 't': 0, 'b': 0}, height=400)
|
| 94 |
+
return fig
|
| 95 |
+
|
| 96 |
# Main app
|
| 97 |
def main():
|
| 98 |
st.title("Optimized EV Charging and Grid Management")
|
|
|
|
| 121 |
if predicted_grid_load is not None:
|
| 122 |
st.write(f"### Predicted Grid Load at {current_time.strftime('%H:%M:%S')}: **{predicted_grid_load:.2f} kW**")
|
| 123 |
|
| 124 |
+
# Create gauge meter based on grid load
|
| 125 |
+
st.plotly_chart(create_gauge(predicted_grid_load))
|
| 126 |
+
|
| 127 |
# Evaluate grid status based on the predicted load
|
| 128 |
if predicted_grid_load > 3400:
|
| 129 |
st.error("Grid is Overloaded! EV Charging Disallowed")
|
| 130 |
st.write("π« Red Light: EV Charging is Disconnected.")
|
| 131 |
+
elif predicted_grid_load <= 3400 and predicted_grid_load > 1700:
|
| 132 |
st.success("Grid is Stable! EV Charging Allowed")
|
| 133 |
st.write("β
Green Light: EV Charging is Active.")
|
| 134 |
+
else:
|
| 135 |
+
st.warning("Grid is Low! EV Charging Allowed")
|
| 136 |
+
st.write("π Light Red Light: EV Charging is Active, but Grid is Low.")
|
| 137 |
|
| 138 |
# Calculate available EV slots
|
| 139 |
available_capacity = 3400 - predicted_grid_load
|