diff --git a/d3mapbuilder.py b/d3mapbuilder.py index 34e238b..a60665c 100644 --- a/d3mapbuilder.py +++ b/d3mapbuilder.py @@ -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) diff --git a/node.py b/node.py index 077d399..57c7f88 100644 --- a/node.py +++ b/node.py @@ -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__()