Spaces:
Sleeping
Sleeping
Commit ·
d6f1e58
1
Parent(s): 33c12a3
updated commit 009
Browse files- app.py +5 -5
- data/network_topology.csv +7 -6
- model/trace_analyzer.py +19 -11
- utils/visualization.py +48 -9
app.py
CHANGED
|
@@ -14,11 +14,11 @@ def process_alarm(alarm_text, source_node):
|
|
| 14 |
|
| 15 |
# Define example inputs
|
| 16 |
examples = [
|
| 17 |
-
["Power failure at
|
| 18 |
-
["Signal
|
| 19 |
-
["
|
| 20 |
-
["
|
| 21 |
-
["
|
| 22 |
]
|
| 23 |
|
| 24 |
iface = gr.Interface(
|
|
|
|
| 14 |
|
| 15 |
# Define example inputs
|
| 16 |
examples = [
|
| 17 |
+
["Power failure detected at BTS1", "BTS1"],
|
| 18 |
+
["Signal loss between BTS2 and BSC1", "BTS2"],
|
| 19 |
+
["Link instability reported at BSC2", "BSC2"],
|
| 20 |
+
["Transmission error from MSC1 to CoreNetwork", "MSC1"],
|
| 21 |
+
["Device reboot alert from BTS3", "BTS3"]
|
| 22 |
]
|
| 23 |
|
| 24 |
iface = gr.Interface(
|
data/network_topology.csv
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
| 1 |
+
Source,Target
|
| 2 |
+
BTS1,BSC1
|
| 3 |
+
BTS2,BSC1
|
| 4 |
+
BTS3,BSC2
|
| 5 |
+
BSC1,MSC1
|
| 6 |
+
BSC2,MSC1
|
| 7 |
+
MSC1,CoreNetwork
|
model/trace_analyzer.py
CHANGED
|
@@ -1,16 +1,24 @@
|
|
| 1 |
-
|
| 2 |
import pandas as pd
|
|
|
|
| 3 |
|
| 4 |
def analyze_trace(source_node):
|
| 5 |
df = pd.read_csv("data/network_topology.csv")
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
return path, nodes
|
|
|
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
+
import networkx as nx
|
| 3 |
|
| 4 |
def analyze_trace(source_node):
|
| 5 |
df = pd.read_csv("data/network_topology.csv")
|
| 6 |
+
|
| 7 |
+
# Build directed graph from the CSV
|
| 8 |
+
G = nx.from_pandas_edgelist(df, source='Source', target='Target', create_using=nx.DiGraph())
|
| 9 |
+
|
| 10 |
+
# Get all nodes
|
| 11 |
+
nodes = list(G.nodes())
|
| 12 |
+
|
| 13 |
+
# Default: no path found
|
| 14 |
+
path = ["Unknown"]
|
| 15 |
+
|
| 16 |
+
# Attempt to find path to CoreNetwork
|
| 17 |
+
target_node = "CoreNetwork"
|
| 18 |
+
if source_node in G and target_node in G:
|
| 19 |
+
try:
|
| 20 |
+
path = nx.shortest_path(G, source=source_node, target=target_node)
|
| 21 |
+
except nx.NetworkXNoPath:
|
| 22 |
+
path = ["No path to CoreNetwork"]
|
| 23 |
+
|
| 24 |
return path, nodes
|
utils/visualization.py
CHANGED
|
@@ -1,13 +1,52 @@
|
|
| 1 |
-
|
| 2 |
-
import matplotlib.pyplot as plt
|
| 3 |
import networkx as nx
|
|
|
|
| 4 |
|
| 5 |
def plot_network(nodes, path):
|
|
|
|
| 6 |
G = nx.DiGraph()
|
| 7 |
-
for i in range(len(nodes)-1):
|
| 8 |
-
G.add_edge(nodes[i], nodes[i+1])
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import plotly.graph_objects as go
|
|
|
|
| 2 |
import networkx as nx
|
| 3 |
+
import random
|
| 4 |
|
| 5 |
def plot_network(nodes, path):
|
| 6 |
+
# Create a graph
|
| 7 |
G = nx.DiGraph()
|
| 8 |
+
for i in range(len(nodes) - 1):
|
| 9 |
+
G.add_edge(nodes[i], nodes[i + 1])
|
| 10 |
+
|
| 11 |
+
# Assign 3D positions
|
| 12 |
+
pos = {node: (random.uniform(-1, 1), random.uniform(-1, 1), random.uniform(-1, 1)) for node in G.nodes()}
|
| 13 |
+
|
| 14 |
+
edge_trace = []
|
| 15 |
+
for edge in G.edges():
|
| 16 |
+
x0, y0, z0 = pos[edge[0]]
|
| 17 |
+
x1, y1, z1 = pos[edge[1]]
|
| 18 |
+
color = "red" if edge[0] in path and edge[1] in path and path.index(edge[1]) - path.index(edge[0]) == 1 else "gray"
|
| 19 |
+
edge_trace.append(go.Scatter3d(
|
| 20 |
+
x=[x0, x1, None], y=[y0, y1, None], z=[z0, z1, None],
|
| 21 |
+
mode='lines',
|
| 22 |
+
line=dict(color=color, width=6 if color == "red" else 2),
|
| 23 |
+
hoverinfo='none'
|
| 24 |
+
))
|
| 25 |
+
|
| 26 |
+
node_trace = go.Scatter3d(
|
| 27 |
+
x=[pos[node][0] for node in G.nodes()],
|
| 28 |
+
y=[pos[node][1] for node in G.nodes()],
|
| 29 |
+
z=[pos[node][2] for node in G.nodes()],
|
| 30 |
+
mode='markers+text',
|
| 31 |
+
marker=dict(
|
| 32 |
+
size=10,
|
| 33 |
+
color=['red' if node in path else 'lightblue' for node in G.nodes()],
|
| 34 |
+
opacity=0.8
|
| 35 |
+
),
|
| 36 |
+
text=list(G.nodes()),
|
| 37 |
+
textposition="top center",
|
| 38 |
+
hoverinfo='text'
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
fig = go.Figure(data=edge_trace + [node_trace])
|
| 42 |
+
fig.update_layout(
|
| 43 |
+
title="Telecom Network Topology - 3D View",
|
| 44 |
+
showlegend=False,
|
| 45 |
+
scene=dict(
|
| 46 |
+
xaxis=dict(showbackground=False),
|
| 47 |
+
yaxis=dict(showbackground=False),
|
| 48 |
+
zaxis=dict(showbackground=False)
|
| 49 |
+
),
|
| 50 |
+
margin=dict(l=0, r=0, b=0, t=40)
|
| 51 |
+
)
|
| 52 |
+
return fig
|