Custom data provider for tests and simulations details

You run the sample in the Decision Center Business console.

Running the sample

In this sample, you do the following tasks:

  • You define and run a test suite that uses an Excel scenario data file.
  • You define and run a test suite that uses a custom data provider.
  • You run a predefined simulation.
  • You define and run a simulation that uses a custom data provider.

For more information about custom data providers, see Setting up custom data providers.

To open the sample:
  1. Do one of the following actions to open the Business console:
    • In Windows, go to Start > All Programs > IBM Operational Decision Manager V8.9 > Sample server, and click Decision Center Business console.
    • Enter the following URL in your browser: http://localhost:<PORT>/decisioncenter
  2. Log in to the console:
    • User name: Paul
    • Password: Paul
  3. Click Library, and click the Loan Validation Service box anywhere except the name.
  4. Click main to open the main branch.
To define and run a test suite that uses an Excel scenario data file:
  1. Click Tests to open the tab, and then Test Suites to open the subtab.
  2. Click the Add button "" to create a new test suite.
  3. Select loan validation with score and grade for the operation, and click OK.
  4. Change the name of the test suite to ExcelTest.
  5. For the file to use, click Choose and browse to <InstallDir>/teamserver/tutorials/assessment.xlsx.
  6. Click Save and Run. In the windows that opens, click Create New Version , and then OK to run the test suite.
  7. On the Reports subtab, open the test report when its status shows a green check mark. It shows that two tests ran successfully.
  8. Close the report.
To create a custom test provider:
  1. Click Test Suites to open the subtab.
  2. Click the Generate Scenario File button "".
  3. Change the scenario file format to Test Data Provider. A section opens to define the tests.
  4. Expand loan report and select approved. Keep the operator as equals.
  5. Give Approved as the identifier, and enter Approved is as the name.
    Note: When you define a test, you provide a name that is used in the test report to display the results, and an ID that is used in the provider code to identify the test.
  6. Select messages, and select contains as the operator. Note that the operator varies according to the type of the selected value.
  7. Give MessagesContain as the identifier, and Messages list contains as the name.
  8. In Expected execution details, select number of rules fired, and equals as the operator. Note that you can select numeric comparison in the list of operators.
  9. Give RulesFiredCount as the identifier, and Count of fired rules as the name.
  10. Click main in the breadcrumbs to return to the Test Suites tab. You do not have to save this description because the sample uses predefined descriptions.
To define and run a test suite that uses a custom data provider:
  1. On the Test Suites tab, and click the Add button "" to create a new test suite.
  2. Change the name of the test suite to CsvTest.
  3. For the file to use, click Choose and browse to <InstallDir>/teamserver/samples/simulationcustomdatasource/simulationdatasource/data/Loan Csv Test Data Provider.tstx.

    The file format changes to Test Data Provider, which is the custom provider that is defined by the selected file. Keep testdataprovider as the name of the data set.

  4. Click Save and Run. In the windows that opens, click Create New Version , and then OK to run the test suite.
  5. On the Reports subtab, open the test report when its status shows a green check mark. It shows that eight tests ran successfully.
  6. In the Results part of the report, open the first test, Low risk approved. It shows the values that were tested. Open the Details link to see the message list. It shows the messages that were returned from running the ruleset.
  7. Close the report.
You can create another test by using the following data file, which randomly generates data and values to check: <InstallDir>/teamserver/samples/simulationcustomdatasource/simulationdatasource/data/Loan Random Test Provider.tstx
To run a predefined simulation:
  1. Click Simulations to open the tab, and then open the Simulations subtab by clicking its name.
  2. Hover over File Simulation, and click the Run button "".
  3. Click OK in the Starting simulations window.

    The Reports tab opens and shows the progress of the simulation. When the simulation finishes, its status changes to green.

  4. Click File Simulation Report to open the report.
  5. Close the report.
To define a simulation that uses a custom data provider:
  1. Open the Data subtab in the Simulations tab.
  2. Click the Add button "" to upload data.
  3. Enter Basic Provider as the name.
  4. Select loan validation with score and grade as the operation.
  5. Browse to <InstallDir>/teamserver/samples/simulationcustomdatasource/simulationdatasource/data/Loan Data Provider (Basic).simx. The file uses queries to gather data for the simulation.
  6. Click Create.
  7. Open the Simulations subtab.
  8. Click the Add button "" to create a new simulation configuration.
  9. Enter Generated Simulation as the name.
  10. Set Server to Simulation, and Report format to Loan Report Template.
  11. Change the title of the simulation report to Generated Simulation.
  12. Set the input data to Basic Provider.
  13. Click Save, and then click Create New Version.
To run the new simulation:
  1. In the Simulations subtab, hover over the Generated Simulation configuration, and click the Run button "" to start the simulation.
  2. Click OK in the Starting simulations window.

    The Report subtab opens to show the progress of the simulation. When the simulation finishes, its status changes to green.

  3. Click the report Generated Simulation. It shows that 100 scenarios were run.
You can create two more simulations by using the following data files in <InstallDir>/teamserver/samples/simulationcustomdatasource/simulationdatasource/data:
  • Loan Data Provider (Min-Max-Year Params).simx: Provides more parameters.
  • Loan Data Provider (Multi Thread).simx: Uses multiple threads.

Rebuilding the sample

To rebuild this sample:
  1. Open the Samples Commands tab in the samples console.
  2. Go to Samples Commands > Decision Center > Custom data provider for tests and simulations.
  3. Double-click clean.
  4. Double-click deploy.

    Rule Designer builds the custom JAR files and deploys them to Rule Execution Server.

How the sample works

The Loan Validation Service decision service is ready to use in the samples server. It includes predefined metrics, KPIs, data, and a simulation. It is also deployed to Rule Execution Server so that the simulation is ready to run.

The source code for the custom data provider is deployed to Rule Execution Server when you use the deploy command of the sample. You can see the resource by opening the Rule Execution Server console with the login and password resAdmin. On the Explorer tab, check that Resources contains simulationSample.zip.

Open the provider description in InstallDir/teamserver/samples/simulationcustomdatasource/simulationdatasource/data/Loan Data Provider (Basic).simx. You see that it requires <uri>resuri://simulationSample.zip/1.0</uri>.

You define the Csv test custom provider in <InstallDir>/teamserver/samples/simulationcustomdatasource/simulationdatasource/data/Loan Csv Test Data Provider.tstx. The file contains the following information:

  • The URI to access the provider classes: <uri>resuri://simulationSample.zip/1.0</uri>
  • A dataset.name parameter that uses Dataset as the display name, and testdataprovider as the default value.
  • The reader class set to simulation.TestSuiteCsvReader.
  • The predicate list that defines the tests. The tests were generated in the Business console. The reader code uses the ID to identify the tests.
Note: For simplicity, the same compressed file contains the CSV data file and the custom provider classes.

The following sections show the predefined artifacts in the simulation.

Metrics
The metrics are listed on the Metrics tab. They can be divided into three categories:
  1. Metrics that produce a value for all loan requests.
  2. Metrics that produce a value only when the loan score and its associated grade are computed, so only for loans that pass the validation phase.
  3. Metrics that produce a value only for approved loans, so only for loans with an acceptable grade.
Table 1. Metrics for the sample
Metric Type Expression
Loan amount NUMERIC the amount of the loan
Granted loan amount NUMERIC the amount of the loan when the loan report is approved
DTI NUMERIC the yearly repayment of the loan or the yearly income of the borrower when the yearly repayment of the loan is more than 0
Insurance rate NUMERIC the insurance rate of the loan when the insurance rate of the loan is more than 0
Interest rate NUMERIC the yearly interest rate of the loan when the loan is approved
Loan grade STRING the loan grade in the loan report
Granted loan - overall BOOLEAN the loan report is approved
Granted loan - with scoring BOOLEAN the loan report is approved when the loan grade in report is not null
Scored loan BOOLEAN the loan grade in the loan report is not null
Required insurance BOOLEAN the loan report is insurance required when the loan report is approved
Loan submission date DATE the start date of the loan
KPIs
The KPIs are listed on the KPIs tab.
Table 2. KPIs for the sample
Metric Expression
Minimum granted loan amount minimum 'Granted loan amount'
Maximum granted loan amount maximum 'Granted loan amount'
Average granted loan amount average 'Granted loan amount'
Ratio of scored loans ratio of 'Scored loan'
Ratio of granted loans - overall ratio of 'Granted loan - overall'
Ratio of granted loans - with scoring ratio of 'Granted loan – with scoring'
Ratio of granted loans by amount ratio of 'Granted loan - with scoring' grouped by 'Loan amount' with a 100000 interval
Scored loans by grade number of 'Scored loan' grouped by 'Loan grade'
Average granted loan amount by submission year average 'Granted loan amount' grouped by 'Loan submission date' with a year interval
Min DTI minimum 'DTI'
Max DTI maximum 'DTI'
Average DTI average 'DTI'
Average DTI by loan amount average 'DTI' grouped by 'Loan amount' with a 100000 interval
Average Insurance rate average 'Insurance rate'
Average Interest rate average 'Interest rate'
Ratio of required insurance ratio of 'Required insurance'
Data
This sample uses the following files, which you can find in this directory <InstallDir>/teamserver/samples/simulationcustomdatasource/
Table 3. Data files for the sample
File name Description
simulationdatasource/data/loanvalidation-simulation.xlsx Excel scenario file
/bin/simulationSample.zip The simulationSample.zip file is generated in the bin directory when you build the sample.

The Java™ code that defines a new connector to create scenarios with random data is compiled and deployed to the XOM. You can open the Rule Execution Server console and see the resources.

simulationdatasource/data/Loan Data Provider (Basic).simx

simulationdatasource/data/Loan Data Provider (Min-Max-Year Params).simx

simulationdatasource/data/Loan Data Provider (Multi Thread).simx

XML description files that gather data. The files contain the following elements:
  • The URI reference to the Java code of the connector <uri>resuri://simulationSample.zip/1.0</uri>
  • The parameter definitions as properties. For example: <property name="scenario.count" xsi:type="longProperty" displayName="Scenario Count"><value>10000</value></property>
  • The job descriptor
    • With a reader that specifies the fully qualified name of the reader class <jsl:reader ref="simulation.RandomReader">
    • With a partitioner that specifies the fully qualified name of the partition mapper class to run the simulation with multiple threads <jsl:mapper ref="simulation.SimplePartitionMapper">

Source files

You can find this sample in the directory <InstallDir>/teamserver/samples/simulationcustomdatasource.

The simulation package contains the following files under /src/simulation:
  • RandomReader.java: The reader class that implements the open and readItem methods to initialize the simulation and get the scenarios.
  • RandomInputGenerator.java: The generator class that builds the loans and borrowers for a scenario.
  • SimplePartitionMapper.java: The partition mapper class that implements the mapPartitions method to run the simulation on multiple threads
  • TestSuiteCsvReader.java: The reader class that implements the open and readItem methods to initialize the test suite and get the scenarios that use a CSV-formatted data file.
  • TestSuiteRandomReader.java: The reader class that implements the open and readItem methods to initialize the test suite and get the scenarios that use a random generator.
  • simulationcustomdatasource/simulationdatasource/data: Contains the simulations and test suites description file and the CSV data file.
Note:

The simulation runtime component is built on top of the JSR 352 Java Batch specification. For more information about the job descriptor format, and the item reader and partition mapper, see Java Batch Wiki.