File size: 2,965 Bytes
d0258ad
 
5c8245c
 
3890c1e
5c8245c
62f1ae6
 
 
 
 
 
 
 
ad36919
bb79117
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5c8245c
62f1ae6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5c8245c
62f1ae6
d0258ad
62f1ae6
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import streamlit as st
import pandas as pd
import plotly.express as px
from simple_salesforce import Salesforce
from map_visualization import show_fault_map

# πŸ” Connect to Salesforce
sf = Salesforce(
    username="[email protected]",
    password="Vedavathi@04",
    security_token="jqe4His8AcuFJucZz5NBHfGU"
)

# πŸ“„ Query to get Pole records
query = """
SELECT Id,
       Name,
       Power_Required__c,
       Power_Sufficient__c,
       RFID_Tag__c,
       Site__c,
       Solar_Generation__c,
       Wind_Generation__c,
       Alert_Level__c,
       Camera_Status__c,
       Health_Score__c,
       Location_Latitude__c,
       Location_Longitude__c
FROM Pole__c
LIMIT 1000
"""

# πŸ“¦ Fetch and flatten records
result = sf.query_all(query)
df = pd.json_normalize(result['records'])

# 🧼 Remove 'attributes' column if present
df = df.drop(columns='attributes', errors='ignore')

# πŸ–₯️ Streamlit App Layout
st.set_page_config(page_title="VIEP Dashboard", layout="wide")
st.title("πŸ”Œ Vedavathi Intelligent Energy Poles Dashboard")

# πŸ“‹ Show Full Table
st.subheader("πŸ“‹ Pole Data Table")
st.dataframe(df)

# πŸ”‹ Bar Chart: Solar vs Wind Generation
st.subheader("πŸ”‹ Solar vs Wind Generation")
fig_bar = px.bar(
    df,
    x="Name",
    y=["Solar_Generation__c", "Wind_Generation__c"],
    barmode="group",
    labels={"value": "Power (kW)", "Name": "Pole"},
    title="Power Generation per Pole"
)
st.plotly_chart(fig_bar, use_container_width=True)

# πŸŽ₯ Pie Chart: Camera Status
st.subheader("πŸŽ₯ Camera Status Distribution")
fig_cam = px.pie(
    df,
    names="Camera_Status__c",
    title="Camera Status",
    hole=0.3
)
st.plotly_chart(fig_cam, use_container_width=True)

# 🚨 Pie Chart: Alert Level
st.subheader("🚨 Alert Level Distribution")
fig_alert = px.pie(
    df,
    names="Alert_Level__c",
    title="Alert Level",
    hole=0.3
)
st.plotly_chart(fig_alert, use_container_width=True)

# πŸ“ˆ Health Score by Site
st.subheader("πŸ“ˆ Health Score by Site")
fig_health = px.box(
    df,
    x="Site__c",
    y="Health_Score__c",
    points="all",
    title="Health Score Distribution",
    labels={"Site__c": "Site", "Health_Score__c": "Health Score"}
)
st.plotly_chart(fig_health, use_container_width=True)

# πŸ—ΊοΈ Map of Pole Locations
st.subheader("πŸ—ΊοΈ Pole Locations Map")
df_map = df.dropna(subset=["Location_Latitude__c", "Location_Longitude__c"])
if not df_map.empty:
    fig_map = px.scatter_mapbox(
        df_map,
        lat="Location_Latitude__c",
        lon="Location_Longitude__c",
        hover_name="Name",
        color="Alert_Level__c",
        zoom=4,
        mapbox_style="open-street-map"
    )
    st.plotly_chart(fig_map, use_container_width=True)
else:
    st.warning("No location data available to show the map.")

# πŸ“₯ Download CSV
st.download_button(
    label="⬇️ Download Data as CSV",
    data=df.to_csv(index=False),
    file_name="pole_data.csv",
    mime="text/csv"
)