-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmisc_light.py
67 lines (54 loc) · 1.76 KB
/
misc_light.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/python3
import itertools as it
import string
import collections as c
import datetime as dt
import sys
def log(log_type, msg):
now = dt.datetime.now()
print('{}: {}: {}'.format(now, log_type, msg), file=sys.stderr)
def swmm_input_read(f):
ls = list(_swmm_input_preprocess(f.readlines()))
nlines = len(ls)
i = 0
expect_header = True
#NOTE: do not mess with section order!
inp = c.OrderedDict()
while i < nlines:
l = ls[i]
if expect_header:
if l[0] == '[' and l[-1] == ']':
name = l[1:-1]
data = []
expect_header = False
else:
return False, 'internal error: expected \'[\', found: \'' + l + '\''
else:
if l[0] == '[':
inp[name] = data
expect_header = True
i -= 1
else:
data.append(l.split())
i += 1
# remainder
if data:
inp[name] = data
return True, inp
def _swmm_input_preprocess(ls):
ls = map(lambda l : ''.join(it.takewhile(lambda c : c not in ";\n\r", l)), ls) # get rid of comments ...
ls = filter(lambda l : any(map(lambda c : c in string.printable, l)), ls) # ... and blank lines
return ls
def swmm_input_write(f, inp):
for name, ls in inp.items():
f.write('[' + name + ']\n')
for l in ls:
f.write(' '.join(l) + '\n')
f.write('\n')
def find_houses_Implementation(values,searchFor,*dedication):
matching = [s for s in values if not 'not_connected' in s and searchFor in s[0]]
matching_RBs = []
for arg in dedication:
matching_RBs += ([s for s in matching if arg in s[0]])
Houses = [s[0] for s in matching_RBs]
return Houses