rehanafzal commited on
Commit
fcb4f92
·
verified ·
1 Parent(s): e60d54e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +81 -147
app.py CHANGED
@@ -1,175 +1,109 @@
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", "Storage", "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
 
 
 
104
 
 
 
 
 
 
 
 
105
 
 
 
 
106
 
 
 
 
 
 
107
 
108
 
109
 
110
 
111
 
112
- import streamlit as st
113
- import pandas as pd
114
- import plotly.express as px
115
- from app_backend import fetch_weather, generate_synthetic_data, optimize_load
116
 
117
- # Constants
118
- API_KEY = "84e26811a314599e940f343b4d5894a7"
119
- LOCATION = "Pakistan"
120
 
121
- # Sidebar
122
- st.sidebar.title("Smart Grid Dashboard")
123
- location = st.sidebar.text_input("Enter Location", LOCATION)
124
 
125
- # Fetch and display weather data
126
- weather = fetch_weather(API_KEY, location)
127
- if weather:
128
- st.sidebar.write(f"Temperature: {weather['temperature']} °C")
129
- st.sidebar.write(f"Wind Speed: {weather['wind_speed']} m/s")
130
- st.sidebar.write(f"Weather: {weather['weather']}")
131
 
132
- # Main dashboard
133
- st.title("Real-Time Smart Grid Dashboard")
134
-
135
- # Generate synthetic data
136
- data = generate_synthetic_data()
137
-
138
- # Plot total power consumption (load demand) in MW
139
- fig = px.line(data, x="timestamp", y="load_demand_mw", title="Power Consumption (MW) Over Time")
140
- st.plotly_chart(fig)
141
-
142
- # Plot renewable energy generation in MW (solar + wind) on the graph
143
- fig = px.bar(
144
- data,
145
- x="timestamp",
146
- y=["solar_output_mw", "wind_output_mw"],
147
- title="Renewable Energy Generation (MW)",
148
- labels={"value": "Power (MW)", "variable": "Energy Source"}
149
- )
150
- st.plotly_chart(fig)
151
-
152
- # Show battery storage in kWh
153
- fig = px.line(data, x="timestamp", y="battery_storage_kwh", title="Battery Storage (kWh) Over Time")
154
- st.plotly_chart(fig)
155
-
156
- # Grid health
157
- st.subheader("Grid Health Overview")
158
- grid_health_counts = data["grid_health"].value_counts()
159
- st.bar_chart(grid_health_counts)
160
-
161
- # Optimization recommendations
162
- current_demand = data["load_demand_mw"].iloc[-1] # Load demand in MW
163
- current_solar = data["solar_output_mw"].iloc[-1] # Solar output in MW
164
- current_wind = data["wind_output_mw"].iloc[-1] # Wind output in MW
165
- recommendation = optimize_load(current_demand, current_solar, current_wind)
166
-
167
- st.subheader("Recommendations")
168
- st.write(f"Current Load Demand: {current_demand} MW")
169
- st.write(f"Solar Output: {current_solar} MW")
170
- st.write(f"Wind Output: {current_wind} MW")
171
- st.write(f"Recommendation: {recommendation}")
172
-
173
- # Electricity Trade Management Tab
174
- st.subheader("Electricity Trade Management")
175
- st.write("Manage energy trading here.")
 
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", "Storage", "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
 
104
 
105
 
 
 
 
 
106
 
 
 
 
107
 
 
 
 
108
 
 
 
 
 
 
 
109