mudassarrafique commited on
Commit
6b279ed
·
verified ·
1 Parent(s): 42f469a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -28
app.py CHANGED
@@ -6,6 +6,7 @@ import datetime
6
 
7
  # Load dataset function
8
  def load_data():
 
9
  df = pd.read_excel("grid_load_data.xlsx")
10
  return df
11
 
@@ -15,12 +16,14 @@ def calculate_grid_load(df, current_time):
15
  hourly_load = df[df["Time"].dt.hour == current_hour]["Grid Load (kW)"].mean()
16
  return hourly_load
17
 
18
- # Create a smaller gauge chart for grid load status
19
  def create_gauge(load_value):
 
20
  ranges = [0, 2000, 3000, 4000]
21
  colors = ['lightgreen', 'green', 'red']
22
  labels = ['Low', 'Normal', 'High']
23
 
 
24
  if load_value < 2000:
25
  color = colors[0]
26
  range_label = labels[0]
@@ -31,10 +34,11 @@ def create_gauge(load_value):
31
  color = colors[2]
32
  range_label = labels[2]
33
 
 
34
  fig = go.Figure(go.Indicator(
35
  mode="gauge+number+delta",
36
  value=load_value,
37
- domain={'x': [0, 1], 'y': [0, 0.6]}, # Smaller gauge
38
  gauge={
39
  'axis': {'range': [0, 5000]},
40
  'bar': {'color': color},
@@ -51,51 +55,72 @@ def create_gauge(load_value):
51
 
52
  # Function to calculate the required EVs for grid stabilization
53
  def calculate_ev_requirements(grid_load, ev_capacity=80, ev_efficiency=0.85):
 
 
54
  evs_needed = grid_load / (ev_capacity * ev_efficiency)
55
- return np.ceil(evs_needed)
 
 
 
 
 
 
56
 
57
  # Display the grid load prediction and related EV info
58
  def display_grid_load_prediction_and_ev_info():
59
  st.header("Grid Load Prediction and EV Charging Info")
60
 
61
- # LED Indicators above the slider
62
- col1, col2 = st.columns(2)
63
- with col1:
64
- st.markdown('<p style="color: red; font-size: 24px;">&#128993; Overload Warning!</p>', unsafe_allow_html=True)
65
- with col2:
66
- st.markdown('<p style="color: green; font-size: 24px;">&#128994; Grid Stable</p>', unsafe_allow_html=True)
67
-
68
- # Grid Load Slider
69
- grid_load = st.slider("Select Grid Load (kW):", 0, 5000, 2000, 100)
70
 
71
- # Display the gauge chart
72
  st.plotly_chart(create_gauge(grid_load), use_container_width=True)
73
 
 
74
  if grid_load > 3500:
75
- st.markdown('<p style="color: red;">Grid overload! Connect EVs to stabilize.</p>', unsafe_allow_html=True)
76
  else:
77
- st.markdown('<p style="color: green;">Grid is stable.</p>', unsafe_allow_html=True)
78
 
79
- # EV Charging Status and Stabilization
80
- if grid_load > 3500:
81
- energy_required = grid_load - 3500
82
- evs_needed = calculate_ev_requirements(energy_required)
83
- st.write(f"To stabilize the grid, {energy_required} kWh of energy is required.")
84
- st.write(f"Approximately {evs_needed} EVs are needed to stabilize the grid.")
85
 
86
- if st.button("Connect EVs to Stabilize Grid"):
87
- grid_load -= energy_required # Adjusting grid load
88
- st.write(f"Grid load reduced to {grid_load} kW. EVs are stabilizing the grid.")
89
- st.experimental_rerun() # Refresh to update the graph
90
-
 
 
 
 
 
 
 
 
 
 
91
  if grid_load > 3000:
92
- st.button("Disconnect EV from Grid", key="disconnect_charge")
93
  else:
94
- st.button("Allow EV to Charge", key="allow_charge")
95
 
96
  # Display Main Application
97
  def main():
98
  st.sidebar.title("EV Charging Optimization")
 
 
99
  display_grid_load_prediction_and_ev_info()
100
 
101
  if __name__ == "__main__":
 
6
 
7
  # Load dataset function
8
  def load_data():
9
+ # Ensure this path is correct for your environment
10
  df = pd.read_excel("grid_load_data.xlsx")
11
  return df
12
 
 
16
  hourly_load = df[df["Time"].dt.hour == current_hour]["Grid Load (kW)"].mean()
17
  return hourly_load
18
 
19
+ # Create a gauge chart for grid load status
20
  def create_gauge(load_value):
21
+ # Define ranges for low, normal, high
22
  ranges = [0, 2000, 3000, 4000]
23
  colors = ['lightgreen', 'green', 'red']
24
  labels = ['Low', 'Normal', 'High']
25
 
26
+ # Determine color and range based on load value
27
  if load_value < 2000:
28
  color = colors[0]
29
  range_label = labels[0]
 
34
  color = colors[2]
35
  range_label = labels[2]
36
 
37
+ # Create the gauge chart using plotly
38
  fig = go.Figure(go.Indicator(
39
  mode="gauge+number+delta",
40
  value=load_value,
41
+ domain={'x': [0, 1], 'y': [0, 1]},
42
  gauge={
43
  'axis': {'range': [0, 5000]},
44
  'bar': {'color': color},
 
55
 
56
  # Function to calculate the required EVs for grid stabilization
57
  def calculate_ev_requirements(grid_load, ev_capacity=80, ev_efficiency=0.85):
58
+ # Assuming each EV contributes its battery capacity (80kWh) and efficiency (85%).
59
+ # Formula: EVs required = Grid load / (EV capacity * efficiency)
60
  evs_needed = grid_load / (ev_capacity * ev_efficiency)
61
+ return np.ceil(evs_needed) # Round to the nearest whole number
62
+
63
+ # Function to calculate power and energy consumption from EV during underload condition
64
+ def calculate_ev_power_consumption(ev_capacity=80, charge_rate=0.85):
65
+ # Power consumed per EV during underload (assuming 85% depth of charge)
66
+ power_consumed = ev_capacity * charge_rate
67
+ return power_consumed
68
 
69
  # Display the grid load prediction and related EV info
70
  def display_grid_load_prediction_and_ev_info():
71
  st.header("Grid Load Prediction and EV Charging Info")
72
 
73
+ # Allow user to manually set grid load using slider (0 to 5000 kW)
74
+ grid_load = st.slider(
75
+ "Select Grid Load (kW):",
76
+ min_value=0,
77
+ max_value=5000,
78
+ value=2000, # Default value
79
+ step=100,
80
+ help="Drag the slider to set the desired grid load."
81
+ )
82
 
83
+ # Display the gauge chart based on selected load value
84
  st.plotly_chart(create_gauge(grid_load), use_container_width=True)
85
 
86
+ # LED Indicators for overload/normal status
87
  if grid_load > 3500:
88
+ st.markdown('<p style="color: red; font-size: 24px;">&#128313; Left LED: Overload! Grid is in danger.</p>', unsafe_allow_html=True)
89
  else:
90
+ st.markdown('<p style="color: green; font-size: 24px;">&#128313; Right LED: Normal. Grid is stable.</p>', unsafe_allow_html=True)
91
 
92
+ # EV Charging Status
93
+ if grid_load < 3000:
94
+ st.markdown('<p style="color: green;">Green: Charging allowed. EVs can charge.</p>', unsafe_allow_html=True)
95
+ # Calculate and display the number of EVs that can be connected based on grid load
96
+ evs_connected = calculate_ev_requirements(grid_load)
97
+ st.write(f"Approximately {evs_connected} EVs can be connected to the grid for charging.")
98
 
99
+ else:
100
+ st.markdown('<p style="color: red;">Red: Grid overload! Disconnecting EV from grid.</p>', unsafe_allow_html=True)
101
+ # If the load exceeds 3500 kW, calculate how much energy is needed to stabilize the grid
102
+ if grid_load > 3500:
103
+ energy_required = grid_load - 3500
104
+ evs_needed = calculate_ev_requirements(energy_required)
105
+ st.write(f"To stabilize the grid, {energy_required} kWh of energy is required.")
106
+ st.write(f"Approximately {evs_needed} EVs are needed to supply this energy to the grid.")
107
+
108
+ # Add a button to connect EVs to stabilize the grid
109
+ if st.button("Connect EVs to Stabilize Grid"):
110
+ grid_load -= energy_required # Decrease grid load by the energy provided by EVs
111
+ st.write(f"Grid load reduced to {grid_load} kW. EVs are stabilizing the grid.")
112
+
113
+ # Allow the user to disconnect EVs if the grid load is too high
114
  if grid_load > 3000:
115
+ st.button("Disconnect EV from Grid", key="disconnect_charge", help="Grid load is too high. Disconnect EV.")
116
  else:
117
+ st.button("Allow EV to Charge", key="allow_charge", help="Grid load is normal. EVs can charge.")
118
 
119
  # Display Main Application
120
  def main():
121
  st.sidebar.title("EV Charging Optimization")
122
+
123
+ # Display the Grid Load Prediction and EV Info all on the same page
124
  display_grid_load_prediction_and_ev_info()
125
 
126
  if __name__ == "__main__":