ffmap-backend/d3mapbuilder.py

24 lines
689 B
Python
Raw Normal View History

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