Commit 17f26dc0 authored by Anze Vavpetic's avatar Anze Vavpetic

added `unzip list` and `list average` widgets

parent d777cebc
......@@ -182,3 +182,40 @@ def base_extract_results(input_dict):
output_dict = {}
output_dict['results']=results
return output_dict
def base_unzip_list(input_dict):
'''
Unzips a list of tuples for the given index.
Example inputs:
index = 0
input_list = [(a, 1), (b, 2), (c, 3)]
result: [a, b, c]
or
index = 1
input_list = [(a, 1), (b, 2), (c, 3)]
result: [1, 2, 3]
'''
idx = int(input_dict.get('index', 0))
input_list = input_dict['input_list']
unzipped_list = [el[idx] for el in input_list]
return {'unzipped_list': unzipped_list}
def base_average_list(input_dict):
'''
Computes the average of the given input list.
'''
input_list = input_dict['input_list']
if input_list:
average = sum(input_list)/float(len(input_list))
else:
average = None
return {'average': average}
[
{
"model": "workflows.abstractwidget",
"fields": {
"category": "01ad639d-acb8-45c0-bc5e-bc8739bb4c95",
"treeview_image": "",
"uid": "5e9c83ea-9a53-4f16-bb69-d1bf66140f78",
"windows_queue": false,
"package": "base",
"interaction_view": "",
"has_progress_bar": false,
"image": "",
"description": "Unzips a list of tuples for the given index.\r\n\r\n Example inputs:\r\n\r\n index = 0\r\n input_list = [(a, 1), (b, 2), (c, 3)]\r\n\r\n result: [a, b, c]\r\n\r\n or\r\n\r\n index = 1\r\n input_list = [(a, 1), (b, 2), (c, 3)]\r\n\r\n result: [1, 2, 3]",
"static_image": "",
"action": "base_unzip_list",
"visualization_view": "",
"streaming_visualization_view": "",
"post_interact_action": "",
"wsdl_method": "",
"wsdl": "",
"interactive": false,
"is_streaming": false,
"order": 1,
"name": "Unzip list"
}
},
{
"model": "workflows.abstractinput",
"fields": {
"widget": "5e9c83ea-9a53-4f16-bb69-d1bf66140f78",
"name": "List",
"short_name": "lst",
"default": "",
"description": "Input list",
"required": true,
"multi": false,
"parameter_type": null,
"variable": "input_list",
"parameter": false,
"order": 1,
"uid": "40170147-20b9-4cb1-9c57-5d6b6fbde603"
}
},
{
"model": "workflows.abstractinput",
"fields": {
"widget": "5e9c83ea-9a53-4f16-bb69-d1bf66140f78",
"name": "Index",
"short_name": "idx",
"default": "0",
"description": "Tuple index to unzip",
"required": false,
"multi": false,
"parameter_type": "text",
"variable": "index",
"parameter": true,
"order": 2,
"uid": "e01147cc-2c37-4155-85ce-d1f22a515de8"
}
},
{
"model": "workflows.abstractoutput",
"fields": {
"widget": "5e9c83ea-9a53-4f16-bb69-d1bf66140f78",
"name": "List",
"short_name": "lst",
"description": "Output list",
"variable": "unzipped_list",
"order": 1,
"uid": "af772a1c-6b82-4873-b385-63ab315bb13e"
}
}
]
\ No newline at end of file
[
{
"model": "workflows.abstractwidget",
"fields": {
"category": "01ad639d-acb8-45c0-bc5e-bc8739bb4c95",
"treeview_image": "",
"uid": "d7f6848d-c01b-429a-88ba-c90741096d10",
"windows_queue": false,
"package": "base",
"interaction_view": "",
"has_progress_bar": false,
"image": "",
"description": "Computes the average of the given input list.",
"static_image": "",
"action": "base_average_list",
"visualization_view": "",
"streaming_visualization_view": "",
"post_interact_action": "",
"wsdl_method": "",
"wsdl": "",
"interactive": false,
"is_streaming": false,
"order": 1,
"name": "List average"
}
},
{
"model": "workflows.abstractinput",
"fields": {
"widget": "d7f6848d-c01b-429a-88ba-c90741096d10",
"name": "List",
"short_name": "lst",
"default": "",
"description": "Input list",
"required": true,
"multi": false,
"parameter_type": null,
"variable": "input_list",
"parameter": false,
"order": 1,
"uid": "863c108e-5908-446b-84e9-31478e36dea7"
}
},
{
"model": "workflows.abstractoutput",
"fields": {
"widget": "d7f6848d-c01b-429a-88ba-c90741096d10",
"name": "Average",
"short_name": "avg",
"description": "Average value",
"variable": "average",
"order": 1,
"uid": "4cb1845d-17d9-4f0a-af27-5a64869d9881"
}
}
]
\ 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