Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
tutorial:scripting_comb_data_model [2020/07/18 02:27]
admin [Model scripting]
tutorial:scripting_comb_data_model [2020/07/18 22:28]
admin [Exporting results]
Line 2: Line 2:
  
 Learning Objectives: Learning Objectives:
-  * Model scripting +  * [[#Model scripting]] 
-  * Activating plugins +  * [[#Looping DataTable]] 
-  * Looping through DataTable +  * [[#Activating plugins]] 
-  * Persisting and exporting results+  * [[#Exporting results]] 
 +  * [[#Remote Execution]] 
 + 
 +This tutorial assumes that you are familiar with how to create a Combinatorial Data Model and have created a simple model with at least 2 variables named Field1 and Field2 and have generated the DataTable.  Please refer to [[comb_data_modeling | Combinatorial Data Modeling]] if you need assistance in creating the model. 
  
 ===== Model scripting ===== ===== Model scripting =====
Line 14: Line 18:
 Unlike [[scripting_state_model | scripting for State Model]], you just write your script right in [[../data_design_ide#script | SCRIPT]] tab. In your script you would just loop through the rows in DataTable.  Below is an example of script: Unlike [[scripting_state_model | scripting for State Model]], you just write your script right in [[../data_design_ide#script | SCRIPT]] tab. In your script you would just loop through the rows in DataTable.  Below is an example of script:
  
-   rowIdx = 0;+   $DATASET.notifyClient('Total number of rows in DataTable: ' + $DATASET.getDataRows().size()); 
 + 
 +Run the model, you should see following returned and displayed on [[../data_design_ide#execute | IDE Execute]] tab: 
 + 
 +   Total number of rows in DataTable: 10 
 + 
 + 
 +===== Looping DataTable ===== 
 +To perform the testing on all rows in DataTable, you must loop through each row in DataTable ($DATASET.getDataRows()). You can do this with //for// loop:
    for (Map<String,String> row: $DATASET.getDataRows()) {    for (Map<String,String> row: $DATASET.getDataRows()) {
-      rowIdx+++      $DATASET.notifyClient(row); 
-      if (rowIdx%2 == 0) {+   } 
 + 
 + 
 + 
 +===== Activating Plugins ===== 
 +Just like [[scripting_state_model | scripting for State Model]], you need to activate plugins to interact with AUT to perform the testing on each row in the DataTable. 
 + 
 +For this tutorial, activate //Random// plugin, and modify the script to use //$RANDOM.randNum(...)// to determine the failure/success as below: 
 + 
 +   for (Map<String,String> row: $DATASET.getDataRows()) { 
 +      if ($RANDOM.randNum(0,10) > 5) {
          row._result = "Successful run on " + row.Field1 + ", " + row.Field2;          row._result = "Successful run on " + row.Field1 + ", " + row.Field2;
          row._status = true;          row._status = true;
Line 23: Line 45:
       else {       else {
          row._result = "Failed run on " + row.Field1 + ", " + row.Field2;          row._result = "Failed run on " + row.Field1 + ", " + row.Field2;
-         row._status = false;  +         row._status = false;
       }       }
       $DATASET.notifyClient(row);       $DATASET.notifyClient(row);
    }    }
 +   
 +Make changes to your script to incorporate the plugin function calls and re-run the model.   
 +
 +===== Exporting results =====
 +When running the model in IDE, you can export/download the execution results in [[../data_design_ide#execute | IDE Execute]] tab. 
 +
 +After model execution completes, you can export the results by menu //File / Export// or {{wiki:overview:tut_comb_btn_export.png?20}}.
 +
 +Try the export and review the result file downloaded.
 +
 +If you are running model remotely using [[../integration#rest_apis | REST api]], you may specify the file location to save the execution results, see next section for details.
 +
 +
 +===== Remote Execution =====
 +You may run your data model remotely using REST api:
  
 +   curl -X POST "http://localhost:8888/api/v1/runtime/dataset/run/sync" -H  "accept: application/json" -H  "Content-Type: application/json" -d " \"modelName\": \"MyDataModel_A\",  \"options\": {\"path\": \"Folder_B\", \"outputFile\": \"myOutputFile.txt\"}}"
  
 +The output is written to "outputFile" in //work// folder.