Spaces:
Runtime error
Runtime error
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,654 +0,0 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import pandas as pd
|
| 3 |
-
import plotly.express as px
|
| 4 |
-
from app_backend import fetch_weather, generate_synthetic_data, optimize_load
|
| 5 |
-
|
| 6 |
-
# Constants
|
| 7 |
-
API_KEY = "84e26811a314599e940f343b4d5894a7"
|
| 8 |
-
LOCATION = "Pakistan"
|
| 9 |
-
|
| 10 |
-
# Sidebar
|
| 11 |
-
st.sidebar.title("Smart Grid Dashboard")
|
| 12 |
-
location = st.sidebar.text_input("Enter Location", LOCATION)
|
| 13 |
-
|
| 14 |
-
# Fetch and display weather data
|
| 15 |
-
weather = fetch_weather(API_KEY, location)
|
| 16 |
-
if weather:
|
| 17 |
-
st.sidebar.write(f"Temperature: {weather['temperature']} °C")
|
| 18 |
-
st.sidebar.write(f"Wind Speed: {weather['wind_speed']} m/s")
|
| 19 |
-
st.sidebar.write(f"Weather: {weather['weather']}")
|
| 20 |
-
|
| 21 |
-
# Main dashboard with tabs
|
| 22 |
-
tabs = st.tabs(["Home", "Electricity Storage", "Electricity Trading"])
|
| 23 |
-
|
| 24 |
-
with tabs[0]:
|
| 25 |
-
st.title("Real-Time Smart Grid Dashboard")
|
| 26 |
-
|
| 27 |
-
# Generate synthetic data
|
| 28 |
-
data = generate_synthetic_data()
|
| 29 |
-
|
| 30 |
-
# Plot total consumption, grid generation, and storage usage
|
| 31 |
-
fig = px.line(data, x="timestamp", y=["total_consumption_kwh", "grid_generation_kwh", "storage_usage_kwh"],
|
| 32 |
-
title="Energy Consumption, Generation, and Storage Usage Over Time",
|
| 33 |
-
labels={"value": "Energy (kWh)", "variable": "Energy Source"})
|
| 34 |
-
st.plotly_chart(fig)
|
| 35 |
-
|
| 36 |
-
# Grid health overview
|
| 37 |
-
st.subheader("Grid Health Overview")
|
| 38 |
-
grid_health_counts = data["grid_health"].value_counts()
|
| 39 |
-
st.bar_chart(grid_health_counts)
|
| 40 |
-
|
| 41 |
-
# Optimization recommendations
|
| 42 |
-
current_demand = data["total_consumption_kwh"].iloc[-1]
|
| 43 |
-
current_solar = data["solar_output_kw"].iloc[-1]
|
| 44 |
-
current_wind = data["wind_output_kw"].iloc[-1]
|
| 45 |
-
recommendation = optimize_load(current_demand, current_solar, current_wind)
|
| 46 |
-
|
| 47 |
-
st.subheader("Recommendations")
|
| 48 |
-
st.write(f"Current Load Demand: {current_demand} kWh")
|
| 49 |
-
st.write(f"Solar Output: {current_solar} kW")
|
| 50 |
-
st.write(f"Wind Output: {current_wind} kW")
|
| 51 |
-
st.write(f"Recommendation: {recommendation}")
|
| 52 |
-
|
| 53 |
-
with tabs[1]:
|
| 54 |
-
st.title("Energy Storage Overview")
|
| 55 |
-
|
| 56 |
-
# Total energy stored
|
| 57 |
-
total_storage = 500 # Example of total energy storage
|
| 58 |
-
st.subheader(f"Total Energy Stored: {total_storage} kWh")
|
| 59 |
-
|
| 60 |
-
# Energy storage contribution from different sources
|
| 61 |
-
st.subheader("Energy Storage Contributions")
|
| 62 |
-
energy_sources = pd.DataFrame({
|
| 63 |
-
"Source": ["Wind", "Solar", "Turbine"],
|
| 64 |
-
"Energy (kW/min)": [5, 7, 10]
|
| 65 |
-
})
|
| 66 |
-
st.bar_chart(energy_sources.set_index("Source"))
|
| 67 |
-
|
| 68 |
-
# Show energy storage status with a rounded circle
|
| 69 |
-
st.subheader("Energy Storage Circle")
|
| 70 |
-
st.markdown("Energy storage is a combination of contributions from different renewable sources.")
|
| 71 |
-
|
| 72 |
-
# Visualization of energy storage circle using Plotly
|
| 73 |
-
storage_data = {
|
| 74 |
-
"Source": ["Wind", "Solar", "Turbine"],
|
| 75 |
-
"Energy": [5, 7, 10],
|
| 76 |
-
}
|
| 77 |
-
storage_df = pd.DataFrame(storage_data)
|
| 78 |
-
fig = px.pie(storage_df, names="Source", values="Energy", title="Energy Storage Sources")
|
| 79 |
-
st.plotly_chart(fig)
|
| 80 |
-
|
| 81 |
-
with tabs[2]:
|
| 82 |
-
st.title("Energy Trading Overview")
|
| 83 |
-
|
| 84 |
-
# Energy cubes
|
| 85 |
-
st.subheader("Energy Cubes Stored")
|
| 86 |
-
energy_cubes = pd.DataFrame({
|
| 87 |
-
"Country": ["China", "Sri Lanka", "Bangladesh"],
|
| 88 |
-
"Energy (kWh)": [100, 200, 300],
|
| 89 |
-
"Shareable": [True, True, False]
|
| 90 |
-
})
|
| 91 |
-
|
| 92 |
-
# Displaying the energy cubes in a grid
|
| 93 |
-
st.write("Stored energy can be shared with other countries.")
|
| 94 |
-
st.dataframe(energy_cubes)
|
| 95 |
-
|
| 96 |
-
# Visualization of energy that can be shared
|
| 97 |
-
st.subheader("Energy Trading Visualization")
|
| 98 |
-
st.markdown("The following energy amounts are available for sharing with different countries.")
|
| 99 |
-
trading_fig = px.bar(energy_cubes, x="Country", y="Energy (kWh)", color="Shareable", title="Energy Trading")
|
| 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
|
| 207 |
-
# import plotly.graph_objects as go
|
| 208 |
-
# from app_backend import fetch_weather, generate_synthetic_data, generate_storage_data
|
| 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")
|
| 216 |
-
# location = st.sidebar.text_input("Enter Location", DEFAULT_LOCATION)
|
| 217 |
-
# weather = fetch_weather(API_KEY, location)
|
| 218 |
-
|
| 219 |
-
# if weather:
|
| 220 |
-
# st.sidebar.write(f"Temperature: {weather['temperature']} °C")
|
| 221 |
-
# st.sidebar.write(f"Wind Speed: {weather['wind_speed']} m/s")
|
| 222 |
-
# st.sidebar.write(f"Weather: {weather['weather']}")
|
| 223 |
-
|
| 224 |
-
# # Main interface
|
| 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]:
|
| 232 |
-
# st.header("Overview: Power and Energy Usage")
|
| 233 |
-
|
| 234 |
-
# # Fetch synthetic data
|
| 235 |
-
# data = generate_synthetic_data()
|
| 236 |
-
|
| 237 |
-
# # Line Graph for Power Consumption, Generation, and Storage
|
| 238 |
-
# fig = go.Figure()
|
| 239 |
-
# fig.add_trace(go.Scatter(
|
| 240 |
-
# x=data["timestamp"],
|
| 241 |
-
# y=data["total_power_consumption_mw"],
|
| 242 |
-
# mode='lines',
|
| 243 |
-
# name="Total Power Consumption (MW)",
|
| 244 |
-
# line=dict(color="red")
|
| 245 |
-
# ))
|
| 246 |
-
# fig.add_trace(go.Scatter(
|
| 247 |
-
# x=data["timestamp"],
|
| 248 |
-
# y=data["grid_generation_mw"],
|
| 249 |
-
# mode='lines',
|
| 250 |
-
# name="Grid Generation (MW)",
|
| 251 |
-
# line=dict(color="green")
|
| 252 |
-
# ))
|
| 253 |
-
# fig.add_trace(go.Scatter(
|
| 254 |
-
# x=data["timestamp"],
|
| 255 |
-
# y=data["storage_utilization_mw"],
|
| 256 |
-
# mode='lines',
|
| 257 |
-
# name="Storage Utilization (MW)",
|
| 258 |
-
# line=dict(color="blue")
|
| 259 |
-
# ))
|
| 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 |
-
# # # Grid health overview
|
| 265 |
-
# # st.subheader("Grid Health Overview")
|
| 266 |
-
# # grid_health_counts = data["grid_health"].value_counts()
|
| 267 |
-
# # st.bar_chart(grid_health_counts)
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
# st.subheader("Grid Health Status")
|
| 272 |
-
# grid_health = "Stable" if data["grid_generation_mw"].mean() >= data["total_power_consumption_mw"].mean() else "Critical"
|
| 273 |
-
# st.write(f"**Grid Health:** {grid_health}")
|
| 274 |
-
|
| 275 |
-
# # AI Recommendations
|
| 276 |
-
# st.subheader("AI Recommendations")
|
| 277 |
-
# recommendations = [
|
| 278 |
-
# "Increase solar panel efficiency by 10% for peak hours.",
|
| 279 |
-
# "Optimize wind turbine alignment based on real-time wind data.",
|
| 280 |
-
# "Store excess energy during low-demand periods for future use.",
|
| 281 |
-
# "Improve grid stability by distributing load dynamically across sectors.",
|
| 282 |
-
# ]
|
| 283 |
-
# for rec in recommendations:
|
| 284 |
-
# st.write(f"- {rec}")
|
| 285 |
-
|
| 286 |
-
# # Storage Tab
|
| 287 |
-
# with tabs[1]:
|
| 288 |
-
# st.header("Energy Storage Overview")
|
| 289 |
-
# storage_data = generate_storage_data()
|
| 290 |
-
|
| 291 |
-
# # Individual Circles for Wind, Solar, and Turbine
|
| 292 |
-
# st.subheader("Energy Contributions")
|
| 293 |
-
# col1, col2, col3 = st.columns(3)
|
| 294 |
-
# with col1:
|
| 295 |
-
# st.metric("Wind Energy", f"{storage_data['wind']} MW/min")
|
| 296 |
-
# with col2:
|
| 297 |
-
# st.metric("Solar Energy", f"{storage_data['solar']} MW/min")
|
| 298 |
-
# with col3:
|
| 299 |
-
# st.metric("Turbine Energy", f"{storage_data['turbine']} MW/min")
|
| 300 |
-
|
| 301 |
-
# # Central Grid Storage Visualization
|
| 302 |
-
# st.subheader("Total Energy Stored in Grid")
|
| 303 |
-
# fig = go.Figure()
|
| 304 |
-
# fig.add_trace(go.Scatter(x=[0], y=[0], mode='markers+text', text=["Grid"], marker=dict(size=70, color="blue")))
|
| 305 |
-
# fig.add_trace(go.Scatter(
|
| 306 |
-
# x=[-1, 1, 0],
|
| 307 |
-
# y=[1, 1, -1],
|
| 308 |
-
# mode='markers+text',
|
| 309 |
-
# text=["Wind", "Solar", "Turbine"],
|
| 310 |
-
# marker=dict(size=50, color=["green", "yellow", "orange"])
|
| 311 |
-
# ))
|
| 312 |
-
# fig.add_trace(go.Scatter(
|
| 313 |
-
# x=[-0.5, 0.5, 0],
|
| 314 |
-
# y=[0.5, 0.5, -0.5],
|
| 315 |
-
# mode="lines",
|
| 316 |
-
# line=dict(width=3, color="gray"),
|
| 317 |
-
# ))
|
| 318 |
-
# fig.update_layout(
|
| 319 |
-
# title="Energy Storage Visualization",
|
| 320 |
-
# xaxis=dict(visible=False),
|
| 321 |
-
# yaxis=dict(visible=False),
|
| 322 |
-
# showlegend=False
|
| 323 |
-
# )
|
| 324 |
-
# st.plotly_chart(fig)
|
| 325 |
-
|
| 326 |
-
# st.write(f"**Total Energy Stored:** {storage_data['total_stored_kwh']} kWh")
|
| 327 |
-
|
| 328 |
-
# # Electricity Trade Management Tab
|
| 329 |
-
# with tabs[2]:
|
| 330 |
-
# st.header("Electricity Trade Management")
|
| 331 |
-
|
| 332 |
-
# # Sample trade data
|
| 333 |
-
# trade_data = {
|
| 334 |
-
# "Country": ["Country A", "Country B", "Country C"],
|
| 335 |
-
# "Energy Exported (MW)": [50, 30, 70],
|
| 336 |
-
# "Energy Imported (MW)": [20, 40, 10],
|
| 337 |
-
# }
|
| 338 |
-
# trade_df = pd.DataFrame(trade_data)
|
| 339 |
-
|
| 340 |
-
# st.subheader("Trade Details")
|
| 341 |
-
# st.write(trade_df)
|
| 342 |
-
|
| 343 |
-
# # Visualization
|
| 344 |
-
# fig = go.Figure()
|
| 345 |
-
# fig.add_trace(go.Bar(x=trade_df["Country"], y=trade_df["Energy Exported (MW)"], name="Exported", marker_color='purple'))
|
| 346 |
-
# fig.add_trace(go.Bar(x=trade_df["Country"], y=trade_df["Energy Imported (MW)"], name="Imported", marker_color='orange'))
|
| 347 |
-
# fig.update_layout(title="Energy Trade", barmode='group')
|
| 348 |
-
# st.plotly_chart(fig)
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
# code 4
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
# import streamlit as st
|
| 356 |
-
# import plotly.express as px
|
| 357 |
-
# from app_backend import fetch_weather, generate_synthetic_data, optimize_load
|
| 358 |
-
# import pandas as pd
|
| 359 |
-
|
| 360 |
-
# # Constants
|
| 361 |
-
# API_KEY = "84e26811a314599e940f343b4d5894a7" # Replace with your OpenWeather API key
|
| 362 |
-
# LOCATION = "Pakistan"
|
| 363 |
-
|
| 364 |
-
# # Sidebar
|
| 365 |
-
# st.sidebar.title("Smart Grid Dashboard")
|
| 366 |
-
# location = st.sidebar.text_input("Enter Location", LOCATION)
|
| 367 |
-
|
| 368 |
-
# # Fetch and display weather data
|
| 369 |
-
# weather = fetch_weather(API_KEY, location)
|
| 370 |
-
# st.sidebar.subheader("Weather Information")
|
| 371 |
-
# if weather:
|
| 372 |
-
# st.sidebar.write(f"**Temperature**: {weather['temperature']} °C")
|
| 373 |
-
# st.sidebar.write(f"**Wind Speed**: {weather['wind_speed']} m/s")
|
| 374 |
-
# st.sidebar.write(f"**Weather**: {weather['weather']}")
|
| 375 |
-
|
| 376 |
-
# # Main tabs
|
| 377 |
-
# tab1, tab2, tab3 = st.tabs(["Home", "Power Storage", "Power Trading management"])
|
| 378 |
-
|
| 379 |
-
# # Home Tab
|
| 380 |
-
# with tab1:
|
| 381 |
-
# st.title("Real-Time Smart Grid Dashboard")
|
| 382 |
-
|
| 383 |
-
# # Generate synthetic data
|
| 384 |
-
# data = generate_synthetic_data()
|
| 385 |
-
|
| 386 |
-
# # Show weather at top
|
| 387 |
-
# if weather:
|
| 388 |
-
# st.write(f"### Location: {location}")
|
| 389 |
-
# st.write(f"Temperature: {weather['temperature']} °C | Wind Speed: {weather['wind_speed']} m/s | Weather: {weather['weather']}")
|
| 390 |
-
|
| 391 |
-
# # Power consumption graph
|
| 392 |
-
# fig = px.line(
|
| 393 |
-
# data,
|
| 394 |
-
# x="timestamp",
|
| 395 |
-
# y=["power_consumption_mw", "generation_mw", "storage_usage_mw"],
|
| 396 |
-
# labels={"value": "Power (MW)", "variable": "Metric"},
|
| 397 |
-
# title="Power Flow Over Time"
|
| 398 |
-
# )
|
| 399 |
-
# fig.update_traces(mode="lines+markers")
|
| 400 |
-
# st.plotly_chart(fig)
|
| 401 |
-
|
| 402 |
-
# # Grid health as bar chart
|
| 403 |
-
# st.subheader("Grid Health Overview")
|
| 404 |
-
# grid_health_counts = data["grid_health"].value_counts()
|
| 405 |
-
# fig_health = px.bar(
|
| 406 |
-
# grid_health_counts,
|
| 407 |
-
# x=grid_health_counts.index,
|
| 408 |
-
# y=grid_health_counts.values,
|
| 409 |
-
# labels={"x": "Grid Status", "y": "Count"},
|
| 410 |
-
# title="Grid Health Status"
|
| 411 |
-
# )
|
| 412 |
-
# st.plotly_chart(fig_health)
|
| 413 |
-
|
| 414 |
-
# # AI recommendations
|
| 415 |
-
# st.subheader("AI Recommendations")
|
| 416 |
-
# current_demand = data["power_consumption_mw"].iloc[-1]
|
| 417 |
-
# current_solar = data["solar_output_mw"].iloc[-1]
|
| 418 |
-
# current_wind = data["wind_output_mw"].iloc[-1]
|
| 419 |
-
# recommendation = optimize_load(current_demand, current_solar, current_wind)
|
| 420 |
-
# st.write(f"**Current Load Demand**: {current_demand} MW")
|
| 421 |
-
# st.write(f"**Solar Output**: {current_solar} MW")
|
| 422 |
-
# st.write(f"**Wind Output**: {current_wind} MW")
|
| 423 |
-
# st.write(f"**Recommendation**: {recommendation}")
|
| 424 |
-
|
| 425 |
-
# # Storage Tab
|
| 426 |
-
# with tab2:
|
| 427 |
-
# st.title("Energy Storage Status")
|
| 428 |
-
|
| 429 |
-
# # Pie chart of energy percentage contribution
|
| 430 |
-
# storage_data = {
|
| 431 |
-
# "Wind": data["wind_output_mw"].mean(),
|
| 432 |
-
# "Solar": data["solar_output_mw"].mean(),
|
| 433 |
-
# "Turbine": data["turbine_output_mw"].mean()
|
| 434 |
-
# }
|
| 435 |
-
# fig_pie = px.pie(
|
| 436 |
-
# names=storage_data.keys(),
|
| 437 |
-
# values=storage_data.values(),
|
| 438 |
-
# title="Energy Contribution by Resource"
|
| 439 |
-
# )
|
| 440 |
-
# st.plotly_chart(fig_pie)
|
| 441 |
-
|
| 442 |
-
# # Circle visualization for storage
|
| 443 |
-
# st.subheader("Total Energy Stored")
|
| 444 |
-
# total_storage = sum(storage_data.values())
|
| 445 |
-
# st.write(f"**Total Energy Stored**: {total_storage:.2f} MW")
|
| 446 |
-
|
| 447 |
-
# st.markdown(
|
| 448 |
-
# """
|
| 449 |
-
# <div style="display: flex; justify-content: center; align-items: center; flex-direction: column;">
|
| 450 |
-
# <div style="width: 150px; height: 150px; border-radius: 50%; background-color: #FFDD00; display: flex; justify-content: center; align-items: center; font-size: 24px; font-weight: bold; margin-bottom: 20px;">
|
| 451 |
-
# {total_storage:.2f} MW
|
| 452 |
-
# </div>
|
| 453 |
-
# <div style="display: flex; gap: 50px;">
|
| 454 |
-
# <div style="width: 100px; height: 100px; border-radius: 50%; background-color: #0073FF; display: flex; justify-content: center; align-items: center; font-size: 16px; font-weight: bold;">
|
| 455 |
-
# Wind<br>{storage_data["Wind"]:.2f} MW
|
| 456 |
-
# </div>
|
| 457 |
-
# <div style="width: 100px; height: 100px; border-radius: 50%; background-color: #FF5733; display: flex; justify-content: center; align-items: center; font-size: 16px; font-weight: bold;">
|
| 458 |
-
# Solar<br>{storage_data["Solar"]:.2f} MW
|
| 459 |
-
# </div>
|
| 460 |
-
# <div style="width: 100px; height: 100px; border-radius: 50%; background-color: #28B463; display: flex; justify-content: center; align-items: center; font-size: 16px; font-weight: bold;">
|
| 461 |
-
# Turbine<br>{storage_data["Turbine"]:.2f} MW
|
| 462 |
-
# </div>
|
| 463 |
-
# </div>
|
| 464 |
-
# </div>
|
| 465 |
-
# """,
|
| 466 |
-
# unsafe_allow_html=True
|
| 467 |
-
# )
|
| 468 |
-
|
| 469 |
-
# # Trading Tab
|
| 470 |
-
# with tab3:
|
| 471 |
-
# st.title("Electricity Trade Management")
|
| 472 |
-
# st.write("Under development...")
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
# code 5
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
# import streamlit as st
|
| 480 |
-
# import pandas as pd
|
| 481 |
-
# import plotly.express as px
|
| 482 |
-
# from app_backend import fetch_weather, generate_synthetic_data, optimize_load
|
| 483 |
-
|
| 484 |
-
# # Constants
|
| 485 |
-
# API_KEY = "84e26811a314599e940f343b4d5894a7"
|
| 486 |
-
# LOCATION = "Pakistan"
|
| 487 |
-
|
| 488 |
-
# # Sidebar
|
| 489 |
-
# st.sidebar.title("Smart Grid Dashboard")
|
| 490 |
-
# location = st.sidebar.text_input("Enter Location", LOCATION)
|
| 491 |
-
|
| 492 |
-
# # Fetch and display weather data
|
| 493 |
-
# weather = fetch_weather(API_KEY, location)
|
| 494 |
-
# if weather:
|
| 495 |
-
# st.sidebar.write(f"Temperature: {weather['temperature']} °C")
|
| 496 |
-
# st.sidebar.write(f"Wind Speed: {weather['wind_speed']} m/s")
|
| 497 |
-
# st.sidebar.write(f"Weather: {weather['weather']}")
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
# # Tabs
|
| 502 |
-
# tab_home, tab_storage, tab_trading = st.tabs(["Home", "Power Storage", "Electricity Trade Management"])
|
| 503 |
-
|
| 504 |
-
# # Home Tab
|
| 505 |
-
# with tab_home:
|
| 506 |
-
# st.title("Real-Time Smart Grid Dashboard")
|
| 507 |
-
|
| 508 |
-
# # Generate synthetic data
|
| 509 |
-
# data = generate_synthetic_data()
|
| 510 |
-
|
| 511 |
-
# # Grid Health
|
| 512 |
-
# # st.subheader("Grid Health Overview")
|
| 513 |
-
# # grid_health_counts = data["grid_health"].value_counts()
|
| 514 |
-
# # st.bar_chart(grid_health_counts)
|
| 515 |
-
|
| 516 |
-
# # Power Consumption, Generation & Storage Graph
|
| 517 |
-
# st.subheader("Power Consumption, Generation & Storage")
|
| 518 |
-
# fig = px.line(data, x="timestamp", y=["load_demand_kwh", "solar_output_kw", "wind_output_kw"],
|
| 519 |
-
# title="Power Consumption, Generation & Storage", labels={"value": "Power (MW)"})
|
| 520 |
-
# fig.update_traces(line=dict(width=2))
|
| 521 |
-
# st.plotly_chart(fig)
|
| 522 |
-
|
| 523 |
-
# # Grid Health
|
| 524 |
-
# st.subheader("Grid Health Overview")
|
| 525 |
-
# grid_health_counts = data["grid_health"].value_counts()
|
| 526 |
-
# st.bar_chart(grid_health_counts)
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
# # Optimization Recommendations
|
| 530 |
-
# current_demand = data["load_demand_kwh"].iloc[-1]
|
| 531 |
-
# current_solar = data["solar_output_kw"].iloc[-1]
|
| 532 |
-
# current_wind = data["wind_output_kw"].iloc[-1]
|
| 533 |
-
# recommendation = optimize_load(current_demand, current_solar, current_wind)
|
| 534 |
-
|
| 535 |
-
# st.subheader("Recommendations")
|
| 536 |
-
# st.write(f"Current Load Demand: {current_demand} MW")
|
| 537 |
-
# st.write(f"Solar Output: {current_solar} MW")
|
| 538 |
-
# st.write(f"Wind Output: {current_wind} MW")
|
| 539 |
-
# st.write(f"Recommendation: {recommendation}")
|
| 540 |
-
|
| 541 |
-
# # Storage Tab
|
| 542 |
-
# with tab_storage:
|
| 543 |
-
# st.title("Energy Storage Overview")
|
| 544 |
-
|
| 545 |
-
# # Energy Contribution by Resources
|
| 546 |
-
# st.subheader("Energy Contribution Percentage by Resources")
|
| 547 |
-
# energy_data = {
|
| 548 |
-
# "Wind": 5,
|
| 549 |
-
# "Solar": 7,
|
| 550 |
-
# "Turbine": 10
|
| 551 |
-
# }
|
| 552 |
-
# energy_df = pd.DataFrame(list(energy_data.items()), columns=["Source", "Energy (MW)"])
|
| 553 |
-
# fig = px.pie(energy_df, values="Energy (MW)", names="Source", title="Energy Contribution by Resources")
|
| 554 |
-
# st.plotly_chart(fig)
|
| 555 |
-
|
| 556 |
-
# # Energy Storage Merge
|
| 557 |
-
# st.subheader("Total Energy Stored")
|
| 558 |
-
# st.write("Energy stored from all sources:")
|
| 559 |
-
# energy_stored = sum(energy_data.values())
|
| 560 |
-
# st.write(f"Total Energy Stored: {energy_stored} MW")
|
| 561 |
-
# st.write("Energy sources merged into total energy storage:")
|
| 562 |
-
# st.write(f"Total Energy Stored in Grid: {energy_stored} MW")
|
| 563 |
-
|
| 564 |
-
# # Trading Tab
|
| 565 |
-
# with tab_trading:
|
| 566 |
-
# st.title("Electricity Trade Management")
|
| 567 |
-
|
| 568 |
-
# # Simulating Electricity Trade (Energy cubes & trading)
|
| 569 |
-
# st.subheader("Energy Trade Overview")
|
| 570 |
-
# energy_trade = {
|
| 571 |
-
# "USA": 50,
|
| 572 |
-
# "Germany": 40,
|
| 573 |
-
# "India": 30
|
| 574 |
-
# }
|
| 575 |
-
# trade_df = pd.DataFrame(list(energy_trade.items()), columns=["Country", "Energy (MW)"])
|
| 576 |
-
# fig = px.bar(trade_df, x="Country", y="Energy (MW)", title="Energy Trading Overview")
|
| 577 |
-
# st.plotly_chart(fig)
|
| 578 |
-
|
| 579 |
-
# st.write("Energy cubes available for trading:")
|
| 580 |
-
# st.write("The system can trade energy with other countries.")
|
| 581 |
-
|
| 582 |
-
# code 6
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
# import streamlit as st
|
| 587 |
-
# import pandas as pd
|
| 588 |
-
# import plotly.graph_objects as go
|
| 589 |
-
# from app_backend import fetch_data, generate_recommendations, grid_health_status, generate_trading_options
|
| 590 |
-
|
| 591 |
-
# # Dashboard layout
|
| 592 |
-
# st.title('Real-Time Smart Grid Application Dashboard')
|
| 593 |
-
# st.sidebar.title('Navigation')
|
| 594 |
-
# tabs = ['Home', 'Energy Storage', 'Electricity Trade Management']
|
| 595 |
-
# selected_tab = st.sidebar.radio('Choose Tab', tabs)
|
| 596 |
-
|
| 597 |
-
# # Fetch data and prepare visualizations
|
| 598 |
-
# data = fetch_data()
|
| 599 |
-
|
| 600 |
-
# if selected_tab == 'Home':
|
| 601 |
-
# st.header('Home - Real-Time Data Overview')
|
| 602 |
-
|
| 603 |
-
# # Current weather and grid information
|
| 604 |
-
# st.subheader("Location Weather Data")
|
| 605 |
-
# st.write(f"Temperature: {data['temperature']} °C")
|
| 606 |
-
# st.write(f"Wind Speed: {data['wind_speed']} m/s")
|
| 607 |
-
# st.write(f"Weather: {data['weather_condition']}")
|
| 608 |
-
|
| 609 |
-
# # Real-Time Power Flow Visualization (with dynamic chart)
|
| 610 |
-
# st.subheader("Real-Time Power Flow Visualization")
|
| 611 |
-
# fig = go.Figure()
|
| 612 |
-
# fig.add_trace(go.Scatter(x=data['timestamps'], y=data['total_consumption'], mode='lines', name='Total Consumption (MW)', line=dict(color='red')))
|
| 613 |
-
# fig.add_trace(go.Scatter(x=data['timestamps'], y=data['grid_generation'], mode='lines', name='Grid Generation (MW)', line=dict(color='green')))
|
| 614 |
-
# fig.add_trace(go.Scatter(x=data['timestamps'], y=data['storage_usage'], mode='lines', name='Storage Usage (MW)', line=dict(color='blue')))
|
| 615 |
-
# fig.update_layout(title="Power Flow", xaxis_title="Time", yaxis_title="Power (MW)")
|
| 616 |
-
# st.plotly_chart(fig)
|
| 617 |
-
|
| 618 |
-
# # Grid Health Status
|
| 619 |
-
# st.subheader("Grid Health Indicators")
|
| 620 |
-
# health_status = grid_health_status(data)
|
| 621 |
-
# st.write(health_status)
|
| 622 |
-
|
| 623 |
-
# # AI Recommendations
|
| 624 |
-
# st.subheader("AI Recommendations")
|
| 625 |
-
# recommendations = generate_recommendations(data)
|
| 626 |
-
# for rec in recommendations:
|
| 627 |
-
# st.write(rec)
|
| 628 |
-
|
| 629 |
-
# elif selected_tab == 'Energy Storage':
|
| 630 |
-
# st.header('Energy Storage Overview')
|
| 631 |
-
|
| 632 |
-
# # Storage Contribution Chart
|
| 633 |
-
# st.subheader("Energy Storage Contribution by Resources")
|
| 634 |
-
# fig = go.Figure()
|
| 635 |
-
# fig.add_trace(go.Pie(labels=['Solar', 'Wind', 'Hydro'], values=[data['solar_storage'], data['wind_storage'], data['hydro_storage']], hole=0.3))
|
| 636 |
-
# fig.update_layout(title="Energy Storage Contribution")
|
| 637 |
-
# st.plotly_chart(fig)
|
| 638 |
-
|
| 639 |
-
# # Total Energy Storage with Circle Representation
|
| 640 |
-
# st.subheader("Total Energy Storage Representation")
|
| 641 |
-
# fig = go.Figure()
|
| 642 |
-
# fig.add_trace(go.Scatterpolar(r=[data['solar_storage'], data['wind_storage'], data['hydro_storage']], theta=['Solar', 'Wind', 'Hydro'], fill='toself', name='Energy Sources'))
|
| 643 |
-
# fig.add_trace(go.Scatterpolar(r=[data['total_storage']], theta=['Total Storage'], fill='none', mode='text+markers', text=['Total Storage'], textposition='center', marker=dict(size=15, color='purple')))
|
| 644 |
-
# fig.update_layout(title="Energy Storage and Total", polar=dict(radialaxis=dict(visible=True)), showlegend=False)
|
| 645 |
-
# st.plotly_chart(fig)
|
| 646 |
-
|
| 647 |
-
# elif selected_tab == 'Electricity Trade Management':
|
| 648 |
-
# st.header('Electricity Trade Management')
|
| 649 |
-
|
| 650 |
-
# # Display available energy for trade
|
| 651 |
-
# st.subheader("Energy Trade Availability")
|
| 652 |
-
# trading_options = generate_trading_options(data)
|
| 653 |
-
# st.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