File size: 3,083 Bytes
8e7b080
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import dash
from dash import html, dcc
import pandas as pd
import plotly.graph_objects as go
import random

# Config
AREAS = ['Kurnool', 'Hyderabad', 'Ballari', 'Gadwal']
POLES_PER_AREA = 12
ALERT_LEVELS = ['Green', 'Yellow', 'Red']

def simulate_poles():
    poles = []
    for area in AREAS:
        for i in range(1, POLES_PER_AREA + 1):
            solar = round(random.uniform(3.0, 7.5), 2)
            wind = round(random.uniform(0.5, 2.0), 2)
            tilt = round(random.uniform(0, 10), 2)
            vibration = round(random.uniform(0, 3), 2)
            camera_status = random.choice(['Online', 'Offline'])
            total_power = solar + wind
            required_power = 6.5
            alert = 'Green'
            if total_power < 4 or tilt > 6 or vibration > 2.5:
                alert = 'Yellow'
            if total_power < 3 or tilt > 8 or vibration > 2.8:
                alert = 'Red'
            poles.append({
                'Area': area,
                'Pole': f'P{i}',
                'Solar (kWh)': solar,
                'Wind (kWh)': wind,
                'Power Total': total_power,
                'Tilt (°)': tilt,
                'Vibration (g)': vibration,
                'Camera': camera_status,
                'Alert': alert
            })
    return pd.DataFrame(poles)

df = simulate_poles()

# Convert alerts to numeric levels for color scale
alert_map = {'Green': 1, 'Yellow': 2, 'Red': 3}
df['AlertLevel'] = df['Alert'].map(alert_map)

def create_alert_heatmap(df):
    pivot_df = df.pivot(index='Area', columns='Pole', values='AlertLevel')
    color_scale = [
        [0, "green"],
        [0.5, "yellow"],
        [1.0, "red"]
    ]
    fig = go.Figure(data=go.Heatmap(
        z=pivot_df.values,
        x=pivot_df.columns,
        y=pivot_df.index,
        colorscale=color_scale,
        zmin=1,
        zmax=3,
        showscale=False,
        hovertemplate="Pole: %{x}<br>Area: %{y}<br>Alert Level: %{z}<extra></extra>"
    ))
    fig.update_layout(title="Smart Pole Alert Heatmap", height=500)
    return fig

app = dash.Dash(__name__)
server = app.server  # Required for Hugging Face

app.layout = html.Div([
    html.H1("Vedavathi Smart Pole Monitoring", style={"textAlign": "center"}),

    dcc.Graph(figure=create_alert_heatmap(df)),

    html.Div([
        html.H3("🚨 Red Alert Poles", style={"color": "red", "textAlign": "center"}),
        html.Div([
            html.Span(f"{row['Area']} - {row['Pole']}", style={
                "animation": "blinker 1s linear infinite",
                "color": "red",
                "fontWeight": "bold",
                "fontSize": "18px",
                "margin": "8px",
                "display": "inline-block"
            })
            for _, row in df[df["Alert"] == "Red"].iterrows()
        ], style={"textAlign": "center"})
    ]),

    dcc.Markdown('''
    <style>
    @keyframes blinker {
        50% { opacity: 0; }
    }
    </style>
    ''', dangerously_allow_html=True)
])

if __name__ == "__main__":
    app.run_server(debug=False, host="0.0.0.0", port=7860)