Icon

02_​Workflow Control - Solution

Session 2 - Workflow Control Learning objective: In this exercise, you will learn how to control execution of workflows with loops and switchesWorkflow description: This workflow introduces key concepts in workflow control structures through several learning objectives:- Repeat a process using a loop.- Automate a process within a loop using flow variables.- Combine outputs from loops.- Conditionally execute workflow branches using IF and Case Switches.- Control active ports in a switch with a flow variable.You will find the instructions to the exercises in the yellow annotations. Activity I: Write data from different cities to separate files using a loop1. Start from the workflow from Activity II of 01_Flow Variable and Component - Exercise you completed earlier. Insert a Group Loop Start nodebefore the Store with Highest Total Sale metanode. Iterate over different city names in the column City.2. Create a path flow variable for the location and the name of the output Excel file. The filename is the name of the city, followed by the executiondate&time.- Make a flow variable connection between the Group Loop Start node to the Date&Time Configuration node.- In the String Manipulation (Variable) node, use the flow variable City as the filename (hint: use the expression join($${SCity}$$,replaceChars($${SExecution_date}$$,":" ,"-" )) ).- In the Create File/Folder Variables node, change the location to the temp folder under the data folder (hint: use a relative path from the workflow, withthe path ../../data/temp )3. Write the records from the store with the highest total sale in the city of the current iteration to an Excel file- Propagate the output table from the Store with Highest Total Sale metanode to an Excel Writer node. It contains the records only from the city of thecurrent iteration.- Make a flow variable connection from the Create File/Folder Variables node to the Excel Writer node. Set the output file path with the path flowvariable output-location.4. Add a Variable Loop End node, with a flow variable connection from Excel Writer node. You can try a step-by-step execution by right-clicking thenode and selecting "Step Loop Execution". Or you can run all iterations by simply executing the Variable Loop End node. Activity IV: Conditional execution of a workflow branch with an IF Switch (optional)1. From the output table of the Excel Reader node, calculate the average age with a GroupBy node. No group column is needed. As for the aggregationmethod, calculate the Mean of the Age column.2. Convert the first row of the resulting aggregation table to flow variables with a Table Row to Variable node. Now the average age is propagated by aflow variable Mean(Age).3. Based on the value of the flow variable Mean(Age), generate a string flow variable with a Rule Engine Variable node.- If Mean(Age) is less than or equal to 30, then output a string "top"- Otherwise, output a string "bottom"- The output string is propagated in a flow variable condition.4. Form another branch of a workflow by connecting the output of the Excel Reader node to an IF Switch node. Make a flow variable connection from theRule Engine Variable node to the IF Switch node. In the IF Switch configuration window, under the Flow Variables tab, set PortChoice to the flowvariable condition.5. To the top output port of the IF Switch node, add a Row Filter node filtering records with Age up to 30.0 years old (hint: set the upper bound to 30.0).6. Add an End IF node, with the top input port connected to the output from the Row Filter node, and the bottom input port connected to the bottomoutput port of the IF Switch node. Activity II: Read multiple Excel files and combine them into a single table with a loop1. Create a list of Excel files and sheets with a Read Excel Sheet Names node. Use the relative path to the temp folder under the data folder, similar toActivity I you completed earlier. Use the File in folder mode.2. Use the resulting table of Excel paths and sheet names in a Table to Variable Loop Start node.3. Add an Excel Reader node and make a flow variable connection from the Table to Variable Loop Start node. Use the flow variable Path to specifythe location of the input file.4. Feed the output table from the Excel Reader node to a Loop End node. After executing all iterations, the tables from all the Excel input files areconcatenated into a single table at the output port of the Loop End node. Activity III: Use a CASE Switch to selectively activate only one of the branches of a workflow1. Start from the workflow from Activity III of 01_Flow Variable and Component - Exercise you completed earlier. Open the Visualization component.2. After the Color Manager node, insert a CASE Switch Start node. Add one table input port and four table output ports. Connect the input port to theoutput of the Color Manager node and connect the four output ports to the four visualization nodes in the in the same order as previously connected tothe Color Manager node.3. Add a Single Selection Widget node with a dropdown menu, with the possible values "Table View", "Scatter Plot", "Bar Chart" and "ParallelCoordinates Plot". Select "Table View" as the default value. Propagate the selection as a flow variable plot_type. Under the Re-execution tab, check Re-execution on widget value change.4. Make a flow variable connection from the Single Selection Widget node to the CASE Switch Start node. In the CASE Switch Start node, for theoption to Select active port, use the flow variable plot_type(index).5. If desired, adjust the composite view layout to accommodate the additional widget, and expand each of the four views to take up a larger area in thecomposite view Customer dataWrite file with execution dateSet execution timeJoin file name with execution datePath flow variableList of Excel filesand sheet namesIterate each rowof the tableReading the Excelfile for this iterationConsolidatingtables fromall iterationsSelect data based on store typeStats per customerCustomer dataCalculatemean ageString flow variablefor port assignmentTop: mean age <= 30Bottom: mean age > 30Filter Age<=30 Excel Reader Excel Writer Store with HighestTotal Sale Date&TimeConfiguration String Manipulation(Variable) Create File/FolderVariables Group Loop Start Variable Loop End Read ExcelSheet Names Table Row ToVariable Loop Start Excel Reader Loop End Store Selection Excel Reader GroupBy Excel Reader GroupBy Table Rowto Variable Rule EngineVariable IF Switch Row Filter End IF Session 2 - Workflow Control Learning objective: In this exercise, you will learn how to control execution of workflows with loops and switchesWorkflow description: This workflow introduces key concepts in workflow control structures through several learning objectives:- Repeat a process using a loop.- Automate a process within a loop using flow variables.- Combine outputs from loops.- Conditionally execute workflow branches using IF and Case Switches.- Control active ports in a switch with a flow variable.You will find the instructions to the exercises in the yellow annotations. Activity I: Write data from different cities to separate files using a loop1. Start from the workflow from Activity II of 01_Flow Variable and Component - Exercise you completed earlier. Insert a Group Loop Start nodebefore the Store with Highest Total Sale metanode. Iterate over different city names in the column City.2. Create a path flow variable for the location and the name of the output Excel file. The filename is the name of the city, followed by the executiondate&time.- Make a flow variable connection between the Group Loop Start node to the Date&Time Configuration node.- In the String Manipulation (Variable) node, use the flow variable City as the filename (hint: use the expression join($${SCity}$$,replaceChars($${SExecution_date}$$,":" ,"-" )) ).- In the Create File/Folder Variables node, change the location to the temp folder under the data folder (hint: use a relative path from the workflow, withthe path ../../data/temp )3. Write the records from the store with the highest total sale in the city of the current iteration to an Excel file- Propagate the output table from the Store with Highest Total Sale metanode to an Excel Writer node. It contains the records only from the city of thecurrent iteration.- Make a flow variable connection from the Create File/Folder Variables node to the Excel Writer node. Set the output file path with the path flowvariable output-location.4. Add a Variable Loop End node, with a flow variable connection from Excel Writer node. You can try a step-by-step execution by right-clicking thenode and selecting "Step Loop Execution". Or you can run all iterations by simply executing the Variable Loop End node. Activity IV: Conditional execution of a workflow branch with an IF Switch (optional)1. From the output table of the Excel Reader node, calculate the average age with a GroupBy node. No group column is needed. As for the aggregationmethod, calculate the Mean of the Age column.2. Convert the first row of the resulting aggregation table to flow variables with a Table Row to Variable node. Now the average age is propagated by aflow variable Mean(Age).3. Based on the value of the flow variable Mean(Age), generate a string flow variable with a Rule Engine Variable node.- If Mean(Age) is less than or equal to 30, then output a string "top"- Otherwise, output a string "bottom"- The output string is propagated in a flow variable condition.4. Form another branch of a workflow by connecting the output of the Excel Reader node to an IF Switch node. Make a flow variable connection from theRule Engine Variable node to the IF Switch node. In the IF Switch configuration window, under the Flow Variables tab, set PortChoice to the flowvariable condition.5. To the top output port of the IF Switch node, add a Row Filter node filtering records with Age up to 30.0 years old (hint: set the upper bound to 30.0).6. Add an End IF node, with the top input port connected to the output from the Row Filter node, and the bottom input port connected to the bottomoutput port of the IF Switch node. Activity II: Read multiple Excel files and combine them into a single table with a loop1. Create a list of Excel files and sheets with a Read Excel Sheet Names node. Use the relative path to the temp folder under the data folder, similar toActivity I you completed earlier. Use the File in folder mode.2. Use the resulting table of Excel paths and sheet names in a Table to Variable Loop Start node.3. Add an Excel Reader node and make a flow variable connection from the Table to Variable Loop Start node. Use the flow variable Path to specifythe location of the input file.4. Feed the output table from the Excel Reader node to a Loop End node. After executing all iterations, the tables from all the Excel input files areconcatenated into a single table at the output port of the Loop End node. Activity III: Use a CASE Switch to selectively activate only one of the branches of a workflow1. Start from the workflow from Activity III of 01_Flow Variable and Component - Exercise you completed earlier. Open the Visualization component.2. After the Color Manager node, insert a CASE Switch Start node. Add one table input port and four table output ports. Connect the input port to theoutput of the Color Manager node and connect the four output ports to the four visualization nodes in the in the same order as previously connected tothe Color Manager node.3. Add a Single Selection Widget node with a dropdown menu, with the possible values "Table View", "Scatter Plot", "Bar Chart" and "ParallelCoordinates Plot". Select "Table View" as the default value. Propagate the selection as a flow variable plot_type. Under the Re-execution tab, check Re-execution on widget value change.4. Make a flow variable connection from the Single Selection Widget node to the CASE Switch Start node. In the CASE Switch Start node, for theoption to Select active port, use the flow variable plot_type(index).5. If desired, adjust the composite view layout to accommodate the additional widget, and expand each of the four views to take up a larger area in thecomposite view Customer dataWrite file with execution dateSet execution timeJoin file name with execution datePath flow variableList of Excel filesand sheet namesIterate each rowof the tableReading the Excelfile for this iterationConsolidatingtables fromall iterationsSelect data based on store typeStats per customerCustomer dataCalculatemean ageString flow variablefor port assignmentTop: mean age <= 30Bottom: mean age > 30Filter Age<=30 Excel Reader Excel Writer Store with HighestTotal Sale Date&TimeConfiguration String Manipulation(Variable) Create File/FolderVariables Group Loop Start Variable Loop End Read ExcelSheet Names Table Row ToVariable Loop Start Excel Reader Loop End Store Selection Excel Reader GroupBy Excel Reader GroupBy Table Rowto Variable Rule EngineVariable IF Switch Row Filter End IF

Nodes

Extensions

Links