This repository was archived by the owner on Aug 1, 2019. It is now read-only.
forked from ffnord/ffmap-backend
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathd3mapbuilder.py
More file actions
47 lines (37 loc) · 1.47 KB
/
d3mapbuilder.py
File metadata and controls
47 lines (37 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import json
import datetime
class D3MapBuilder:
def __init__(self, db):
self._db = db
def build(self):
output = dict()
now = datetime.datetime.utcnow().replace(microsecond=0)
nodes = self._db.get_nodes()
#remove invalid nodes (without name)
#nodes = list(filter(lambda x: x.name != "", nodes))
output['nodes'] = [{'name': x.name, 'id': x.id,
'geo': [float(x) for x in x.gps.split(" ")] if x.gps else None,
'firmware': x.firmware,
'flags': x.flags,
'clientcount': x.clientcount,
'uptime': x.uptime,
'tx_bytes': x.tx_bytes,
'rx_bytes': x.rx_bytes,
'loadavg': x.loadavg,
'autoupdater': x.autoupdater,
'branch': x.branch,
'hardware': x.hardware,
'gateway': x.gateway
} for x in nodes]
links = self._db.get_links()
#remove invalid links
#nodes = list(filter(lambda x: x.name != "", nodes))
output['links'] = [{'source': x.source.id, 'target': x.target.id,
'quality': x.quality,
'type': x.type,
'id': x.id
} for x in links]
output['meta'] = {
'timestamp': now.isoformat()
}
return json.dumps(output)