Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X
Use the Statistical Calculation Thing Shape to Execute Common Statistical Functions
This project will introduce the Statistical Calculation Thing Shape.
The steps in this guide outline how to utilize Descriptive Analytics in ThingWorx Analytics to perform common mathematical analyses on data sets. You will learn how to use the Statistical Calculation Thing Shape's built-in functionality to calculate the mean, median, mode, and other useful insights.
NOTE: The estimated time to complete this guide is 30 minutes.
Descriptive Analytics enables users to perform on-demand common statistical calculations and enable statistical monitoring. Output from these Services can then easily be added to IoT applications built with the ThingWorx platform.
For example, output generated by Descriptive Analytics can be used to build solution-specific visualizations (Mashups or Widgets), create Alerts based on logged Property values, or generate transformed data for machine learning processes.
Descriptive Analytics includes two microservers, each with its own set of statistical Services. This guide will deal specifically with the Statistical Calculation Thing Shape.
This Thing Shape will add a variety of built-in Services to any Thing or Thing Template you choose, such as calculations for Mean, Median, Mode, or Standard Deviation.
To perform these statistical calculations, a Property must have time-series data logged to a Value Stream.
In addition, the Statistical Calculation Thing Shape has been optimized to perform calculations only on particular time ranges and with a maximum entry-count. This helps minimize some of the performance hits that can occur from repeatedly accessing Value Streams.
You perform this "data grooming" via the QueryTimedValuesForProperty Service, which is also part of the Statistical Calculation Thing Shape.
In addition to the name of a Property with values logged to a Value Stream, you also provide a Start Date, End Date, and Max Item Count.
The QueryTimedValuesForProperty Service then formats the values from the Value Stream to work with for the other built-in statistical calculation Services.
The inputs to the built-in Services of the Statistical Calculation Thing Shape require time-series data stored in a Value Stream. Setting a Thing's Properties to be Logged will store valid time-series data on which to perform Descriptive Analytics.
Follow the steps below to create a Value Stream that you will later tie to a Thing.
You will need a Data Shape to format the timed_values Property we will create in the next step.
Next, you will create a Thing and tie the previously-created Value Stream to it.
You will assign the Statistical Calculation Thing Shape to get a variety of built-in analytics Services to manipulate the data. You will also create a series of Properties to facilitate the new Services.
Next, you will add a series of Properties to scts_thing.
Perform the following steps repeatedly until all Properties have been added.
Repeat steps 3-7 until all of the properties in the table below have been added.
NOTE: For the final standarddev_result Property, do NOT click Done and Add; you'll just click the check for Done instead.
Property Name | Base Type | Data Shape | Persistent | Logged |
start_time | DATETIME | N/A | Checked | NOT checked |
end_time | DATETIME | N/A | Checked | NOT checked |
timed_values | INFOTABLE | scts_timed_values_datashape | Checked | NOT checked |
mean_result | NUMBER | N/A | Checked | NOT checked |
median_result | NUMBER | N/A | Checked | NOT checked |
mode_result | INFOTABLE | none, i.e. leave it blank | Checked | NOT checked |
standarddev_result | NUMBER | N/A | Checked | NOT checked |
You will now set the properties to guarantee that each calculation gives us a different answer.
Mean is the average. Median is the "middle" number from the dataset. Mode is the most common number. Standard Deviation is a measure of the "dispersion" of the dataset.
You will use the following dataset: 1, 5, 9, 5, 9, 1, 9.
The mean is 39 / 7 = 5.571...
The median is 5, as 5 is the middle of 1, 5, and 9.
Mode is 9, because 9 appears most commonly in the dataset.
Standard Deviation is 3.5989...
Perform the following steps to enter the above values into the numbers property.
Repeat steps 1-4 above, changing the value each time according to the table below:
Value Change Count | Entered Value |
2nd | 5 |
3rd | 9 |
4th | 5 |
5th | 9 |
6th | 1 |
7th | 9 |
You also need to set the start_time and end_time. These are dates used to define the time-period in which the Statistical Calculation Thing Shape will search for values.
For instance, you could set the calculations to run at midnight, and then use the past 24-hours as your time-period.
For this example, set dates to be 24 hours prior to the time at which you set the above values of the numbers property, through 24 hours in the future.
Click here to view Part 2 of this guide.