d3json: make output more similar to pre-rewrite version
parent
446bc98403
commit
5fba69de7a
|
@ -86,4 +86,6 @@ class Node(defaultdict):
|
||||||
else:
|
else:
|
||||||
new_neighbor[key] = val
|
new_neighbor[key] = val
|
||||||
ret["neighbors"].append(new_neighbor)
|
ret["neighbors"].append(new_neighbor)
|
||||||
|
if "id" not in ret:
|
||||||
|
ret["id"] = self.id
|
||||||
return ret
|
return ret
|
||||||
|
|
|
@ -25,42 +25,55 @@ class Output:
|
||||||
nodes = []
|
nodes = []
|
||||||
count = 0
|
count = 0
|
||||||
for node in set(nodedb.values()):
|
for node in set(nodedb.values()):
|
||||||
nodes.append(node.export())
|
node_export = node.export()
|
||||||
|
node_export["flags"] = {
|
||||||
|
"gateway": "vpn" in node and node["vpn"],
|
||||||
|
"client": False,
|
||||||
|
"online": True
|
||||||
|
}
|
||||||
|
nodes.append(node_export)
|
||||||
indexes[node.id] = count
|
indexes[node.id] = count
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
links = []
|
links = {}
|
||||||
for node in set(nodedb.values()):
|
for node in set(nodedb.values()):
|
||||||
if "neighbors" in node:
|
for neighbor in node.get("neighbors", []):
|
||||||
links.extend(
|
key = (neighbor["neighbor"].id, node.id)
|
||||||
{
|
rkey = tuple(reversed(key))
|
||||||
|
if rkey in links:
|
||||||
|
links[rkey]["quality"] += ","+neighbor["metric"]
|
||||||
|
else:
|
||||||
|
links[key] = {
|
||||||
"source": indexes[node.id],
|
"source": indexes[node.id],
|
||||||
"target": indexes[neighbor["neighbor"].id],
|
"target": indexes[neighbor["neighbor"].id],
|
||||||
"quality": neighbor["metric"],
|
"quality": neighbor["metric"],
|
||||||
"type": "vpn" if neighbor["neighbor"]["vpn"] else None,
|
"type": "vpn" if neighbor["neighbor"]["vpn"] or node["vpn"] else None,
|
||||||
"id": "-".join((node.id, neighbor["neighbor"].id)),
|
"id": "-".join((node.id, neighbor["neighbor"].id)),
|
||||||
} for neighbor in node["neighbors"]
|
}
|
||||||
)
|
for client in node.get("clients", []):
|
||||||
if "clients" in node:
|
if not client in indexes:
|
||||||
for client in node["clients"]:
|
nodes.append({
|
||||||
if not client in indexes:
|
"id": client,
|
||||||
nodes.append({
|
"flags": {
|
||||||
"id": client,
|
"client": True,
|
||||||
})
|
"online": True,
|
||||||
indexes[client] = count
|
"gateway": False
|
||||||
count += 1
|
}
|
||||||
|
|
||||||
links.append({
|
|
||||||
"source": indexes[node.id],
|
|
||||||
"target": indexes[client],
|
|
||||||
"quality": "TT",
|
|
||||||
"type": "client",
|
|
||||||
"id": "-".join((node.id, client)),
|
|
||||||
})
|
})
|
||||||
|
indexes[client] = count
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
links[(node.id, client)] = {
|
||||||
|
"source": indexes[node.id],
|
||||||
|
"target": indexes[client],
|
||||||
|
"quality": "TT",
|
||||||
|
"type": "client",
|
||||||
|
"id": "-".join((node.id, client)),
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"nodes": nodes,
|
"nodes": nodes,
|
||||||
"links": links,
|
"links": list(links.values()),
|
||||||
"meta": {
|
"meta": {
|
||||||
"timestamp": datetime.utcnow()
|
"timestamp": datetime.utcnow()
|
||||||
.replace(microsecond=0)
|
.replace(microsecond=0)
|
||||||
|
|
Loading…
Reference in New Issue