initial working test wf
This commit is contained in:
parent
bfb039328c
commit
2fdd9aaf77
|
@ -85,45 +85,45 @@ class Workflow:
|
||||||
print self.name
|
print self.name
|
||||||
for stage in self.stages:
|
for stage in self.stages:
|
||||||
print ' %s' % stage.name
|
print ' %s' % stage.name
|
||||||
for fun in stage.functions:
|
for task in stage.tasks:
|
||||||
print ' %s' % fun.name
|
print ' %s' % task.name
|
||||||
|
|
||||||
|
|
||||||
class EmptyWorkflow(Workflow):
|
class EmptyWorkflow(Workflow):
|
||||||
name = 'Empty Workflow'
|
name = 'Empty Workflow'
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
print "initing empty workflow"
|
logger.log("debug", "initing empty workflow")
|
||||||
Workflow.__init__(self)
|
Workflow.__init__(self)
|
||||||
|
|
||||||
|
|
||||||
class Stage:
|
class Stage:
|
||||||
"""A stage is a part of the data analysis process.
|
"""A stage is a part of the data analysis process.
|
||||||
|
|
||||||
Each stage contains a set of functions that can be used to
|
Each stage contains a set of tasks that can be used to
|
||||||
accomplish the task. A typical early stage is 'preprocessing', which
|
accomplish the task. A typical early stage is 'preprocessing', which
|
||||||
can be done in several ways, each represented by a function.
|
can be done in several ways, each represented by a task.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, id, name):
|
def __init__(self, id, name):
|
||||||
self.id = id
|
self.id = id
|
||||||
self.name = name
|
self.name = name
|
||||||
self.functions = []
|
self.tasks = []
|
||||||
self.functions_by_id = {}
|
self.tasks_by_id = {}
|
||||||
|
|
||||||
def add_function(self, fun):
|
def add_task(self, task):
|
||||||
self.functions.append(fun)
|
self.tasks.append(task)
|
||||||
self.functions_by_id[fun.id] = fun
|
#self.tasks_by_id[task.id] = task
|
||||||
|
|
||||||
|
|
||||||
class Task:
|
class Task:
|
||||||
"""A Function object encapsulates a function on a data set.
|
"""A Task object encapsulates a task on a data set.
|
||||||
|
|
||||||
Each Function instance encapsulates some function that can be applied
|
Each Task instance encapsulates some task that can be applied
|
||||||
to one or more types of data.
|
to one or more types of data.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
title = ""
|
name = ""
|
||||||
|
|
||||||
def __init__(self, input):
|
def __init__(self, input):
|
||||||
self.input = input
|
self.input = input
|
||||||
|
@ -135,7 +135,7 @@ class Task:
|
||||||
|
|
||||||
# just return a Validation object
|
# just return a Validation object
|
||||||
def validate_input(input):
|
def validate_input(input):
|
||||||
return Validation(True,"Validation Not Implemented")
|
return Validation(True, "Validation Not Implemented")
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
print self.input
|
print self.input
|
||||||
|
@ -143,6 +143,7 @@ class Task:
|
||||||
def show_options_gui(self, editable=False):
|
def show_options_gui(self, editable=False):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Validation:
|
class Validation:
|
||||||
def __init__(self,result, reason):
|
def __init__(self,result, reason):
|
||||||
self.succeeded = result
|
self.succeeded = result
|
||||||
|
@ -168,12 +169,11 @@ class WorkflowView (gtk.VBox):
|
||||||
btn_box.show()
|
btn_box.show()
|
||||||
exp.add(btn_align)
|
exp.add(btn_align)
|
||||||
|
|
||||||
# Add functions in each stage
|
# Add tasks in each stage
|
||||||
for fun in stage.functions:
|
for task in stage.tasks:
|
||||||
btn = gtk.Button(fun.name)
|
btn = gtk.Button(task.name)
|
||||||
btn.connect('clicked',
|
btn.connect('clicked',
|
||||||
lambda button, f=fun : self.run_function(f))
|
lambda button, t=task : self.run_task(t))
|
||||||
|
|
||||||
btn_box.add(btn)
|
btn_box.add(btn)
|
||||||
btn.show()
|
btn.show()
|
||||||
|
|
||||||
|
@ -190,53 +190,27 @@ class WorkflowView (gtk.VBox):
|
||||||
self.remove_workflow()
|
self.remove_workflow()
|
||||||
self.setup_workflow(workflow)
|
self.setup_workflow(workflow)
|
||||||
|
|
||||||
def run_function(self, function):
|
def run_task(self, task):
|
||||||
logger.log('debug', 'Starting function: %s' % function.name)
|
logger.log('debug', 'Creating task: %s' % task.name)
|
||||||
parent_data = main.project.current_data
|
parent_data = main.project.current_data
|
||||||
|
task_instance = task(input=["hei"])
|
||||||
|
print task_instance.input
|
||||||
|
1/0
|
||||||
|
#validation = task.validate_input()
|
||||||
|
|
||||||
validation = function.validate_input()
|
#if not validation.succeeded:
|
||||||
|
# logger.log('warning','Invalid Inputdata: ' + str(reason))
|
||||||
|
# return
|
||||||
|
|
||||||
if not validation.succeeded:
|
#task_result = task.run(*parent_data)
|
||||||
logger.log('warning','Invalid Inputdata: ' + str(reason))
|
|
||||||
return
|
|
||||||
|
|
||||||
args, varargs, varkw, defaults = inspect.getargspec(function.run)
|
|
||||||
|
|
||||||
# first argument is 'self' and second should be the selection
|
#if new_data != None:
|
||||||
# and we don't care about those...
|
# main.project.add_data(parent_data, task_result, task.name)
|
||||||
args.remove('self')
|
#else:
|
||||||
if "selection" in args:
|
# logger.log('debug', 'Task gave no output: %s' % task.name)
|
||||||
pass_selection = True
|
|
||||||
args.remove('selection')
|
|
||||||
else:
|
|
||||||
pass_selection = False
|
|
||||||
|
|
||||||
if varargs and len(parent_data) < len(args):
|
logger.log('debug', 'Task ended: %s' % task.name)
|
||||||
logger.log('warning', "Function requires minimum %d datasets selected." % len(args))
|
|
||||||
return
|
|
||||||
elif not varargs and args and len(args) != len(parent_data):
|
|
||||||
# functions requiring datasets have to have the right number
|
|
||||||
logger.log('warning', "Function requires %d datasets, but only %d selected." % (len(args), len(parent_data)))
|
|
||||||
return
|
|
||||||
|
|
||||||
if not args:
|
|
||||||
# we allow functions requiring no data to be run even if a
|
|
||||||
# dataset is is selected
|
|
||||||
data = []
|
|
||||||
else:
|
|
||||||
data = parent_data
|
|
||||||
|
|
||||||
if pass_selection:
|
|
||||||
# if the function has a 'selection' argument, we pass in
|
|
||||||
# the selection
|
|
||||||
new_data = function.run(selection=main.project.get_selection(), *data)
|
|
||||||
else:
|
|
||||||
new_data = function.run(*data)
|
|
||||||
|
|
||||||
if new_data != None:
|
|
||||||
main.project.add_data(parent_data, new_data, function.name)
|
|
||||||
|
|
||||||
logger.log('debug', 'Function ended: %s' % function.name)
|
|
||||||
|
|
||||||
|
|
||||||
class Options(dict):
|
class Options(dict):
|
||||||
|
@ -261,8 +235,8 @@ class Options(dict):
|
||||||
class OptionsDialog(gtk.Dialog):
|
class OptionsDialog(gtk.Dialog):
|
||||||
"""The basic input/output dialog box.
|
"""The basic input/output dialog box.
|
||||||
|
|
||||||
This defines the first page of the function options-gui.
|
This defines the first page of the task options-gui.
|
||||||
Any function that invokes a option-gui will inherit from this class.
|
Any task that invokes a option-gui will inherit from this class.
|
||||||
"""
|
"""
|
||||||
def __init__(self, data, options, input_names=['X','Y']):
|
def __init__(self, data, options, input_names=['X','Y']):
|
||||||
gtk.Dialog.__init__(self, 'Input-Output dialog',
|
gtk.Dialog.__init__(self, 'Input-Output dialog',
|
||||||
|
@ -454,12 +428,12 @@ class WorkflowMenu (gtk.Menu):
|
||||||
stage_menu = gtk.Menu()
|
stage_menu = gtk.Menu()
|
||||||
stage_menu_item.set_submenu(stage_menu)
|
stage_menu_item.set_submenu(stage_menu)
|
||||||
|
|
||||||
for fun in stage.functions:
|
for task in stage.tasks:
|
||||||
stage_menu.append(self._create_function_item(fun))
|
stage_menu.append(self._create_task_item(task))
|
||||||
return stage_menu_item
|
return stage_menu_item
|
||||||
|
|
||||||
def _create_function_item(self, function):
|
def _create_task_item(self, task):
|
||||||
menuitem = gtk.MenuItem(function.name)
|
menuitem = gtk.MenuItem(task.name)
|
||||||
menuitem.show()
|
menuitem.show()
|
||||||
return menuitem
|
return menuitem
|
||||||
|
|
||||||
|
|
|
@ -12,19 +12,19 @@ class TestWorkflow (workflow.Workflow):
|
||||||
ident = 'test'
|
ident = 'test'
|
||||||
description = 'This workflow currently serves as a general testing workflow.'
|
description = 'This workflow currently serves as a general testing workflow.'
|
||||||
|
|
||||||
def __init__(self, app):
|
def __init__(self):
|
||||||
workflow.Workflow.__init__(self, app)
|
workflow.Workflow.__init__(self)
|
||||||
|
|
||||||
load = workflow.Stage('load', 'Test Data')
|
load = workflow.Stage('load', 'Test Data')
|
||||||
load.add_function(TestDataFunction())
|
load.add_task(TestDataTask)
|
||||||
self.add_stage(load)
|
self.add_stage(load)
|
||||||
|
|
||||||
|
|
||||||
class TestDataTask(workflow.Task):
|
class TestDataTask(workflow.Task):
|
||||||
title = "Test data"
|
name = "Test data"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, input):
|
||||||
workflow.Task.__init__(self)
|
workflow.Task.__init__(self, input)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
logger.log('notice', 'Injecting foo test data')
|
logger.log('notice', 'Injecting foo test data')
|
||||||
|
|
Reference in New Issue