2012-05-11 18:39:26 +02:00
|
|
|
import json
|
|
|
|
|
|
|
|
class D3MapBuilder:
|
|
|
|
def __init__(self, db):
|
2012-05-12 14:57:25 +02:00
|
|
|
self._db = db
|
2012-05-11 18:39:26 +02:00
|
|
|
|
|
|
|
def build(self):
|
|
|
|
output = dict()
|
|
|
|
|
2012-06-04 17:33:23 +02:00
|
|
|
output['nodes'] = [{'group': x.group, 'name': x.name, 'id': x.id,
|
2012-05-11 18:39:26 +02:00
|
|
|
'macs': ', '.join(x.macs)
|
2012-05-12 14:57:25 +02:00
|
|
|
} for x in self._db.get_nodes() if x.online]
|
2012-05-11 18:39:26 +02:00
|
|
|
output['links'] = [{'source': x.pair[0], 'target': x.pair[1],
|
|
|
|
'distance': x.distance,
|
|
|
|
'strength': x.strength
|
2012-05-12 14:57:25 +02:00
|
|
|
} for x in self._db.get_links()]
|
2012-05-11 18:39:26 +02:00
|
|
|
|
|
|
|
return json.dumps(output)
|
|
|
|
|