DSatishchandra commited on
Commit
12a0b73
Β·
verified Β·
1 Parent(s): 316a19c

Update modules/visuals.py

Browse files
Files changed (1) hide show
  1. modules/visuals.py +34 -42
modules/visuals.py CHANGED
@@ -2,60 +2,52 @@ import streamlit as st
2
  import plotly.express as px
3
  import pandas as pd
4
 
5
- def display_dashboard(df):
6
- st.subheader("πŸ“Š System Summary")
7
- col1, col2, col3, col4 = st.columns(4)
8
  col1.metric("Total Poles", df.shape[0])
9
  col2.metric("🚨 Red Alerts", df[df['AlertLevel'] == "Red"].shape[0])
10
  col3.metric("⚑ Power Issues", df[df['PowerSufficient'] == "No"].shape[0])
11
- col4.metric("πŸ“ Locations", len(df['Location'].unique()))
12
 
13
  def display_charts(df):
14
  st.subheader("βš™οΈ Energy Generation Trends")
15
- st.bar_chart(df.groupby("Location")[["SolarGen(kWh)", "WindGen(kWh)"]].sum())
16
  st.subheader("πŸ“‰ Tilt vs Vibration")
17
  st.scatter_chart(df.rename(columns={"Tilt(Β°)": "Tilt", "Vibration(g)": "Vibration"}).set_index("PoleID")[["Tilt", "Vibration"]])
18
 
19
- def display_heatmap(df):
20
- # Map AlertLevel to numeric values for heatmap intensity
21
- alert_map = {"Green": 0, "Yellow": 1, "Red": 2}
22
- df = df.copy() # Avoid modifying the original DataFrame
23
- df["AlertValue"] = df["AlertLevel"].map(alert_map)
24
 
25
- # Pivot table for heatmap values (AlertValue)
26
- pivot_df = df.pivot_table(index="Location", columns="PoleID", values="AlertValue", fill_value=0)
 
27
 
28
- # Create hover text DataFrame
29
- hover_data = df[["Location", "PoleID", "AlertLevel", "Anomalies"]].copy()
30
- hover_text = pivot_df.copy().astype(str)
31
- for loc in pivot_df.index:
32
- for pole in pivot_df.columns:
33
- # Find matching row in hover_data
34
- match = hover_data[(hover_data["Location"] == loc) & (hover_data["PoleID"] == pole)]
35
- if not match.empty:
36
- alert = match["AlertLevel"].iloc[0]
37
- anomalies = match["Anomalies"].iloc[0]
38
- hover_text.loc[loc, pole] = f"Pole: {pole}<br>Alert: {alert}<br>Anomalies: {anomalies}"
39
- else:
40
- hover_text.loc[loc, pole] = f"Pole: {pole}<br>Alert: None<br>Anomalies: None"
41
-
42
- # Create heatmap using Plotly
43
- fig = px.imshow(
44
- pivot_df,
45
- color_continuous_scale=["green", "yellow", "red"],
46
- zmin=0,
47
- zmax=2,
48
- title="Pole Alert Heatmap by Location",
49
- text_auto=False,
50
- height=500
51
  )
52
- fig.update_traces(hovertemplate="%{customdata}<br>%{x}<br>%{y}", customdata=hover_text)
53
  fig.update_layout(
54
- xaxis_title="Pole ID",
55
- yaxis_title="Location",
56
- coloraxis_colorbar=dict(
57
- tickvals=[0, 1, 2],
58
- ticktext=["Green", "Yellow", "Red"]
59
- )
60
  )
61
  st.plotly_chart(fig, use_container_width=True)
 
2
  import plotly.express as px
3
  import pandas as pd
4
 
5
+ def display_dashboard(df, location):
6
+ st.subheader(f"πŸ“Š System Summary - {location}")
7
+ col1, col2, col3 = st.columns(3)
8
  col1.metric("Total Poles", df.shape[0])
9
  col2.metric("🚨 Red Alerts", df[df['AlertLevel'] == "Red"].shape[0])
10
  col3.metric("⚑ Power Issues", df[df['PowerSufficient'] == "No"].shape[0])
 
11
 
12
  def display_charts(df):
13
  st.subheader("βš™οΈ Energy Generation Trends")
14
+ st.bar_chart(df.groupby("Zone")[["SolarGen(kWh)", "WindGen(kWh)"]].sum())
15
  st.subheader("πŸ“‰ Tilt vs Vibration")
16
  st.scatter_chart(df.rename(columns={"Tilt(Β°)": "Tilt", "Vibration(g)": "Vibration"}).set_index("PoleID")[["Tilt", "Vibration"]])
17
 
18
+ def display_map_heatmap(df, location):
19
+ if df.empty:
20
+ st.warning("No data available for this location.")
21
+ return
 
22
 
23
+ # Map AlertLevel to colors
24
+ df = df.copy()
25
+ df["AlertColor"] = df["AlertLevel"].map({"Green": "green", "Yellow": "yellow", "Red": "red"})
26
 
27
+ # Create scatter map
28
+ fig = px.scatter_mapbox(
29
+ df,
30
+ lat="Latitude",
31
+ lon="Longitude",
32
+ color="AlertLevel",
33
+ color_discrete_map={"Green": "green", "Yellow": "yellow", "Red": "red"},
34
+ size_max=15,
35
+ zoom=10,
36
+ hover_data={
37
+ "PoleID": True,
38
+ "RFID": True,
39
+ "AlertLevel": True,
40
+ "Anomalies": True,
41
+ "Zone": True,
42
+ "Latitude": False,
43
+ "Longitude": False
44
+ },
45
+ title=f"Pole Alert Map - {location}",
46
+ height=600
 
 
 
47
  )
 
48
  fig.update_layout(
49
+ mapbox_style="open-street-map",
50
+ margin={"r":0,"t":50,"l":0,"b":0},
51
+ showlegend=True
 
 
 
52
  )
53
  st.plotly_chart(fig, use_container_width=True)