for general-satellite

 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
def add_node(tree, h, *t):
((not t or t[0] is None)
and ((type(tree) == set
and tree.add(h)
or tree.__setitem__(h, {}))
or 1)
or (h in tree
and (add_node(tree[h], *t) or 1)
or add_node(tree.__setitem__(h, {}) or tree[h], *t)))
def serialize_to_jqtree(tree):
if type(tree) == dict:
d = []
for k in tree:
d.append({'label': k, 'children': serialize_to_jqtree(tree[k])})
return d
else:
return [{'label': k} for k in tree]
def generate_cond(attrs, _str, params):
conv = lambda x: x and dt.strptime(x, '%Y-%m-%d %H:%M:%S')
from_date = conv(params[1].get('from', False))
to_date = conv(params[1].get('to', False))
extra_cond = None
opt = []
if from_date:
extra_cond = (params[0] >= from_date)
if to_date:
extra_cond = (extra_cond
and extra_cond & (params[0] <= to_date)
or (params[0] <= to_date))
for e in [zip(attrs, el.split('|')) for el in _str.split()]:
cond = None
list_attr = []
for attr, val in e:
cond = cond and (attr == val) & cond or (attr == val)
list_attr.append(attr)
if extra_cond:
cond = cond & extra_cond
opt.append((cond, list_attr))
return opt