From f8595bab3118563c2ca9ed4cb3d8b8c3b20f2096 Mon Sep 17 00:00:00 2001 From: Anika Bettge Date: Wed, 15 Apr 2020 12:41:42 +0200 Subject: [PATCH 1/2] add parameters --- actinia_gdi/core/gmodulesActinia.py | 23 +++++++++++++++++------ actinia_gdi/core/gmodulesParser.py | 1 + 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/actinia_gdi/core/gmodulesActinia.py b/actinia_gdi/core/gmodulesActinia.py index ec7d7ba..b46fec1 100644 --- a/actinia_gdi/core/gmodulesActinia.py +++ b/actinia_gdi/core/gmodulesActinia.py @@ -174,17 +174,27 @@ def createActiniaModule(self, processchain): if '{{ ' in val and ' }}' in val and val not in aggregated_vals: aggregated_vals.append(val) run_interface_descr = True - input_dict[processid]["gparams"][key] = {} # matches placeholder in longer value, e.g. in # 'res = if(input <= {{ my_values }}, 1, null() )' # beware that in general it is easier to make the whole value # a placeholder. Might be not possible for e.g. r.mapcalc - placeholder = re.search(r"\{\{(.*?)\}\}", str(val)).groups()[0] - amkey = placeholder.strip(' ') - input_dict[processid]["gparams"][key]['amkey'] = amkey - if 'comment' in j: - input_dict[processid]["gparams"][key]['comment'] = j['comment'] + placeholders = re.findall(r"\{\{(.*?)\}\}", str(val)) + + if len(placeholders) == 1: + input_dict[processid]["gparams"][key] = {} + amkey = placeholders[0].strip(' ') + input_dict[processid]["gparams"][key]['amkey'] = amkey + if 'comment' in j: + input_dict[processid]["gparams"][key]['comment'] = j['comment'] + else: + for placeholder in placeholders: + amkey = placeholder.strip(' ') + newkey = "%s_%s" % (key, amkey) + input_dict[processid]["gparams"][newkey] = {} + input_dict[processid]["gparams"][newkey]['amkey'] = amkey + if 'comment' in j: + input_dict[processid]["gparams"][newkey]['comment'] = j['comment'] if 'import_descr' in j: for key, val in j['import_descr'].items(): @@ -223,6 +233,7 @@ def createActiniaModule(self, processchain): xml_string, keys=aggregated_keys.keys() ) + import pdb; pdb.set_trace() if 'parameters' in grass_module: for param in grass_module['parameters']: diff --git a/actinia_gdi/core/gmodulesParser.py b/actinia_gdi/core/gmodulesParser.py index 3b7e46f..21019db 100644 --- a/actinia_gdi/core/gmodulesParser.py +++ b/actinia_gdi/core/gmodulesParser.py @@ -198,6 +198,7 @@ def ParseInterfaceDescription(xml_string, keys=None): if keys: # case for actinia modules key = setVirtualParameterKey(module_id, parameter) + import pdb;pdb.set_trace() if key not in keys: continue else: From 794403cc111462083c4034f3ee19986699865249 Mon Sep 17 00:00:00 2001 From: Anika Bettge Date: Wed, 15 Apr 2020 16:26:23 +0200 Subject: [PATCH 2/2] each varaible as own parameter and comment added --- actinia_gdi/core/gmodulesActinia.py | 23 +++++++++++-------- actinia_gdi/core/gmodulesParser.py | 8 ++++++- .../templates/pc_templates/default_value.json | 1 + 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/actinia_gdi/core/gmodulesActinia.py b/actinia_gdi/core/gmodulesActinia.py index 8fd4f9f..86aee8f 100644 --- a/actinia_gdi/core/gmodulesActinia.py +++ b/actinia_gdi/core/gmodulesActinia.py @@ -110,12 +110,17 @@ def add_param_description(moduleparameter, param, input_dict): # update description and mention grass module parameter suffix = " [generated from " + param + "]" moduleparameter['description'] += suffix - # add comment if there is one in process chain template + # add comment if there is one in process chain template + if not param in input_dict: + for input_dict_key in input_dict: + if param in input_dict_key: + param = input_dict_key if param in input_dict and 'comment' in input_dict[param]: comment = input_dict[param]['comment'] - moduleparameter['description'] += " - " + comment - # moduleparameter['comment'] = comment + if comment not in moduleparameter['description']: + moduleparameter['description'] += " - " + comment + # moduleparameter['comment'] = comment def createActiniaModule(self, processchain): @@ -241,16 +246,16 @@ def createActiniaModule(self, processchain): xml_string, keys=aggregated_keys.keys() ) - import pdb; pdb.set_trace() if 'parameters' in grass_module: for param in grass_module['parameters']: - if param in aggregated_keys.keys(): - amkey = aggregated_keys[param]['amkey'] - virtual_module_params[amkey] = grass_module['parameters'][param] + for aggregated_key in aggregated_keys: + if param in aggregated_key: + amkey = aggregated_keys[aggregated_key]['amkey'] + virtual_module_params[amkey] = grass_module['parameters'][param] - add_param_description( - virtual_module_params[amkey], param, aggregated_keys) + add_param_description( + virtual_module_params[amkey], param, aggregated_keys) if 'returns' in grass_module: for param in grass_module['returns']: diff --git a/actinia_gdi/core/gmodulesParser.py b/actinia_gdi/core/gmodulesParser.py index 21019db..41000b0 100644 --- a/actinia_gdi/core/gmodulesParser.py +++ b/actinia_gdi/core/gmodulesParser.py @@ -198,8 +198,14 @@ def ParseInterfaceDescription(xml_string, keys=None): if keys: # case for actinia modules key = setVirtualParameterKey(module_id, parameter) - import pdb;pdb.set_trace() + key_exists = False if key not in keys: + for actiniakey in keys: + if actiniakey.startswith(key): + key_exists = True + else: + key_exists = True + if not key_exists: continue else: # case for GRASS modules diff --git a/actinia_gdi/templates/pc_templates/default_value.json b/actinia_gdi/templates/pc_templates/default_value.json index 9d51ac0..730633e 100644 --- a/actinia_gdi/templates/pc_templates/default_value.json +++ b/actinia_gdi/templates/pc_templates/default_value.json @@ -10,6 +10,7 @@ "inputs": [ { "param": "expression", + "comment": "output = r.mapcalc result, string; value = raster value (default=0.428), float", "value": "{{ output }} = {{ value|default(0.428) }}" } ]