From f444b03b90c7571ad0c4eb382928cdd331edefc1 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Tue, 23 Apr 2019 12:02:44 +0200 Subject: [PATCH] Add a expression tool that creates parameters from input file This tool allows parsing text, integer, float and boolean parameters from a input dataset. This closes #7774 --- config/tool_conf.xml.sample | 3 + .../parse_values_from_file.xml | 106 ++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 tools/expression_tools/parse_values_from_file.xml diff --git a/config/tool_conf.xml.sample b/config/tool_conf.xml.sample index f77edc40d82..aeb42d29f3b 100644 --- a/config/tool_conf.xml.sample +++ b/config/tool_conf.xml.sample @@ -42,6 +42,9 @@ +
+ +
diff --git a/tools/expression_tools/parse_values_from_file.xml b/tools/expression_tools/parse_values_from_file.xml new file mode 100644 index 00000000000..12f52d72451 --- /dev/null +++ b/tools/expression_tools/parse_values_from_file.xml @@ -0,0 +1,106 @@ + + from dataset + { +var output; +if ($job.remove_newlines || $job.param_type != 'string') { + $job.input1.contents = $job.input1.contents.trim(); +} +if ($job.param_type == 'integer') { + output = parseInt($job.input1.contents); +} else if ($job.param_type == 'float') { + output = parseFloat($job.input1.contents); +} else if ($job.param_type == 'boolean') { + const trueValues = ['yes', 'true', '1'] + const falseValues = ['no', 'false', '0'] + let lowerCaseContents = $job.input1.contents.toLowerCase(); + if (trueValues.includes(lowerCaseContents)) { + output = true; + } else if (falseValues.includes(lowerCaseContents)) { + output = false; + } + else { + return 'NOT A BOOLEAN VALUE'; + } +} else { + output = $job.input1.contents; +} +return {'output': output}; + } + + + + + + + + + + + + + param_type == 'string' + + + param_type == 'integer' + + + param_type == 'float' + + + param_type == 'boolean' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +