Commit 8041ee10 authored by Janez K's avatar Janez K
Browse files

procesiranje streamov s for loopi

parent f8933ac2
...@@ -14,93 +14,117 @@ class Stream(models.Model): ...@@ -14,93 +14,117 @@ class Stream(models.Model):
def execute(self,workflow=None,outputs={}): def execute(self,workflow=None,outputs={}):
if workflow is None: if workflow is None:
workflow = self.workflow workflow = self.workflow
finished = []
ready_to_run = [] ready_to_run = []
widgets = workflow.widgets.all() widgets = workflow.widgets.all()
#get unfinished #get unfinished
unfinished_list = [] if workflow.is_for_loop():
loop = True fi = workflow.widgets.filter(type='for_input')[0]
while loop: fo = workflow.widgets.filter(type='for_output')[0]
for w in unfinished_list: outer_output = fo.inputs.all()[0].outer_output
# prepare all the inputs for this widget outputs[outer_output.pk]=(outer_output.variable,[])
input_dict = {} input_list = []
output_dict = {} try:
if fi.outputs.all()[0].outer_input.connections.count() > 0:
for i in w.inputs.all(): input_list = outputs[fi.outputs.all()[0].outer_input.connections.all()[0].output.pk][1]
#gremo pogledat ce obstaja povezava in ce obstaja gremo value prebrat iz outputa except:
if not i.parameter: input_list = []
if i.connections.count() > 0: else:
#preberemo value iz output_dicta input_list = [0]
i.value = outputs[i.connections.all()[0].output.pk][1]
#print input_list
for for_input in input_list:
#print for_input
finished = []
unfinished_list = []
loop = True
while loop:
for w in unfinished_list:
# prepare all the inputs for this widget
input_dict = {}
output_dict = {}
for i in w.inputs.all():
#gremo pogledat ce obstaja povezava in ce obstaja gremo value prebrat iz outputa
if not i.parameter:
if i.connections.count() > 0:
#preberemo value iz output_dicta
i.value = outputs[i.connections.all()[0].output.pk][1]
else:
i.value = None
if i.multi_id == 0:
input_dict[i.variable]=i.value
else:
if not i.variable in input_dict:
input_dict[i.variable]=[]
if not i.value==None:
input_dict[i.variable].append(i.value)
if w.type == 'regular':
function_to_call = getattr(workflows.library,w.abstract_widget.action)
if w.abstract_widget.wsdl != '':
input_dict['wsdl']=w.abstract_widget.wsdl
input_dict['wsdl_method']=w.abstract_widget.wsdl_method
if w.abstract_widget.has_progress_bar:
output_dict = function_to_call(input_dict,w)
else: else:
i.value = None output_dict = function_to_call(input_dict)
if i.multi_id == 0:
input_dict[i.variable]=i.value
else:
if not i.variable in input_dict:
input_dict[i.variable]=[]
if not i.value==None:
input_dict[i.variable].append(i.value)
if w.type == 'regular':
function_to_call = getattr(workflows.library,w.abstract_widget.action)
if w.abstract_widget.wsdl != '':
input_dict['wsdl']=w.abstract_widget.wsdl
input_dict['wsdl_method']=w.abstract_widget.wsdl_method
if w.abstract_widget.has_progress_bar:
output_dict = function_to_call(input_dict,w)
else:
output_dict = function_to_call(input_dict)
if w.type == 'subprocess':
new_outputs = self.execute(workflow=w.workflow_link,outputs=outputs)
for o in w.outputs.all():
value = None
try:
if o.inner_input.connections.count() > 0:
value = new_outputs[o.inner_input.connections.all()[0].output.pk][1]
except:
value = None
output_dict[o.variable]=value
if w.type == 'for_input':
pass
if w.type == 'for_output':
pass
if w.type == 'input':
for o in w.outputs.all():
value = None
try:
if o.outer_input.connections.count() > 0:
value = outputs[o.outer_input.connections.all()[0].output.pk][1]
except:
value = None
output_dict[o.variable]=value
if w.type == 'output':
pass
for o in w.outputs.all(): if w.type == 'subprocess':
outputs[o.pk]=(o.variable,output_dict[o.variable]) new_outputs = self.execute(workflow=w.workflow_link,outputs=outputs)
for o in w.outputs.all():
finished.append(w.pk) try:
unfinished_list = [] outputs[o.pk]=new_outputs[o.pk]
for w in widgets: except:
if not w.pk in finished: outputs[o.pk]=(o.variable,None)
ready_to_run = True
connections = workflow.connections.filter(input__widget=w) if w.type == 'for_input':
for c in connections: for o in w.outputs.all():
if c.output.widget.pk not in finished: outputs[o.pk]=(o.variable,for_input)
ready_to_run = False #print outputs[o.pk]
break output_dict[o.variable]=for_input
if ready_to_run:
unfinished_list.append(w) if w.type == 'for_output':
if len(unfinished_list)==0: for i in w.inputs.all():
loop = False outputs[i.outer_output.pk][1].append(input_dict[i.variable])
output_dict[i.variable]=input_dict[i.variable]
if w.type == 'input':
for o in w.outputs.all():
value = None
try:
if o.outer_input.connections.count() > 0:
value = outputs[o.outer_input.connections.all()[0].output.pk][1]
except:
value = None
output_dict[o.variable]=value
if w.type == 'output':
for i in w.inputs.all():
outputs[i.outer_output.pk]=(i.outer_output.variable,input_dict[i.variable])
if w.type != 'subprocess':
for o in w.outputs.all():
outputs[o.pk]=(o.variable,output_dict[o.variable])
finished.append(w.pk)
unfinished_list = []
for w in widgets:
if not w.pk in finished:
ready_to_run = True
connections = workflow.connections.filter(input__widget=w)
for c in connections:
if c.output.widget.pk not in finished:
ready_to_run = False
break
if ready_to_run:
unfinished_list.append(w)
if len(unfinished_list)==0:
loop = False
return outputs return outputs
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment