cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

8.3.3 - Using PredictionThing to perform real time scoring from a Service (not a REST call)

SajidPatel
8-Gravel

8.3.3 - Using PredictionThing to perform real time scoring from a Service (not a REST call)

Has anyone been able to do a real time scoring in 8.3 by calling 'RealtimeScore' service of 'AnalyticsServer_PredictionThing' Thing? I want to be able to send data constructed as an infotable. 

 

I have a published Analytics Model. I tried the following code without much luck:

 

var adsmf = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({
infoTableName : "InfoTable", dataShapeName : "AnalyticsDatasetMetadataFlattened" }); var dataShape = DataShapes["AnalyticsServerConnector.pa_temp_pa_lft_temp_705999f9-e266-4771-91b2-b8d38bf1ca9f.InputParamsDataShape"].GetFieldDefinitions(); var tableLength = dataShape.rows.length; for (var x=0; x < tableLength; x++) { var row = dataShape.rows[x]; if (row.name.startsWith('_')) { fieldName = newEntry.item.substring(1, newEntry.item.length); var adsmfEntry = new Object(); adsmfEntry.timeSamplingInterval = undefined; // INTEGER adsmfEntry.isStatic = undefined; // BOOLEAN adsmfEntry.fieldName = fieldName; // STRING adsmfEntry.min = row.min; // NUMBER adsmfEntry.max = row.max; // NUMBER adsmfEntry.dataType = row.dataType; // STRING adsmfEntry.opType = row.opType; // STRING } } var dsRef = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({ infoTableName : "InfoTable", dataShapeName : "AnalyticsDatasetRef" });
// Tried different way to set values without any luck - any clues would be helpful
dsRefEntry = new Object(); dsRefEntry.datasetUri = 'body:/'; // STRING dsRefEntry.metadata = adsmf; // INFOTABLE //dsRefEntry.data = values; // INFOTABLE dsRefEntry.format = 'csv'; // STRING dsRef.AddRow(dsRefEntry); var result = Things["PTC02PWIL-AnalyticsServer_PredictionThing"].RealtimeScore({ goalField: 'MY_GOAL' /* STRING */, modelUri: 'http://localhost:8080/Thingworx/FileRepositories/TW.AnalysisServices.ModelRepository/AnalyticsServerConnector/pa_temp_pa_lft_temp_705999f9-e266-4771-91b2-b8d38bf1ca9f.xml', identifierFields: idFields, datasetRef: dsRef });
1 ACCEPTED SOLUTION

Accepted Solutions
cmorfin
19-Tanzanite
(To:SajidPatel)

Hi @SajidPatel 

 

We have a couple of post that do use , among other things, the RealTimeScore service of PredictionThing.

They come with the entities that you can import and review the code.

 

Analytics: Prediction Methods Mashup

How to work with ordinal and categorical data in ThingWorx Analytics 

 

Also in your code the modelURI has a wrong format, it should be of type results://models/<jobID>

Similarly you will be able to see this in the above posts.

 

Finally be mindful of https://www.ptc.com/en/support/article?n=CS298126 if passing scoring data inline using a body type, it will only work with small amount of data.

 

How this helps

Kind regards

Christophe

 

View solution in original post

2 REPLIES 2
cmorfin
19-Tanzanite
(To:SajidPatel)

Hi @SajidPatel 

 

We have a couple of post that do use , among other things, the RealTimeScore service of PredictionThing.

They come with the entities that you can import and review the code.

 

Analytics: Prediction Methods Mashup

How to work with ordinal and categorical data in ThingWorx Analytics 

 

Also in your code the modelURI has a wrong format, it should be of type results://models/<jobID>

Similarly you will be able to see this in the above posts.

 

Finally be mindful of https://www.ptc.com/en/support/article?n=CS298126 if passing scoring data inline using a body type, it will only work with small amount of data.

 

How this helps

Kind regards

Christophe

 

@cmorfin Thanks, this is exactly what I was looking for. I am scoring just one row of data on need basis.

Top Tags