Commit 160cc531 authored by Alberts S's avatar Alberts S
Browse files

Add visualizations via pyvis

parent 7d108309
......@@ -8,6 +8,7 @@ import matplotlib.pyplot as plt
import networkx as nx
import scipy
import seaborn as sns
from pyvis.network import Network
from CapybaraNetty import CapybaraNetty
......@@ -22,11 +23,11 @@ class Visualizer(CapybaraNetty):
async def run(self):
G_simple = await self.get_host_latency_overview()
if len(G_simple) > 0:
await self.draw_graph(G_simple, "simple")
await self.draw_graphs(G_simple, "simple")
G_optimizations = await self.get_host_latency_optimization_overview(G_simple.copy())
await self.draw_graph(self.get_graph_only_improved_overview(G_optimizations), "optimizations_overview")
await self.draw_graphs(self.get_graph_only_improved_overview(G_optimizations), "optimizations_overview")
for target in self.external_targets_for_optimizations:
await self.draw_graph(
await self.draw_graphs(
self.get_graph_only_improved_specific_target(G_optimizations, target),
f"optimizations_target_{target}",
)
......@@ -92,7 +93,24 @@ class Visualizer(CapybaraNetty):
G = self.get_graph_only_improved_overview(G)
return nx.subgraph_view(G, filter_node=filter_node, filter_edge=filter_edge)
async def draw_graph(self, G: nx.Graph, file_base_name):
async def draw_graphs(self, G: nx.Graph, file_base_name):
output_base_name = f'out/network_latency_{file_base_name}_{time.strftime("%Y%m%d-%H_%M_%S")}'
await self.draw_graph_networkx(G, output_base_name)
await self.draw_graph_pyvis(G, output_base_name)
async def draw_graph_pyvis(self, G, output_base):
# PyVis
net = Network("1280px", "1280px")
net.from_nx(G)
for edge in net.edges:
edge["label"] = edge["weight"]
output_name = f"{output_base}_pyvis.html"
self.__logger.info(f"Writing {output_name}")
net.save_graph(output_name)
async def draw_graph_networkx(self, G, output_base):
# Matplotlib + NetworkX
pos = nx.fruchterman_reingold_layout(G, 5)
fig = plt.figure(1, figsize=(60, 20), dpi=120)
......@@ -101,7 +119,7 @@ class Visualizer(CapybaraNetty):
node_colors = ["red" if node in self.external_targets_for_optimizations else "green" for node in G]
nx.draw_networkx_edge_labels(G, pos, edge_labels=labels, label_pos=0.5)
nx.draw(G, pos, with_labels=True, edge_color=edge_colors, node_size=100, node_color=node_colors)
output_name = f'out/network_latency_{file_base_name}_{time.strftime("%Y%m%d-%H_%M_%S")}.png'
output_name = f"{output_base}_networkx.png"
self.__logger.info(f"Writing {output_name}")
plt.savefig(output_name, bbox_inches="tight")
plt.close()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment