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

Community email notifications are disrupted. While we are working to resolve, please check on your favorite boards regularly to keep up with your conversations and new topics.

Use PredictionThing to perform real time scoring

skef
11-Garnet

Use PredictionThing to perform real time scoring

Hello,

 

I would like to use the PredictorThing to perform scoring with the RealtimeScore service in order to be able to use this service via the REST API.

 

I want to provide the data input temporally without the need to save a (small) dataset every time. But I don't know excatly how do I have to pass the datasetRef InfoTable correctly, when I want to pass the input parameters as json/in body. In the nested InfoTable of the metadata field, I pass the fieldnames, optype, dataType etc, and in the value fieldname, I pass the data corresponding to the field, beginning with the oldest value. Back in the datasetRef Infotable, I pass "json" as format and "body:/" at dataSetUri.

 

I get the following error message: 

 

 

Could not process request: [Unable to process JSON [refer to logs for more details]]

This is the json body of the request:

 

{
	"modelUri": "results:/models/d081b9f3-fcd2-4f94-b839-07f8961b6d63",
	"datasetRef": {
		"created": 1521639099629,
		"description": "",
		"name": "Infotable",
		"dataShape": {
			"fieldDefinitions": {
				"filter": {
					"name": "filter",
					"aspects": {},
					"description": "SQL WHERE clause to refine the dataset",
					"baseType": "STRING",
					"ordinal": 3
				},
				"datasetUri": {
					"name": "datasetUri",
					"aspects": {},
					"description": "Location of the data",
					"baseType": "STRING",
					"ordinal": 1
				},
				"metadata": {
					"name": "metadata",
					"aspects": {
						"dataShape": "AnalyticsDatasetMetadata"
					},
					"description": "Metadata of the dataset (for providing data as part of request)",
					"baseType": "INFOTABLE",
					"ordinal": 6
				},
				"data": {
					"name": "data",
					"aspects": {},
					"description": "An infotable of data (must be flat. for providing data as part of request)",
					"baseType": "INFOTABLE",
					"ordinal": 5
				},
				"format": {
					"name": "format",
					"aspects": {},
					"description": "Structure of the data (CSV,PARQUET,CLQUET)",
					"baseType": "STRING",
					"ordinal": 2
				},
				"exclusions": {
					"name": "exclusions",
					"aspects": {
						"dataShape": "GenericStringList"
					},
					"description": "Fields to remove from the dataset",
					"baseType": "INFOTABLE",
					"ordinal": 4
				}
			},
			"name": "AnalyticsDatasetRef",
			"description": "Reference to a dataset"
		},
		"rows": [{
				"datasetUri": "body:/",
				"metadata": {
					"created": 1521639557758,
					"description": "",
					"name": "Infotable",
					"dataShape": {
						"fieldDefinitions": {
							"timeSamplingInterval": {
								"name": "timeSamplingInterval",
								"aspects": {},
								"description": "Time between observations in a Temporal field",
								"baseType": "INTEGER",
								"ordinal": 7
							},
							"isStatic": {
								"name": "isStatic",
								"aspects": {
									"defaultValue": false
								},
								"description": "If true, this field remains unchanged over time",
								"baseType": "BOOLEAN",
								"ordinal": 8
							},
							"fieldName": {
								"name": "fieldName",
								"aspects": {},
								"description": "Name of the field",
								"baseType": "STRING",
								"ordinal": 1
							},
							"min": {
								"name": "min",
								"aspects": {},
								"description": "Minimum observed value for Continuous fields",
								"baseType": "NUMBER",
								"ordinal": 4
							},
							"max": {
								"name": "max",
								"aspects": {},
								"description": "Maximum observed value for Continuous fields",
								"baseType": "NUMBER",
								"ordinal": 5
							},
							"dataType": {
								"name": "dataType",
								"aspects": {},
								"description": "Format of the data (STRING,DOUBLE,BOOLEAN,INTEGER)",
								"baseType": "STRING",
								"ordinal": 2
							},
							"opType": {
								"name": "opType",
								"aspects": {},
								"description": "Behavior of the data (CONTINUOUS,CATEGORICAL,ORDINAL,BOOLEAN,TEMPORAL,ENTITY_ID)",
								"baseType": "STRING",
								"ordinal": 3
							},
							"values": {
								"name": "values",
								"aspects": {
									"dataShape": "GenericStringList"
								},
								"description": "Collection of possible values for Ordinal and Categorical fields",
								"baseType": "INFOTABLE",
								"ordinal": 6
							}
						},
						"name": "AnalyticsDatasetMetadata",
						"description": "Metadata describing the fields of a dataset"
					},
					"rows": [{
							"isStatic": false,
							"fieldName": "asset_id",
							"dataType": "STRING",
							"opType": "ENTITY_ID",
							"values": {
								"created": 1521639563486,
								"description": "",
								"name": "Infotable",
								"dataShape": {
									"fieldDefinitions": {
										"item": {
											"name": "item",
											"aspects": {
												"isPrimaryKey": true
											},
											"description": "Item",
											"baseType": "STRING",
											"ordinal": 0
										}
									},
									"name": "GenericStringList",
									"description": "Generic data shape to hold a list of strings"
								},
								"rows": [{
										"item": "test"
									}, {
										"item": "test"
									}, {
										"item": "test"
									}, {
										"item": "test"
									}, {
										"item": "test"
									}, {
										"item": "test"
									}, {
										"item": "test"
									}, {
										"item": "test"
									}
								]
							}
						}, {
							"isStatic": false,
							"fieldName": "A",
							"dataType": "DOUBLE",
							"opType": "CONTINUOUS",
							"values": {
								"created": 1521639564074,
								"description": "",
								"name": "Infotable",
								"dataShape": {
									"fieldDefinitions": {
										"item": {
											"name": "item",
											"aspects": {
												"isPrimaryKey": true
											},
											"description": "Item",
											"baseType": "STRING",
											"ordinal": 0
										}
									},
									"name": "GenericStringList",
									"description": "Generic data shape to hold a list of strings"
								},
								"rows": [{
										"item": "1"
									}, {
										"item": "3"
									}, {
										"item": "5"
									}, {
										"item": "7"
									}, {
										"item": "9"
									}, {
										"item": "11"
									}, {
										"item": "13"
									}, {
										"item": "15"
									}
								]
							}
						}, {
							"isStatic": false,
							"fieldName": "B",
							"dataType": "DOUBLE",
							"opType": "CONTINUOUS",
							"values": {
								"created": 1521639564675,
								"description": "",
								"name": "Infotable",
								"dataShape": {
									"fieldDefinitions": {
										"item": {
											"name": "item",
											"aspects": {
												"isPrimaryKey": true
											},
											"description": "Item",
											"baseType": "STRING",
											"ordinal": 0
										}
									},
									"name": "GenericStringList",
									"description": "Generic data shape to hold a list of strings"
								},
								"rows": [{
										"item": "1"
									}, {
										"item": "3"
									}, {
										"item": "5"
									}, {
										"item": "7"
									}, {
										"item": "9"
									}, {
										"item": "11"
									}, {
										"item": "13"
									}, {
										"item": "15"
									}
								]
							}
						}, {
							"isStatic": false,
							"fieldName": "C",
							"dataType": "DOUBLE",
							"opType": "CONTINUOUS",
							"values": {
								"created": 1521639566311,
								"description": "",
								"name": "Infotable",
								"dataShape": {
									"fieldDefinitions": {
										"item": {
											"name": "item",
											"aspects": {
												"isPrimaryKey": true
											},
											"description": "Item",
											"baseType": "STRING",
											"ordinal": 0
										}
									},
									"name": "GenericStringList",
									"description": "Generic data shape to hold a list of strings"
								},
								"rows": [{
										"item": "1"
									}, {
										"item": "2"
									}, {
										"item": "3"
									}, {
										"item": "4"
									}, {
										"item": "5"
									}, {
										"item": "6"
									}, {
										"item": "7"
									}, {
										"item": "8"
									}
								]
							}
						}, {
							"timeSamplingInterval": 1,
							"isStatic": false,
							"fieldName": "time",
							"dataType": "DOUBLE",
							"opType": "TEMPORAL",
							"values": {
								"created": 1521640129762,
								"description": "",
								"name": "Infotable",
								"dataShape": {
									"fieldDefinitions": {
										"item": {
											"name": "item",
											"aspects": {
												"isPrimaryKey": true
											},
											"description": "Item",
											"baseType": "STRING",
											"ordinal": 0
										}
									},
									"name": "GenericStringList",
									"description": "Generic data shape to hold a list of strings"
								},
								"rows": [{
										"item": "1"
									}, {
										"item": "2"
									}, {
										"item": "3"
									}, {
										"item": "4"
									}, {
										"item": "5"
									}, {
										"item": "6"
									}, {
										"item": "7"
									}, {
										"item": "8"
									}
								]
							}
						}, {
							"isStatic": false,
							"fieldName": "failure",
							"dataType": "BOOLEAN",
							"opType": "BOOLEAN",
							"values": {
								"created": 1521641692805,
								"description": "",
								"name": "Infotable",
								"dataShape": {
									"fieldDefinitions": {
										"item": {
											"name": "item",
											"aspects": {
												"isPrimaryKey": true
											},
											"description": "Item",
											"baseType": "STRING",
											"ordinal": 0
										}
									},
									"name": "GenericStringList",
									"description": "Generic data shape to hold a list of strings"
								},
								"rows": [{
										"item": "0"
									}, {
										"item": "0"
									}, {
										"item": "0"
									}, {
										"item": "0"
									}, {
										"item": "0"
									}, {
										"item": "0"
									}, {
										"item": "0"
									}, {
										"item": "0"
									}
								]
							}
						}
					]
				},
				"format": "json",
				"exclusions": {
					"created": 1521639557815,
					"description": "",
					"name": "Infotable",
					"dataShape": {
						"fieldDefinitions": {
							"item": {
								"name": "item",
								"aspects": {
									"isPrimaryKey": true
								},
								"description": "Item",
								"baseType": "STRING",
								"ordinal": 0
							}
						},
						"name": "GenericStringList",
						"description": "Generic data shape to hold a list of strings"
					},
					"rows": []
				}
			}
		]
	},
	"goalField": "ttf",
	"preferredCategoricalValues": {
		"created": 1521639099684,
		"description": "",
		"name": "Infotable",
		"dataShape": {
			"fieldDefinitions": {
				"item": {
					"name": "item",
					"aspects": {
						"isPrimaryKey": true
					},
					"description": "Item",
					"baseType": "STRING",
					"ordinal": 0
				}
			},
			"name": "GenericStringList",
			"description": "Generic data shape to hold a list of strings"
		},
		"rows": []
	}
}
1 ACCEPTED SOLUTION

Accepted Solutions
cmorfin
19-Tanzanite
(To:cmorfin)

Hi

 

Apologies for late answer.

I have written an article that covers how to score data from the body of a REST call. It is available at https://www.ptc.com/en/support/article?n=CS282398 .
It does contains a sample dataset and scoring json request which is probably the most useful part of the article.

I believe you can use this to amend your rest call.

 

Note when scoring time series , you do need to pass an amount of data that is at least equal to the Lookback window of your model (see https://support.ptc.com/help/thingworx_hc/thingworx_analytics_8/#page/thingworx_analytics_8%2Ftwxa-time-series.html).

These values need to be passed in the data field not the metadata one.

 

hope this helps

Christophe

 

View solution in original post

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

Hi

 

Just to let you know I am checking on this ... no answer as yet but  I will post as soon as I have something useful.

 

Thank you

Kind regards

Christophe

 

cmorfin
19-Tanzanite
(To:cmorfin)

Hi

 

Apologies for late answer.

I have written an article that covers how to score data from the body of a REST call. It is available at https://www.ptc.com/en/support/article?n=CS282398 .
It does contains a sample dataset and scoring json request which is probably the most useful part of the article.

I believe you can use this to amend your rest call.

 

Note when scoring time series , you do need to pass an amount of data that is at least equal to the Lookback window of your model (see https://support.ptc.com/help/thingworx_hc/thingworx_analytics_8/#page/thingworx_analytics_8%2Ftwxa-time-series.html).

These values need to be passed in the data field not the metadata one.

 

hope this helps

Christophe

 

Top Tags