4
0
mirror of https://github.com/cwinfo/yggdrasil-map synced 2025-08-14 15:58:10 +00:00

Pushing nodes to a database and generating graph from it

This commit is contained in:
Vanhala Antti
2014-05-30 17:34:00 +03:00
parent d6b0b97528
commit f51cf2025e
13 changed files with 293 additions and 318 deletions

29
web/graph.py Normal file
View File

@@ -0,0 +1,29 @@
class Node:
def __init__(self, ip, version=None, label=None):
self.ip = ip
self.version = version
self.label = ip[-4:] if label == None else label
def __lt__(self, b):
return self.ip < b.ip
def __repr__(self):
return 'Node(ip="%s", version=%s, label="%s")' % (
self.ip,
self.version,
self.label)
class Edge:
def __init__(self, a, b):
self.a, self.b = sorted([a, b])
def is_in(self, edges):
for e in edges:
if e.a.ip == self.a.ip and e.b.ip == self.b.ip:
return True
return False
def __repr__(self):
return 'Edge(a.ip="%s", b.ip="%s")' % (
self.a.ip,
self.b.ip)