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-06 03:34:52 +02:00
|
|
|
nodes = self._db.get_nodes()
|
|
|
|
|
2012-06-07 22:21:50 +02:00
|
|
|
output['nodes'] = [{'name': x.name, 'id': x.id,
|
2012-06-07 00:02:45 +02:00
|
|
|
'macs': ', '.join(x.macs),
|
2012-06-07 22:21:50 +02:00
|
|
|
'geo': x.gps.split(" ") if x.gps else None,
|
|
|
|
'flags': x.flags
|
|
|
|
} for x in nodes if x.flags['online']]
|
2012-05-11 18:39:26 +02:00
|
|
|
output['links'] = [{'source': x.pair[0], 'target': x.pair[1],
|
2012-06-06 03:34:52 +02:00
|
|
|
'quality': x.quality,
|
2012-06-07 22:58:45 +02:00
|
|
|
'type': x.type,
|
2012-06-06 03:34:52 +02:00
|
|
|
'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()]
|
2012-05-11 18:39:26 +02:00
|
|
|
|
|
|
|
return json.dumps(output)
|
|
|
|
|