Sanjayraju30 commited on
Commit
8ea7afe
·
verified ·
1 Parent(s): 86ef349

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -30
app.py CHANGED
@@ -1,29 +1,29 @@
1
  import dash
2
- from dash import dcc, html, dash_table
3
  import pandas as pd
4
  import numpy as np
5
  import plotly.graph_objects as go
6
  import random
7
 
8
- # Constants
9
  SITES = ['Hyderabad', 'Kurnool', 'Bangalore', 'Warangal']
10
  POLES_PER_SITE = 12
11
- ALERT_THRESHOLD = 80 # Poles above this are red alert
12
 
13
- # Generate dummy data
14
  def generate_data():
15
- data = []
16
- for site in SITES:
17
- for pole in range(1, POLES_PER_SITE + 1):
18
- status = random.randint(0, 100)
19
- data.append({'Site': site, 'Pole': f'P{pole}', 'Status': status})
20
- return pd.DataFrame(data)
 
 
 
21
 
22
  df = generate_data()
23
 
24
- # Create heatmap figure
25
- def create_heatmap(dataframe):
26
- pivot_df = dataframe.pivot(index="Site", columns="Pole", values="Status")
27
  fig = go.Figure(data=go.Heatmap(
28
  z=pivot_df.values,
29
  x=pivot_df.columns,
@@ -36,34 +36,27 @@ def create_heatmap(dataframe):
36
  fig.update_layout(title="Pole Status Heatmap", height=500)
37
  return fig
38
 
39
- # Dash App
40
  app = dash.Dash(__name__)
41
- server = app.server # Needed for Hugging Face Spaces
42
-
43
- # Blinking style (CSS)
44
- blinking_style = {
45
- "animation": "blinker 1s linear infinite",
46
- "color": "red",
47
- "fontWeight": "bold",
48
- "fontSize": "20px",
49
- "margin": "10px"
50
- }
51
 
52
  app.layout = html.Div([
53
  html.H1("Pole Management Dashboard", style={'textAlign': 'center'}),
54
-
55
  dcc.Graph(figure=create_heatmap(df)),
56
 
57
  html.Div([
58
  html.Div("🚨 Red Alert Poles:", style={"fontWeight": "bold", "marginTop": "20px"}),
59
  html.Div([
60
- html.Span(f"{row['Site']} - {row['Pole']}", style=blinking_style)
 
 
 
 
 
 
61
  for _, row in df[df["Status"] > ALERT_THRESHOLD].iterrows()
62
  ])
63
  ], style={"textAlign": "center"}),
64
 
65
- # Add CSS for blinking effect
66
- html.Div([
67
  dcc.Markdown('''
68
  <style>
69
  @keyframes blinker {
@@ -73,7 +66,6 @@ app.layout = html.Div([
73
  ''', dangerously_allow_html=True)
74
  ])
75
 
76
- ])
77
-
78
  if __name__ == "__main__":
79
  app.run_server(debug=False, host="0.0.0.0", port=7860)
 
 
1
  import dash
2
+ from dash import dcc, html
3
  import pandas as pd
4
  import numpy as np
5
  import plotly.graph_objects as go
6
  import random
7
 
 
8
  SITES = ['Hyderabad', 'Kurnool', 'Bangalore', 'Warangal']
9
  POLES_PER_SITE = 12
10
+ ALERT_THRESHOLD = 80
11
 
 
12
  def generate_data():
13
+ return pd.DataFrame([
14
+ {
15
+ 'Site': site,
16
+ 'Pole': f'P{pole}',
17
+ 'Status': random.randint(0, 100)
18
+ }
19
+ for site in SITES
20
+ for pole in range(1, POLES_PER_SITE + 1)
21
+ ])
22
 
23
  df = generate_data()
24
 
25
+ def create_heatmap(df):
26
+ pivot_df = df.pivot(index="Site", columns="Pole", values="Status")
 
27
  fig = go.Figure(data=go.Heatmap(
28
  z=pivot_df.values,
29
  x=pivot_df.columns,
 
36
  fig.update_layout(title="Pole Status Heatmap", height=500)
37
  return fig
38
 
 
39
  app = dash.Dash(__name__)
40
+ server = app.server
 
 
 
 
 
 
 
 
 
41
 
42
  app.layout = html.Div([
43
  html.H1("Pole Management Dashboard", style={'textAlign': 'center'}),
 
44
  dcc.Graph(figure=create_heatmap(df)),
45
 
46
  html.Div([
47
  html.Div("🚨 Red Alert Poles:", style={"fontWeight": "bold", "marginTop": "20px"}),
48
  html.Div([
49
+ html.Span(f"{row['Site']} - {row['Pole']}", style={
50
+ "animation": "blinker 1s linear infinite",
51
+ "color": "red",
52
+ "fontWeight": "bold",
53
+ "fontSize": "20px",
54
+ "margin": "10px"
55
+ })
56
  for _, row in df[df["Status"] > ALERT_THRESHOLD].iterrows()
57
  ])
58
  ], style={"textAlign": "center"}),
59
 
 
 
60
  dcc.Markdown('''
61
  <style>
62
  @keyframes blinker {
 
66
  ''', dangerously_allow_html=True)
67
  ])
68
 
 
 
69
  if __name__ == "__main__":
70
  app.run_server(debug=False, host="0.0.0.0", port=7860)
71
+