Parametric Selection FeatureIn the previous example, all data used in the model was simply passed as constants in the file. The example model DT Loan Strategy Model2.json, demonstrates how to import this same data from an external data file using a parametric selection criteria. A Parametric Selection allows a single record to be selected from an external datasource file as an input. Parametric selection in data-sources is universal, it is critical to decision tables, which expect a single record for their inputs. All supported data types may be used with this feature. Most of the customer and loan data is imported from the two datasources: loan_data and cust_data. The datasources section creates two datasources, cust_data and loan_data. The datasource, cust_data, binds to the customers.txt csv file. This file contains five input parameters, age, maritalStatus, employmentStatus, creditScore and bankrupt. A screenshot of this file is shown below. The loan_data datasource binds to the loans.txt csv file. This file contains three input parameters: type, rate and term.
Inside of the cust_data datasource, we see the connection argument passing the CSV file, connection: "customers.txt" (screenshot above). The selection argument selects the "CustID" column , from the customers.txt file, and replaces "custID = ?" with "custID = cuID"; the parameters argument binds "cuID" to "c1". In addition, indexCols is set to "cust ID" and valueCols are set to 'age', 'maritalStatus', 'employmentStatus', 'creditScore' and 'bankrupt'. This means that cust ID is the index column and 'age', 'maritalStatus', 'employmentStatus', 'creditScore' and 'bankrupt' are the value columns.
Inside of the loan_data datasource, we see the connection argument passing the CSV file, connection: "loans.txt" (screenshot above). The selection argument selects the "loanID" column , from the loans.txt file, and replaces "loanID = ?" with "loanID = loID"; the parameters argument binds "loID" to "l1". In addition, indexCols is set to "loanID" and valueCols are set to 'type', 'rate' and 'term'. This means that loanID is the index column and 'type', 'rate' and 'term' are the value columns. If we wanted to use multiple selection criteria, such as cust ID, maritalStatus and age, we would change the code to the following:
The selection component indicates which column or columns in the database/table are to be queried. There is no limit on the amount of parameters queried using "and" or "or". In this example, the "binding" property allows cuID, marry and yrold parameters to be queried outside of the RASON Model environment (see example below); 'c1’ is the default custID in this example; 's' is the default maritalStatus and '44' is the default 'age'; if a query parameter is used outside of the RASON model environment, this value will be replaced by the query parameter. Parameters may be matched to the selection arguments "by order" or "by name". In the example code above, the parameters are matched to the selection arguments "by order". This means that the order in which the selection arguments are given must match the order of the parameters i.e. the selection argument order in the example above is custID, maritalStatus, age; therefore, parameters must be listed in the same order: cuID, marry and yrold. If matching by name, the order is not relevant. An example of how to match by name is below. selection: "custID=$cuID and maritalStatus=$marry or age=$yrold",
Here, "custID" is matched with "cuID", "maritalStatus" is matched with "marry" and "age" is matched with "yrold" because they have been explicitly matched. Note: A parameter must have a different name from the column name in the table to which it refers. In the example above, we use "cuID" as a parameter to distinguish it from the column name "custID" because "custID" is a column name marked as an index column. Index columns are index set objects used in the model to dimension variables. They cannot be mixed with parameters. The parameter "cuID" is a single value, an element of a table column used to select records. However, "custID" is the set of all possible elements of a column.
To perform a query using custID, maritalStatus and age outside of the RASON model environment, use the query parameter: $.get(https://rason.net/api/decision? custID=c2&maritalStatus=s&age=40 .....
Or in general, $.get(https://rason.net/api/decision?par1=val1&par2=val2.....
The RASON Server will map "custID=?" with "custID = c2", "maritalStatus=?" with "maritalStatus = s" and "age=?" with "age=44" . The remaining data is passed in the data section. The input data custExist is passed as a constant within the RASON model.
It's also possible to match the name defined in the RASON model to the SQL parameter name. In this example, the syntax would be:
Or, with multiple selections…
The remaining data is passed in the data section. The input data custExist is passed as a constant within the RASON model. Input data monthIncome, monthExpenses and loanAmnt are passed within the RASON model as "get" only. This binding property allows write access to the data outside of the model environment using the keyword "get". The decision table results return the recommended loan strategy for customer 1.
|