-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsplitters.py
More file actions
70 lines (54 loc) · 1.54 KB
/
splitters.py
File metadata and controls
70 lines (54 loc) · 1.54 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from .common import *
from .dandynodes import *
def flatten(lst):
flattened = []
for x in lst:
if isinstance(x, list):
flattened.extend(flatten(x))
else:
flattened.append(x)
return flattened
def string_cat(lst):
cat = ""
for x in lst:
if isinstance(x, list):
cat += string_cat(x)
elif isinstance(x, str):
cat += x
else:
cat += str(x)
return cat
class DandySplitter(DandyWithHash):
CATEGORY = DANDY_SPLITTERS_CATEGORY
@classmethod
def DANDY_INPUTS(cls):
return DandyOptionalInputs(super(), { 'n_outputs': N_OUTPUTS_INPUT, })
def input_name_prefix(self):
return 'whoopsydaisies'
def run(self, **kwargs):
n_outputs = kwargs['n_outputs']
inputs = []
for key, value in kwargs.items():
if key.startswith(self.input_name_prefix()) and value != None:
inputs.append(value)
inputs = flatten(inputs)
n_inputs = len(inputs)
n = min(n_inputs, n_outputs)
out = []
if n > 0:
for i in range(0, n_outputs):
j = i % n
out.append(inputs[j])
return ui_and_result(*out)
class DandyIntSplitter(DandySplitter):
def input_name_prefix(self):
return 'int'
class DandyFloatSplitter(DandySplitter):
def input_name_prefix(self):
return 'float'
class DandyBooleanSplitter(DandySplitter):
def input_name_prefix(self):
return 'boolean'
class DandyStringArraySplitter(DandySplitter):
def input_name_prefix(self):
return 'string'