Use the Statistical Calculation Thing Shape to Execute Common Statistical Functions GUIDE CONCEPT 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. YOU'LL LEARN HOW TO Create a Value Stream and Data Shape Create a Thing with the Statistical Calculation Thing Shape Modify a Property to record values to the Value Stream Utilize various built-in services to perform the Mean, Median, Mode, and Standard Deviation calculations NOTE: The estimated time to complete this guide is 30 minutes. Step 1: Introduction 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. Step 2: Create Prerequisites 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. Create Value Stream Follow the steps below to create a Value Stream that you will later tie to a Thing. On the ThingWorx Composer Browse tab, click DATA STORAGE > Value Streams, + New. Select ValueStream and click OK. In the Name field, enter scts_valuestream. If Project is not already set, search for and select PTCDefaultProject. At the top, click Save. Create Data Shape You will need a Data Shape to format the timed_values Property we will create in the next step. On the ThingWorx Composer Browse tab, click MODELING > Data Shapes, + New. In the Name field, enter scts_timed_values_datashape. If Project is not already set, search for and select PTCDefaultProject. At the top, click Field Definitions. Click + Add. On the right slide-out, in the Name field, enter value. Change the Base Type to NUMBER. At the top-right, click the "check with a +" icon for Done and Add. In the Name field, enter timestamp. Change the Base Type to LONG. At the top-right, click the "check" icon for Done. At the top, click Save. Step 3: Create Thing 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. On the ThingWorx Composer Browse tab, click MODELING > Things, + New. In the Name field, enter scts_thing. If Project is not already set, search for and select PTCDefaultProject. In the Base Thing Template field, search for and select GenericThing. In the Implemented Shapes field, search for and select StatisticalCalculationThingShape. In the Value Stream field, search for and select scts_valuestream. At the top, click Save. Add Properties Next, you will add a series of Properties to scts_thing. Perform the following steps repeatedly until all Properties have been added. At the top, click Properties and Alerts. Click + Add. On the right slide-out, in the Name field, enter numbers. Change the Base Type to NUMBER. Click Persistent. Click Logged. At the top-right, click the "check with a +" icon for Done and Add. 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 At the top-right, click the "check" icon for DONE. At the top, click Save. Step 4: Set Properties 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. Set numbers Under the Value column and on the numbers property row, click the "pencil" icon for Set value of property. On the right slide-out, enter 1. At the top-right, click the "check" icon for Done. At the top, click Save. 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. Set start_time Under the Value column and on the start_time Property row, click the "pencil" icon for Set value of property. On the right slide-out, search for and select the previous day. At the top-right, click the "check" icon for Done. At the top, click Save. Set end_time Under the Value column and on the end_time property row, click the "pencil" icon for Set value of property. On the right slide-out, search for and select the following day. At the top-right, click the "check" icon for Done. At the top, click Save. Click here to view Part 2 of this guide.
View full tip