-
Notifications
You must be signed in to change notification settings - Fork 0
/
blendomaticutil.py
63 lines (48 loc) · 1.83 KB
/
blendomaticutil.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
import re
import json
def parse_list_string(list_string):
list_string = "[{}]".format(list_string.strip())
# add double quotes to make the list json parse-able
list_string = re.sub("\s*\,\s*", '","', list_string )
list_string = re.sub("\s*\[\s*", '["', list_string )
list_string = re.sub("\s*\]\s*", '"]', list_string )
# treat special cases, where we inserted quotes between two brackets
list_string = re.sub("\s*\,\s*\"\s*\[", ',[', list_string )
list_string = re.sub("\]\s*\"\s*\,\s*", '],', list_string )
list_string = re.sub("\[\s*\"\s*\[", '[[', list_string )
list_string = re.sub("\]\s*\"\s*\]", ']]', list_string )
jimport = json.loads(list_string)
# make sure every entry is wrapped in a list
wrapped_list = []
for entry in jimport:
if isinstance(entry, (list,)):
wrapped_list.append(entry)
else:
wrapped_list.append([entry])
return wrapped_list
def map_inputs_to_ouputs(*args):
"""
[ [o1,o2], [o3,o4] ]
[ f1, f2 ]
[ one_option ]
becomes
[ [o1,o2], [f1], [one_option] ]
[ [o3,o4], [f2], [one_option] ]
"""
parsed_input_lists = [ parse_list_string(e) for e in args]
# find which colum has the most entries
most_entries = 0
for e in parsed_input_lists:
most_entries = max(most_entries, len(e))
out_list = []
# re-arrange to have easier access to all parameters of one category
# in one entry of the output list
for i in range(most_entries):
this_entry_out = []
for e in parsed_input_lists:
# either use the entry if available, or use the last enry
# which is available
this_entries = e[i] if i < len(e) else e[-1]
this_entry_out.append(this_entries)
out_list.append(this_entry_out)
return out_list