rehanafzal commited on
Commit
1d2c4f6
·
verified ·
1 Parent(s): b24634c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +155 -13
app.py CHANGED
@@ -100,6 +100,107 @@
100
  # st.plotly_chart(trading_fig)
101
 
102
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
 
104
  import streamlit as st
105
  import pandas as pd
@@ -108,7 +209,7 @@ from app_backend import fetch_weather, generate_synthetic_data, generate_storage
108
 
109
  # Constants
110
  API_KEY = "84e26811a314599e940f343b4d5894a7"
111
- DEFAULT_LOCATION = "Pakistan"
112
 
113
  # Sidebar for location and weather data
114
  st.sidebar.title("Smart Grid Dashboard")
@@ -124,7 +225,7 @@ if weather:
124
  st.title("Real-Time Smart Grid Dashboard")
125
 
126
  # Tabs
127
- tabs = st.tabs(["Home", "Power Storage", "Electricity Trade Management"])
128
 
129
  # Home Tab
130
  with tabs[0]:
@@ -159,28 +260,71 @@ with tabs[0]:
159
  fig.update_layout(title="Power and Energy Trends", xaxis_title="Time", yaxis_title="Power (MW)")
160
  st.plotly_chart(fig)
161
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  # Storage Tab
163
  with tabs[1]:
164
  st.header("Energy Storage Overview")
165
  storage_data = generate_storage_data()
166
 
167
- st.write(f"**Total Energy Stored:** {storage_data['total_stored_kwh']} kWh")
168
-
169
- # Circular storage breakdown
170
- sources = ["Wind", "Solar", "Turbine"]
171
- values = [storage_data["wind"], storage_data["solar"], storage_data["turbine"]]
172
-
173
- fig = go.Figure(data=[go.Pie(labels=sources, values=values, hole=.4)])
174
- fig.update_layout(title="Energy Storage Breakdown")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  st.plotly_chart(fig)
176
 
 
 
177
  # Electricity Trade Management Tab
178
  with tabs[2]:
179
  st.header("Electricity Trade Management")
180
 
181
  # Sample trade data
182
  trade_data = {
183
- "Country": ["Srilanka", "China", "Bangladesh"],
184
  "Energy Exported (MW)": [50, 30, 70],
185
  "Energy Imported (MW)": [20, 40, 10],
186
  }
@@ -198,5 +342,3 @@ with tabs[2]:
198
 
199
 
200
 
201
-
202
-
 
100
  # st.plotly_chart(trading_fig)
101
 
102
 
103
+ # code 2
104
+
105
+
106
+ # import streamlit as st
107
+ # import pandas as pd
108
+ # import plotly.graph_objects as go
109
+ # from app_backend import fetch_weather, generate_synthetic_data, generate_storage_data
110
+
111
+ # # Constants
112
+ # API_KEY = "84e26811a314599e940f343b4d5894a7"
113
+ # DEFAULT_LOCATION = "Pakistan"
114
+
115
+ # # Sidebar for location and weather data
116
+ # st.sidebar.title("Smart Grid Dashboard")
117
+ # location = st.sidebar.text_input("Enter Location", DEFAULT_LOCATION)
118
+ # weather = fetch_weather(API_KEY, location)
119
+
120
+ # if weather:
121
+ # st.sidebar.write(f"Temperature: {weather['temperature']} °C")
122
+ # st.sidebar.write(f"Wind Speed: {weather['wind_speed']} m/s")
123
+ # st.sidebar.write(f"Weather: {weather['weather']}")
124
+
125
+ # # Main interface
126
+ # st.title("Real-Time Smart Grid Dashboard")
127
+
128
+ # # Tabs
129
+ # tabs = st.tabs(["Home", "Power Storage", "Electricity Trade Management"])
130
+
131
+ # # Home Tab
132
+ # with tabs[0]:
133
+ # st.header("Overview: Power and Energy Usage")
134
+
135
+ # # Fetch synthetic data
136
+ # data = generate_synthetic_data()
137
+
138
+ # # Line Graph for Power Consumption, Generation, and Storage
139
+ # fig = go.Figure()
140
+ # fig.add_trace(go.Scatter(
141
+ # x=data["timestamp"],
142
+ # y=data["total_power_consumption_mw"],
143
+ # mode='lines',
144
+ # name="Total Power Consumption (MW)",
145
+ # line=dict(color="red")
146
+ # ))
147
+ # fig.add_trace(go.Scatter(
148
+ # x=data["timestamp"],
149
+ # y=data["grid_generation_mw"],
150
+ # mode='lines',
151
+ # name="Grid Generation (MW)",
152
+ # line=dict(color="green")
153
+ # ))
154
+ # fig.add_trace(go.Scatter(
155
+ # x=data["timestamp"],
156
+ # y=data["storage_utilization_mw"],
157
+ # mode='lines',
158
+ # name="Storage Utilization (MW)",
159
+ # line=dict(color="blue")
160
+ # ))
161
+ # fig.update_layout(title="Power and Energy Trends", xaxis_title="Time", yaxis_title="Power (MW)")
162
+ # st.plotly_chart(fig)
163
+
164
+ # # Storage Tab
165
+ # with tabs[1]:
166
+ # st.header("Energy Storage Overview")
167
+ # storage_data = generate_storage_data()
168
+
169
+ # st.write(f"**Total Energy Stored:** {storage_data['total_stored_kwh']} kWh")
170
+
171
+ # # Circular storage breakdown
172
+ # sources = ["Wind", "Solar", "Turbine"]
173
+ # values = [storage_data["wind"], storage_data["solar"], storage_data["turbine"]]
174
+
175
+ # fig = go.Figure(data=[go.Pie(labels=sources, values=values, hole=.4)])
176
+ # fig.update_layout(title="Energy Storage Breakdown")
177
+ # st.plotly_chart(fig)
178
+
179
+ # # Electricity Trade Management Tab
180
+ # with tabs[2]:
181
+ # st.header("Electricity Trade Management")
182
+
183
+ # # Sample trade data
184
+ # trade_data = {
185
+ # "Country": ["Srilanka", "China", "Bangladesh"],
186
+ # "Energy Exported (MW)": [50, 30, 70],
187
+ # "Energy Imported (MW)": [20, 40, 10],
188
+ # }
189
+ # trade_df = pd.DataFrame(trade_data)
190
+
191
+ # st.subheader("Trade Details")
192
+ # st.write(trade_df)
193
+
194
+ # # Visualization
195
+ # fig = go.Figure()
196
+ # fig.add_trace(go.Bar(x=trade_df["Country"], y=trade_df["Energy Exported (MW)"], name="Exported", marker_color='purple'))
197
+ # fig.add_trace(go.Bar(x=trade_df["Country"], y=trade_df["Energy Imported (MW)"], name="Imported", marker_color='orange'))
198
+ # fig.update_layout(title="Energy Trade", barmode='group')
199
+ # st.plotly_chart(fig)
200
+
201
+
202
+ # code 3
203
+
204
 
205
  import streamlit as st
206
  import pandas as pd
 
209
 
210
  # Constants
211
  API_KEY = "84e26811a314599e940f343b4d5894a7"
212
+ DEFAULT_LOCATION = "pakistan"
213
 
214
  # Sidebar for location and weather data
215
  st.sidebar.title("Smart Grid Dashboard")
 
225
  st.title("Real-Time Smart Grid Dashboard")
226
 
227
  # Tabs
228
+ tabs = st.tabs(["Home", "Storage", "Electricity Trade Management"])
229
 
230
  # Home Tab
231
  with tabs[0]:
 
260
  fig.update_layout(title="Power and Energy Trends", xaxis_title="Time", yaxis_title="Power (MW)")
261
  st.plotly_chart(fig)
262
 
263
+ # Grid Health Indicator
264
+ st.subheader("Grid Health Status")
265
+ grid_health = "Stable" if data["grid_generation_mw"].mean() >= data["total_power_consumption_mw"].mean() else "Critical"
266
+ st.write(f"**Grid Health:** {grid_health}")
267
+
268
+ # AI Recommendations
269
+ st.subheader("AI Recommendations")
270
+ recommendations = [
271
+ "Increase solar panel efficiency by 10% for peak hours.",
272
+ "Optimize wind turbine alignment based on real-time wind data.",
273
+ "Store excess energy during low-demand periods for future use.",
274
+ "Improve grid stability by distributing load dynamically across sectors.",
275
+ ]
276
+ for rec in recommendations:
277
+ st.write(f"- {rec}")
278
+
279
  # Storage Tab
280
  with tabs[1]:
281
  st.header("Energy Storage Overview")
282
  storage_data = generate_storage_data()
283
 
284
+ # Individual Circles for Wind, Solar, and Turbine
285
+ st.subheader("Energy Contributions")
286
+ col1, col2, col3 = st.columns(3)
287
+ with col1:
288
+ st.metric("Wind Energy", f"{storage_data['wind']} MW/min")
289
+ with col2:
290
+ st.metric("Solar Energy", f"{storage_data['solar']} MW/min")
291
+ with col3:
292
+ st.metric("Turbine Energy", f"{storage_data['turbine']} MW/min")
293
+
294
+ # Central Grid Storage Visualization
295
+ st.subheader("Total Energy Stored in Grid")
296
+ fig = go.Figure()
297
+ fig.add_trace(go.Scatter(x=[0], y=[0], mode='markers+text', text=["Grid"], marker=dict(size=70, color="blue")))
298
+ fig.add_trace(go.Scatter(
299
+ x=[-1, 1, 0],
300
+ y=[1, 1, -1],
301
+ mode='markers+text',
302
+ text=["Wind", "Solar", "Turbine"],
303
+ marker=dict(size=50, color=["green", "yellow", "orange"])
304
+ ))
305
+ fig.add_trace(go.Scatter(
306
+ x=[-0.5, 0.5, 0],
307
+ y=[0.5, 0.5, -0.5],
308
+ mode="lines",
309
+ line=dict(width=3, color="gray"),
310
+ ))
311
+ fig.update_layout(
312
+ title="Energy Storage Visualization",
313
+ xaxis=dict(visible=False),
314
+ yaxis=dict(visible=False),
315
+ showlegend=False
316
+ )
317
  st.plotly_chart(fig)
318
 
319
+ st.write(f"**Total Energy Stored:** {storage_data['total_stored_kwh']} kWh")
320
+
321
  # Electricity Trade Management Tab
322
  with tabs[2]:
323
  st.header("Electricity Trade Management")
324
 
325
  # Sample trade data
326
  trade_data = {
327
+ "Country": ["Country A", "Country B", "Country C"],
328
  "Energy Exported (MW)": [50, 30, 70],
329
  "Energy Imported (MW)": [20, 40, 10],
330
  }
 
342
 
343
 
344