ensure unique ids for links and nodes
This commit is contained in:
parent
b5c8f9b6bc
commit
c7b33a4839
|
@ -7,13 +7,16 @@ class D3MapBuilder:
|
||||||
def build(self):
|
def build(self):
|
||||||
output = dict()
|
output = dict()
|
||||||
|
|
||||||
|
nodes = self._db.get_nodes()
|
||||||
|
|
||||||
output['nodes'] = [{'group': x.group, 'name': x.name, 'id': x.id,
|
output['nodes'] = [{'group': x.group, 'name': x.name, 'id': x.id,
|
||||||
'macs': ', '.join(x.macs)
|
'macs': ', '.join(x.macs)
|
||||||
} for x in self._db.get_nodes() if x.online]
|
} for x in nodes if x.online]
|
||||||
output['links'] = [{'source': x.pair[0], 'target': x.pair[1],
|
output['links'] = [{'source': x.pair[0], 'target': x.pair[1],
|
||||||
'distance': x.distance,
|
'distance': x.distance,
|
||||||
'strength': x.strength,
|
'strength': x.strength,
|
||||||
'quality': x.quality
|
'quality': x.quality,
|
||||||
|
'id': "-".join(nodes[i].id for i in x.pair)
|
||||||
} for x in self._db.get_links()]
|
} for x in self._db.get_links()]
|
||||||
|
|
||||||
return json.dumps(output)
|
return json.dumps(output)
|
||||||
|
|
6
node.py
6
node.py
|
@ -13,7 +13,11 @@ class Node():
|
||||||
# 3 TT
|
# 3 TT
|
||||||
|
|
||||||
def add_mac(self, mac):
|
def add_mac(self, mac):
|
||||||
self.macs.add(mac.lower())
|
mac = mac.lower()
|
||||||
|
if len(self.macs) == 0:
|
||||||
|
self.id = mac
|
||||||
|
|
||||||
|
self.macs.add(mac)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return self.macs.__repr__()
|
return self.macs.__repr__()
|
||||||
|
|
Loading…
Reference in a new issue