latency, country labels

This commit is contained in:
Felix Pankratz 2025-07-22 22:45:49 +02:00
parent 0005a15922
commit 1d6ccaf5bb
3 changed files with 17 additions and 11 deletions

View File

@ -69,7 +69,7 @@ def generate_arch(p1, p2, height_factor=0.2, n_points=100):
return arch_points return arch_points
def traceroute(target: str) -> list[tuple[int, int]]: def traceroute(target: str):
database = IP2Location.IP2Location("IP2LOCATION-LITE-DB5.BIN", "SHARED_MEMORY") database = IP2Location.IP2Location("IP2LOCATION-LITE-DB5.BIN", "SHARED_MEMORY")
# Run traceroute command # Run traceroute command
@ -78,10 +78,11 @@ def traceroute(target: str) -> list[tuple[int, int]]:
capture_output=True, capture_output=True,
text=True, text=True,
) )
hops: list[str] = re.findall(r"\n\s*\d+\s+([\d.]+)", result.stdout) ips: list[str] = re.findall(r"\n\s*\d+\s+([\d.]+)\s+([\d.]+)", result.stdout)
coords: list[tuple[int, int]] = [] hops = []
for ip in hops: print(ips)
for ip, latency in ips:
if ip.startswith( if ip.startswith(
( (
"10.", "10.",
@ -108,10 +109,10 @@ def traceroute(target: str) -> list[tuple[int, int]]:
): ):
# exclude common local network addreses # exclude common local network addreses
continue continue
info = database.get_all(ip) hop = database.get_all(ip)
coords.append((float(info.latitude), float(info.longitude))) hop.latency = latency
return coords hops.append(hop)
return hops
async def main(): async def main():
@ -150,7 +151,7 @@ async def main():
if args.example: if args.example:
points_3d = [latlon_to_xyz(lat, lon) for lat, lon in EXAMPLE_ROUTE] points_3d = [latlon_to_xyz(lat, lon) for lat, lon in EXAMPLE_ROUTE]
else: else:
points_3d = [latlon_to_xyz(lat, lon) for lat, lon in locations] points_3d = [latlon_to_xyz(float(_.latitude), float(_.longitude)) for _ in locations]
if args.size: if args.size:
width, height = args.size width, height = args.size
@ -165,7 +166,7 @@ async def main():
city_marker = pv.Sphere(center=point, radius=0.02) city_marker = pv.Sphere(center=point, radius=0.02)
plotter.add_mesh(city_marker, color="blue") plotter.add_mesh(city_marker, color="blue")
labels = [str(_) for _ in range(len(points_3d))] labels = [ f'{_.country_short}: {_.latency}ms' for _ in locations]
raised_points = [point * 1.1 for point in points_3d] raised_points = [point * 1.1 for point in points_3d]
if raised_points: if raised_points:
plotter.add_point_labels(raised_points, labels, point_size=0, font_size=14) plotter.add_point_labels(raised_points, labels, point_size=0, font_size=14)

View File

@ -5,6 +5,7 @@ description = "Add your description here"
readme = "README.md" readme = "README.md"
requires-python = ">=3.13" requires-python = ">=3.13"
dependencies = [ dependencies = [
"ip2location>=8.10.5",
"numpy<2", "numpy<2",
"pyrender>=0.1.45", "pyrender>=0.1.45",
"pyvista>=0.45.3", "pyvista>=0.45.3",

View File

@ -42,6 +42,7 @@ class TerminalPlotter(pv.Plotter):
self.start_y -= missing self.start_y -= missing
print("\n" * self.needed_lines, end="") print("\n" * self.needed_lines, end="")
kitty.set_position(self.start_y, self.start_x) kitty.set_position(self.start_y, self.start_x)
self.orbit = self.generate_orbital_path()
async def _handle_key(self, c): async def _handle_key(self, c):
if c == "a": if c == "a":
@ -56,6 +57,8 @@ class TerminalPlotter(pv.Plotter):
self.camera.zoom(1.1) self.camera.zoom(1.1)
elif c == "-": elif c == "-":
self.camera.zoom(0.9) self.camera.zoom(0.9)
elif c == "p":
self.fly_to(self.orbit.points[15])
async def _input_loop(self): async def _input_loop(self):
fd = sys.stdin.fileno() fd = sys.stdin.fileno()
@ -70,7 +73,7 @@ class TerminalPlotter(pv.Plotter):
self._running = False self._running = False
else: else:
await self._handle_key(c) await self._handle_key(c)
await asyncio.sleep(0.01) await asyncio.sleep(0.001)
finally: finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
@ -98,6 +101,7 @@ class TerminalPlotter(pv.Plotter):
img.save(buffer, format="PNG") img.save(buffer, format="PNG")
await kitty.draw_to_terminal(buffer) await kitty.draw_to_terminal(buffer)
kitty.set_position(self.start_y, self.start_x) kitty.set_position(self.start_y, self.start_x)
self.camera.Azimuth(1)
async def run(self): async def run(self):
await self.initialize() await self.initialize()