Commit 9278aa0c authored by Janez K's avatar Janez K

Merge branch 'speedup' into dev

parents 3be5187a 16edca33
[report]
# Regexes for lines to exclude from consideration
exclude_lines =
# Have to re-enable the standard pragma
pragma: no cover
# Don't complain about missing debug-only code:
def __repr__
if self\.debug
if settings\.DEBUG
# Don't complain if tests don't hit defensive assertion code:
raise AssertionError
raise NotImplementedError
# Don't complain if non-runnable code isn't run:
if 0:
if __name__ == .__main__.:
\ No newline at end of file
......@@ -28,3 +28,5 @@ build/
/mothra/mothra.db-journal
celerybeat-schedule
.coverage
htmlcov
\ No newline at end of file
coverage run --source='.' manage.py test
coverage html --omit=workflows/segmine/data/mappings.py
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -21,4 +21,4 @@ class HarfLearner(orngRFCons.RandomForestLearner):
self.learner
class HarfClassifier(orngRFCons.RandomForestClassifier):
#class HarfClassifier(orngRFCons.RandomForestClassifier):
......@@ -19,6 +19,8 @@ if USE_CONCURRENCY:
from workflows.tasks import executeWidgetFunction, executeWidgetProgressBar, executeWidgetStreaming, executeWidgetWithRequest, runWidget, executeWidgetPostInteract
from workflows.engine import WidgetRunner, WorkflowRunner
class WidgetException(Exception):
pass
......@@ -157,7 +159,7 @@ class Workflow(models.Model):
for w in widgets:
if not w.finished and not w.running:
ready_to_run = True
connections = self.connections.filter(input__widget=w)
connections = self.connections.filter(input__widget=w).select_related('input__widget')
for c in connections:
if not c.output.widget.finished:
#print c.output.widget
......@@ -167,17 +169,46 @@ class Workflow(models.Model):
unfinished_list.append(w)
return unfinished_list
"""def run_for_loop(self):
widgets = self.widgets.all().prefetch_related('inputs','outputs')
connections = self.connections.all().select_related('input','output','input__widget','output__widget')
fi = None
fo = None
for w in widgets:
if w.type=='for_input':
fi = w
if w.type=='for_output':
fo = w
outer_output = fo.inputs.all()[0].outer_output
outer_output.value=[]
outer_output.save()
total = len(widgets)
input_list = fi.outputs.all()[0].outer_input.value # get all inputs from outer part
progress_total = len(input_list) # for progress bar
current_iteration = 0
for i in input_list:
finished = []
unfinished_list = []
fi.finished = True
proper_output = fi.outputs.all()[0]"""
def run_for_loop(self):
""" Method runs the workflow for loop. The use of [0] at the end of lines is because
there can be only one for loop in one workflow. This way we take the first one. """
#clear for_input and for_output
#print("run_for_loop")
fi = self.widgets.filter(type='for_input')[0]
fo = self.widgets.filter(type='for_output')[0]
widgets = self.widgets.all().prefetch_related('inputs','outputs')
fi = None
fo = None
for w in widgets:
if w.type=='for_input':
fi = w
if w.type=='for_output':
fo = w
outer_output = fo.inputs.all()[0].outer_output
outer_output.value=[]
outer_output.save()
total = len(widgets)
input_list = fi.outputs.all()[0].outer_input.value # get all inputs from outer part
progress_total = len(input_list) # for progress bar
current_iteration = 0
......@@ -198,10 +229,12 @@ class Workflow(models.Model):
while len(unfinished_list)>0:
for w in unfinished_list:
w.run(True) # run the widget
total = self.widgets.count()
completed = self.widgets.filter(finished=True).count()
self.widget.progress = (int)((current_iteration*100.0/progress_total)+(((completed*1.0)/total)*(100/progress_total)))
self.widget.save()
completed = 0
for w in widgets:
if w.finished:
completed = completed+1
self.widget.progress = (int)((current_iteration*100.0/progress_total)+(((completed*1.0)/total)*(100/progress_total)))
self.widget.save()
unfinished_list = self.get_runnable_widgets()
except:
raise
......@@ -763,16 +796,9 @@ class Widget(models.Model):
""" else run abstract widget function """
outputs = function_to_call(input_dict)
else:
if self.workflow_link.is_for_loop():
""" if this is object is a for loop than true and run;
else false and run workflow """
#print("proper_run_is_for_loop")
self.workflow_link.run_for_loop()
#print self.outputs.all()[0].value
elif self.workflow_link.is_cross_validation():
self.workflow_link.run_cross_validation()
else:
self.workflow_link.run()
wr = WidgetRunner(self,workflow_runner=WorkflowRunner(self.workflow,clean=False),standalone=True)
wr.run()
return
except:
self.error=True
self.running=False
......@@ -854,16 +880,23 @@ class Widget(models.Model):
elif self.type == 'cv_output':
""" if object is an output widget for cross validation,
then read output values and configure parameters"""
print "smo v cv_output"
for i in self.inputs.all():
if not i.parameter:
""" if there is a connection than true and read the output value """
if i.connections.count() > 0:
if i.value is None:
print "1"
i.value = [i.connections.all()[0].output.value]
else:
print "2"
i.value = [i.connections.all()[0].output.value] + i.value
print i.value
#print i.value
i.save()
print "----"
print i.outer_output.value
print "----"
i.outer_output.value.append(i.value)
i.outer_output.save()
self.finished=True
......
......@@ -6,11 +6,46 @@ Replace this with more appropriate tests for your application.
"""
from django.test import TestCase
from workflows.engine import WorkflowRunner, WidgetRunner
from workflows.models import Workflow, Widget
import time
class WorkflowEngineTest(TestCase):
fixtures = ['test_data',]
def test_fast_workflow_runner(self):
w = Workflow.objects.get(name='For loop test')
wr = WorkflowRunner(w)
wr.run()
wid = Widget.objects.get(id=6)
o = wid.outputs.all()[0].value
self.assertEqual(o,[20,40,60,80])
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.assertEqual(1 + 1, 2)
def test_fast_workflow_runner_cv(self):
w = Workflow.objects.get(name='Cross test')
wr = WorkflowRunner(w)
wr.run()
wid = Widget.objects.get(id=16)
o = wid.outputs.all()[0].value
self.assertEqual(o,[[[[u'2'], [u'1']], [u'3'], 1],
[[[u'3'], [u'1']], [u'2'], 1],
[[[u'3'], [u'2']], [u'1'], 1]])
class WidgetEngineTest(TestCase):
fixtures = ['test_data2',]
def test_fast_widget_runner(self):
w = Widget.objects.get(id=6)
wr = WidgetRunner(w,workflow_runner=WorkflowRunner(w.workflow,clean=False),standalone=True)
wr.run()
wid = Widget.objects.get(id=6)
o = wid.outputs.all()[0].value
self.assertEqual(o,[20,40,60,80])
def test_fast_widget_runner_cv(self):
w = Widget.objects.get(id=16)
wr = WidgetRunner(w,workflow_runner=WorkflowRunner(w.workflow,clean=False),standalone=True)
wr.run()
wid = Widget.objects.get(id=16)
o = wid.outputs.all()[0].value
self.assertEqual(o,[[[[u'2'], [u'1']], [u'3'], 1],
[[[u'3'], [u'1']], [u'2'], 1],
[[[u'3'], [u'2']], [u'1'], 1]])
\ No newline at end of file
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