ensure unique ids for links and nodes

This commit is contained in:
Nils Schneider 2012-06-06 03:34:52 +02:00
parent b5c8f9b6bc
commit c7b33a4839
2 changed files with 10 additions and 3 deletions

View file

@ -7,13 +7,16 @@ class D3MapBuilder:
def build(self):
output = dict()
nodes = self._db.get_nodes()
output['nodes'] = [{'group': x.group, 'name': x.name, 'id': x.id,
'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],
'distance': x.distance,
'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()]
return json.dumps(output)

View file

@ -13,7 +13,11 @@ class Node():
# 3 TT
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):
return self.macs.__repr__()