initial working test wf
This commit is contained in:
parent
bfb039328c
commit
2fdd9aaf77
|
@ -85,45 +85,45 @@ class Workflow:
|
|||
print self.name
|
||||
for stage in self.stages:
|
||||
print ' %s' % stage.name
|
||||
for fun in stage.functions:
|
||||
print ' %s' % fun.name
|
||||
for task in stage.tasks:
|
||||
print ' %s' % task.name
|
||||
|
||||
|
||||
class EmptyWorkflow(Workflow):
|
||||
name = 'Empty Workflow'
|
||||
|
||||
def __init__(self):
|
||||
print "initing empty workflow"
|
||||
logger.log("debug", "initing empty workflow")
|
||||
Workflow.__init__(self)
|
||||
|
||||
|
||||
class Stage:
|
||||
"""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
|
||||
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):
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.functions = []
|
||||
self.functions_by_id = {}
|
||||
self.tasks = []
|
||||
self.tasks_by_id = {}
|
||||
|
||||
def add_function(self, fun):
|
||||
self.functions.append(fun)
|
||||
self.functions_by_id[fun.id] = fun
|
||||
def add_task(self, task):
|
||||
self.tasks.append(task)
|
||||
#self.tasks_by_id[task.id] = 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.
|
||||
"""
|
||||
|
||||
title = ""
|
||||
name = ""
|
||||
|
||||
def __init__(self, input):
|
||||
self.input = input
|
||||
|
@ -143,6 +143,7 @@ class Task:
|
|||
def show_options_gui(self, editable=False):
|
||||
pass
|
||||
|
||||
|
||||
class Validation:
|
||||
def __init__(self,result, reason):
|
||||
self.succeeded = result
|
||||
|
@ -168,12 +169,11 @@ class WorkflowView (gtk.VBox):
|
|||
btn_box.show()
|
||||
exp.add(btn_align)
|
||||
|
||||
# Add functions in each stage
|
||||
for fun in stage.functions:
|
||||
btn = gtk.Button(fun.name)
|
||||
# Add tasks in each stage
|
||||
for task in stage.tasks:
|
||||
btn = gtk.Button(task.name)
|
||||
btn.connect('clicked',
|
||||
lambda button, f=fun : self.run_function(f))
|
||||
|
||||
lambda button, t=task : self.run_task(t))
|
||||
btn_box.add(btn)
|
||||
btn.show()
|
||||
|
||||
|
@ -190,53 +190,27 @@ class WorkflowView (gtk.VBox):
|
|||
self.remove_workflow()
|
||||
self.setup_workflow(workflow)
|
||||
|
||||
def run_function(self, function):
|
||||
logger.log('debug', 'Starting function: %s' % function.name)
|
||||
def run_task(self, task):
|
||||
logger.log('debug', 'Creating task: %s' % task.name)
|
||||
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:
|
||||
logger.log('warning','Invalid Inputdata: ' + str(reason))
|
||||
return
|
||||
#task_result = task.run(*parent_data)
|
||||
|
||||
args, varargs, varkw, defaults = inspect.getargspec(function.run)
|
||||
|
||||
# first argument is 'self' and second should be the selection
|
||||
# and we don't care about those...
|
||||
args.remove('self')
|
||||
if "selection" in args:
|
||||
pass_selection = True
|
||||
args.remove('selection')
|
||||
else:
|
||||
pass_selection = False
|
||||
#if new_data != None:
|
||||
# main.project.add_data(parent_data, task_result, task.name)
|
||||
#else:
|
||||
# logger.log('debug', 'Task gave no output: %s' % task.name)
|
||||
|
||||
if varargs and len(parent_data) < len(args):
|
||||
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)
|
||||
logger.log('debug', 'Task ended: %s' % task.name)
|
||||
|
||||
|
||||
class Options(dict):
|
||||
|
@ -261,8 +235,8 @@ class Options(dict):
|
|||
class OptionsDialog(gtk.Dialog):
|
||||
"""The basic input/output dialog box.
|
||||
|
||||
This defines the first page of the function options-gui.
|
||||
Any function that invokes a option-gui will inherit from this class.
|
||||
This defines the first page of the task options-gui.
|
||||
Any task that invokes a option-gui will inherit from this class.
|
||||
"""
|
||||
def __init__(self, data, options, input_names=['X','Y']):
|
||||
gtk.Dialog.__init__(self, 'Input-Output dialog',
|
||||
|
@ -454,12 +428,12 @@ class WorkflowMenu (gtk.Menu):
|
|||
stage_menu = gtk.Menu()
|
||||
stage_menu_item.set_submenu(stage_menu)
|
||||
|
||||
for fun in stage.functions:
|
||||
stage_menu.append(self._create_function_item(fun))
|
||||
for task in stage.tasks:
|
||||
stage_menu.append(self._create_task_item(task))
|
||||
return stage_menu_item
|
||||
|
||||
def _create_function_item(self, function):
|
||||
menuitem = gtk.MenuItem(function.name)
|
||||
def _create_task_item(self, task):
|
||||
menuitem = gtk.MenuItem(task.name)
|
||||
menuitem.show()
|
||||
return menuitem
|
||||
|
||||
|
|
|
@ -12,19 +12,19 @@ class TestWorkflow (workflow.Workflow):
|
|||
ident = 'test'
|
||||
description = 'This workflow currently serves as a general testing workflow.'
|
||||
|
||||
def __init__(self, app):
|
||||
workflow.Workflow.__init__(self, app)
|
||||
def __init__(self):
|
||||
workflow.Workflow.__init__(self)
|
||||
|
||||
load = workflow.Stage('load', 'Test Data')
|
||||
load.add_function(TestDataFunction())
|
||||
load.add_task(TestDataTask)
|
||||
self.add_stage(load)
|
||||
|
||||
|
||||
class TestDataTask(workflow.Task):
|
||||
title = "Test data"
|
||||
name = "Test data"
|
||||
|
||||
def __init__(self):
|
||||
workflow.Task.__init__(self)
|
||||
def __init__(self, input):
|
||||
workflow.Task.__init__(self, input)
|
||||
|
||||
def run(self):
|
||||
logger.log('notice', 'Injecting foo test data')
|
||||
|
|
Reference in New Issue