ThingWorx Analytics Functionality > Prescriptive Scoring > Parsing Prescriptive Scoring Results
Parsing Prescriptive Scoring Results
Beginning in Analytics Server 9.0, the format in which prescriptive scoring results are returned has been realigned. In this release, when a scoring job is launched via a direct API call, either real time (synchronous) or batch (asynchronous), the results are returned in the same Infotable format. This change creates simpler, more consistent scoring output.
This change to the Infotable format does present an additional complication when parsing scoring results for consumption by subsequent processes. In the Infotable format, table headers are no longer generic to every model. Lever field names appear as column headers and therefore drilling programmatically down the results structure to find scoring values requires the names of the lever fields.
To facilitate the parsing of prescriptive scoring results, the following code snippet can be added to programatically identify the lever field names for subsequent processes:
function findLever(column) { return column.endsWith("_originalValue"); }
var LeverField = Object.keys(prescriptiveScore.rows[0]).find(findLever).slice(0, -14);
Sample Request
The following sample request shows how the findLever code snippet can be used, in context, to help parse prescriptive scoring results.
// Submit the scoring request
var prescriptiveScore = Things["AnalyticsServer_PrescriptiveThing"].RealtimeScore(request);

// Retrieve the lever fields from the prescriptiveScores result
function findLever(column) { return column.endsWith("_originalValue"); }
var LeverField = Object.keys(prescriptiveScore.rows[0]).find(findLever).slice(0, -14);

// Iterates over each scored result, find the original and optimized lever values and scores
for (var x = 0; x < prescriptiveScore.rows.length; x++) {
originalScore = prescriptiveScore.getRow(x)["originalScore"];
optimizedScore = prescriptiveScore.getRow(x)["optimizedScore"];
originalLever = prescriptiveScore.getRow(x)[LeverField + "_originalValue"];
optimalLever = prescriptiveScore.getRow(x)[LeverField + "_optimalValue"];
identifier = prescriptiveScore.getRow(x)["identifier_1"];

var jsonScore = {originalScore:originalScore, optimizedScore:optimizedScore, originalLever:originalLever,optimalLever:optimalLever, identifier:identifier};

// ... run a process to consume the results
}
Was this helpful?