From c7b33a4839068ff58a58f7d9440423f462293ad8 Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Wed, 6 Jun 2012 03:34:52 +0200 Subject: [PATCH] ensure unique ids for links and nodes --- d3mapbuilder.py | 7 +++++-- node.py | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-) 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__()