rehanafzal commited on
Commit
b6427c3
·
verified ·
1 Parent(s): 8f2dde4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +152 -152
app.py CHANGED
@@ -476,177 +476,177 @@
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
- # # Tabs
500
- # tab_home, tab_storage, tab_trading = st.tabs(["Home", "Power Storage", "Electricity Trade Management"])
501
-
502
- # # Home Tab
503
- # with tab_home:
504
- # st.title("Real-Time Smart Grid Dashboard")
505
-
506
- # # Generate synthetic data
507
- # data = generate_synthetic_data()
508
-
509
- # # Grid Health
510
- # # st.subheader("Grid Health Overview")
511
- # # grid_health_counts = data["grid_health"].value_counts()
512
- # # st.bar_chart(grid_health_counts)
513
-
514
- # # Power Consumption, Generation & Storage Graph
515
- # st.subheader("Power Consumption, Generation & Storage")
516
- # fig = px.line(data, x="timestamp", y=["load_demand_kwh", "solar_output_kw", "wind_output_kw"],
517
- # title="Power Consumption, Generation & Storage", labels={"value": "Power (MW)"})
518
- # fig.update_traces(line=dict(width=2))
519
- # st.plotly_chart(fig)
520
 
521
- # # Grid Health
522
- # st.subheader("Grid Health Overview")
523
- # grid_health_counts = data["grid_health"].value_counts()
524
- # st.bar_chart(grid_health_counts)
525
 
526
 
527
- # # Optimization Recommendations
528
- # current_demand = data["load_demand_kwh"].iloc[-1]
529
- # current_solar = data["solar_output_kw"].iloc[-1]
530
- # current_wind = data["wind_output_kw"].iloc[-1]
531
- # recommendation = optimize_load(current_demand, current_solar, current_wind)
532
-
533
- # st.subheader("Recommendations")
534
- # st.write(f"Current Load Demand: {current_demand} MW")
535
- # st.write(f"Solar Output: {current_solar} MW")
536
- # st.write(f"Wind Output: {current_wind} MW")
537
- # st.write(f"Recommendation: {recommendation}")
538
-
539
- # # Storage Tab
540
- # with tab_storage:
541
- # st.title("Energy Storage Overview")
542
-
543
- # # Energy Contribution by Resources
544
- # st.subheader("Energy Contribution Percentage by Resources")
545
- # energy_data = {
546
- # "Wind": 5,
547
- # "Solar": 7,
548
- # "Turbine": 10
549
- # }
550
- # energy_df = pd.DataFrame(list(energy_data.items()), columns=["Source", "Energy (MW)"])
551
- # fig = px.pie(energy_df, values="Energy (MW)", names="Source", title="Energy Contribution by Resources")
552
- # st.plotly_chart(fig)
553
-
554
- # # Energy Storage Merge
555
- # st.subheader("Total Energy Stored")
556
- # st.write("Energy stored from all sources:")
557
- # energy_stored = sum(energy_data.values())
558
- # st.write(f"Total Energy Stored: {energy_stored} MW")
559
- # st.write("Energy sources merged into total energy storage:")
560
- # st.write(f"Total Energy Stored in Grid: {energy_stored} MW")
561
-
562
- # # Trading Tab
563
- # with tab_trading:
564
- # st.title("Electricity Trade Management")
565
 
566
- # # Simulating Electricity Trade (Energy cubes & trading)
567
- # st.subheader("Energy Trade Overview")
568
- # energy_trade = {
569
- # "USA": 50,
570
- # "Germany": 40,
571
- # "India": 30
572
- # }
573
- # trade_df = pd.DataFrame(list(energy_trade.items()), columns=["Country", "Energy (MW)"])
574
- # fig = px.bar(trade_df, x="Country", y="Energy (MW)", title="Energy Trading Overview")
575
- # st.plotly_chart(fig)
 
 
 
 
 
 
 
 
 
 
 
 
576
 
577
- # st.write("Energy cubes available for trading:")
578
- # st.write("The system can trade energy with other countries.")
579
 
580
  # code 6
581
 
582
 
583
 
584
- import streamlit as st
585
- import pandas as pd
586
- import plotly.graph_objects as go
587
- from app_backend import fetch_data, generate_recommendations, grid_health_status, generate_trading_options
588
 
589
- # Dashboard layout
590
- st.title('Real-Time Smart Grid Application Dashboard')
591
- st.sidebar.title('Navigation')
592
- tabs = ['Home', 'Energy Storage', 'Electricity Trade Management']
593
- selected_tab = st.sidebar.radio('Choose Tab', tabs)
594
 
595
- # Fetch data and prepare visualizations
596
- data = fetch_data()
597
 
598
- if selected_tab == 'Home':
599
- st.header('Home - Real-Time Data Overview')
600
 
601
- # Current weather and grid information
602
- st.subheader("Location Weather Data")
603
- st.write(f"Temperature: {data['temperature']} °C")
604
- st.write(f"Wind Speed: {data['wind_speed']} m/s")
605
- st.write(f"Weather: {data['weather_condition']}")
606
-
607
- # Real-Time Power Flow Visualization (with dynamic chart)
608
- st.subheader("Real-Time Power Flow Visualization")
609
- fig = go.Figure()
610
- fig.add_trace(go.Scatter(x=data['timestamps'], y=data['total_consumption'], mode='lines', name='Total Consumption (MW)', line=dict(color='red')))
611
- fig.add_trace(go.Scatter(x=data['timestamps'], y=data['grid_generation'], mode='lines', name='Grid Generation (MW)', line=dict(color='green')))
612
- fig.add_trace(go.Scatter(x=data['timestamps'], y=data['storage_usage'], mode='lines', name='Storage Usage (MW)', line=dict(color='blue')))
613
- fig.update_layout(title="Power Flow", xaxis_title="Time", yaxis_title="Power (MW)")
614
- st.plotly_chart(fig)
615
 
616
- # Grid Health Status
617
- st.subheader("Grid Health Indicators")
618
- health_status = grid_health_status(data)
619
- st.write(health_status)
620
 
621
- # AI Recommendations
622
- st.subheader("AI Recommendations")
623
- recommendations = generate_recommendations(data)
624
- for rec in recommendations:
625
- st.write(rec)
626
 
627
- elif selected_tab == 'Energy Storage':
628
- st.header('Energy Storage Overview')
629
 
630
- # Storage Contribution Chart
631
- st.subheader("Energy Storage Contribution by Resources")
632
- fig = go.Figure()
633
- fig.add_trace(go.Pie(labels=['Solar', 'Wind', 'Hydro'], values=[data['solar_storage'], data['wind_storage'], data['hydro_storage']], hole=0.3))
634
- fig.update_layout(title="Energy Storage Contribution")
635
- st.plotly_chart(fig)
636
 
637
- # Total Energy Storage with Circle Representation
638
- st.subheader("Total Energy Storage Representation")
639
- fig = go.Figure()
640
- fig.add_trace(go.Scatterpolar(r=[data['solar_storage'], data['wind_storage'], data['hydro_storage']], theta=['Solar', 'Wind', 'Hydro'], fill='toself', name='Energy Sources'))
641
- 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')))
642
- fig.update_layout(title="Energy Storage and Total", polar=dict(radialaxis=dict(visible=True)), showlegend=False)
643
- st.plotly_chart(fig)
644
 
645
- elif selected_tab == 'Electricity Trade Management':
646
- st.header('Electricity Trade Management')
647
 
648
- # Display available energy for trade
649
- st.subheader("Energy Trade Availability")
650
- trading_options = generate_trading_options(data)
651
- st.write(trading_options)
652
 
 
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
+ # Tabs
500
+ tab_home, tab_storage, tab_trading = st.tabs(["Home", "Power Storage", "Electricity Trade Management"])
501
+
502
+ # Home Tab
503
+ with tab_home:
504
+ st.title("Real-Time Smart Grid Dashboard")
505
+
506
+ # Generate synthetic data
507
+ data = generate_synthetic_data()
508
+
509
+ # Grid Health
510
+ # st.subheader("Grid Health Overview")
511
+ # grid_health_counts = data["grid_health"].value_counts()
512
+ # st.bar_chart(grid_health_counts)
513
+
514
+ # Power Consumption, Generation & Storage Graph
515
+ st.subheader("Power Consumption, Generation & Storage")
516
+ fig = px.line(data, x="timestamp", y=["load_demand_kwh", "solar_output_kw", "wind_output_kw"],
517
+ title="Power Consumption, Generation & Storage", labels={"value": "Power (MW)"})
518
+ fig.update_traces(line=dict(width=2))
519
+ st.plotly_chart(fig)
520
 
521
+ # Grid Health
522
+ st.subheader("Grid Health Overview")
523
+ grid_health_counts = data["grid_health"].value_counts()
524
+ st.bar_chart(grid_health_counts)
525
 
526
 
527
+ # Optimization Recommendations
528
+ current_demand = data["load_demand_kwh"].iloc[-1]
529
+ current_solar = data["solar_output_kw"].iloc[-1]
530
+ current_wind = data["wind_output_kw"].iloc[-1]
531
+ recommendation = optimize_load(current_demand, current_solar, current_wind)
532
+
533
+ st.subheader("Recommendations")
534
+ st.write(f"Current Load Demand: {current_demand} MW")
535
+ st.write(f"Solar Output: {current_solar} MW")
536
+ st.write(f"Wind Output: {current_wind} MW")
537
+ st.write(f"Recommendation: {recommendation}")
538
+
539
+ # Storage Tab
540
+ with tab_storage:
541
+ st.title("Energy Storage Overview")
542
+
543
+ # Energy Contribution by Resources
544
+ st.subheader("Energy Contribution Percentage by Resources")
545
+ energy_data = {
546
+ "Wind": 5,
547
+ "Solar": 7,
548
+ "Turbine": 10
549
+ }
550
+ energy_df = pd.DataFrame(list(energy_data.items()), columns=["Source", "Energy (MW)"])
551
+ fig = px.pie(energy_df, values="Energy (MW)", names="Source", title="Energy Contribution by Resources")
552
+ st.plotly_chart(fig)
 
 
 
 
 
 
 
 
 
 
 
 
553
 
554
+ # Energy Storage Merge
555
+ st.subheader("Total Energy Stored")
556
+ st.write("Energy stored from all sources:")
557
+ energy_stored = sum(energy_data.values())
558
+ st.write(f"Total Energy Stored: {energy_stored} MW")
559
+ st.write("Energy sources merged into total energy storage:")
560
+ st.write(f"Total Energy Stored in Grid: {energy_stored} MW")
561
+
562
+ # Trading Tab
563
+ with tab_trading:
564
+ st.title("Electricity Trade Management")
565
+
566
+ # Simulating Electricity Trade (Energy cubes & trading)
567
+ st.subheader("Energy Trade Overview")
568
+ energy_trade = {
569
+ "USA": 50,
570
+ "Germany": 40,
571
+ "India": 30
572
+ }
573
+ trade_df = pd.DataFrame(list(energy_trade.items()), columns=["Country", "Energy (MW)"])
574
+ fig = px.bar(trade_df, x="Country", y="Energy (MW)", title="Energy Trading Overview")
575
+ st.plotly_chart(fig)
576
 
577
+ st.write("Energy cubes available for trading:")
578
+ st.write("The system can trade energy with other countries.")
579
 
580
  # code 6
581
 
582
 
583
 
584
+ # import streamlit as st
585
+ # import pandas as pd
586
+ # import plotly.graph_objects as go
587
+ # from app_backend import fetch_data, generate_recommendations, grid_health_status, generate_trading_options
588
 
589
+ # # Dashboard layout
590
+ # st.title('Real-Time Smart Grid Application Dashboard')
591
+ # st.sidebar.title('Navigation')
592
+ # tabs = ['Home', 'Energy Storage', 'Electricity Trade Management']
593
+ # selected_tab = st.sidebar.radio('Choose Tab', tabs)
594
 
595
+ # # Fetch data and prepare visualizations
596
+ # data = fetch_data()
597
 
598
+ # if selected_tab == 'Home':
599
+ # st.header('Home - Real-Time Data Overview')
600
 
601
+ # # Current weather and grid information
602
+ # st.subheader("Location Weather Data")
603
+ # st.write(f"Temperature: {data['temperature']} °C")
604
+ # st.write(f"Wind Speed: {data['wind_speed']} m/s")
605
+ # st.write(f"Weather: {data['weather_condition']}")
606
+
607
+ # # Real-Time Power Flow Visualization (with dynamic chart)
608
+ # st.subheader("Real-Time Power Flow Visualization")
609
+ # fig = go.Figure()
610
+ # fig.add_trace(go.Scatter(x=data['timestamps'], y=data['total_consumption'], mode='lines', name='Total Consumption (MW)', line=dict(color='red')))
611
+ # fig.add_trace(go.Scatter(x=data['timestamps'], y=data['grid_generation'], mode='lines', name='Grid Generation (MW)', line=dict(color='green')))
612
+ # fig.add_trace(go.Scatter(x=data['timestamps'], y=data['storage_usage'], mode='lines', name='Storage Usage (MW)', line=dict(color='blue')))
613
+ # fig.update_layout(title="Power Flow", xaxis_title="Time", yaxis_title="Power (MW)")
614
+ # st.plotly_chart(fig)
615
 
616
+ # # Grid Health Status
617
+ # st.subheader("Grid Health Indicators")
618
+ # health_status = grid_health_status(data)
619
+ # st.write(health_status)
620
 
621
+ # # AI Recommendations
622
+ # st.subheader("AI Recommendations")
623
+ # recommendations = generate_recommendations(data)
624
+ # for rec in recommendations:
625
+ # st.write(rec)
626
 
627
+ # elif selected_tab == 'Energy Storage':
628
+ # st.header('Energy Storage Overview')
629
 
630
+ # # Storage Contribution Chart
631
+ # st.subheader("Energy Storage Contribution by Resources")
632
+ # fig = go.Figure()
633
+ # fig.add_trace(go.Pie(labels=['Solar', 'Wind', 'Hydro'], values=[data['solar_storage'], data['wind_storage'], data['hydro_storage']], hole=0.3))
634
+ # fig.update_layout(title="Energy Storage Contribution")
635
+ # st.plotly_chart(fig)
636
 
637
+ # # Total Energy Storage with Circle Representation
638
+ # st.subheader("Total Energy Storage Representation")
639
+ # fig = go.Figure()
640
+ # fig.add_trace(go.Scatterpolar(r=[data['solar_storage'], data['wind_storage'], data['hydro_storage']], theta=['Solar', 'Wind', 'Hydro'], fill='toself', name='Energy Sources'))
641
+ # 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')))
642
+ # fig.update_layout(title="Energy Storage and Total", polar=dict(radialaxis=dict(visible=True)), showlegend=False)
643
+ # st.plotly_chart(fig)
644
 
645
+ # elif selected_tab == 'Electricity Trade Management':
646
+ # st.header('Electricity Trade Management')
647
 
648
+ # # Display available energy for trade
649
+ # st.subheader("Energy Trade Availability")
650
+ # trading_options = generate_trading_options(data)
651
+ # st.write(trading_options)
652