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

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Perform Statistical Calculations with Descriptive Analytics Part 1

No ratings

 

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.

 

  1. On the ThingWorx Composer Browse tab, click DATA STORAGE > Value Streams, + New.

    01-scda-value-streams.png

     

  2. Select ValueStream and click OK.

    02-scda-value-stream-popup.png

     

  3. In the Name field, enter scts_valuestream.
  4. If Project is not already set, search for and select PTCDefaultProject.

    01-scts-value-stream.png

     

  5. At the top, click Save.

    04-scda-value-stream-saved.png

     

Create Data Shape

 

You will need a Data Shape to format the timed_values Property we will create in the next step.

 

  1. On the ThingWorx Composer Browse tab, click MODELING > Data Shapes, + New.

    05-scda-data-shapes.png

     

  2. In the Name field, enter scts_timed_values_datashape.
  3. If Project is not already set, search for and select PTCDefaultProject.

    02-scts-data-shape.png

     

  4. At the top, click Field Definitions.

    07-scda-field-definitions.png

     

  5. Click + Add.
  6. On the right slide-out, in the Name field, enter value.
  7. Change the Base Type to NUMBER.

    08-scda-value-definition.png

     

  8. At the top-right, click the "check with a +" icon for Done and Add.
  9. In the Name field, enter timestamp.
  10. Change the Base Type to LONG.

    09-scda-timestamp-definition.png

     

  11. At the top-right, click the "check" icon for Done.
  12. At the top, click Save.
     

    10-scda-data-shape-save.png

 
 

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.

 

  1. On the ThingWorx Composer Browse tab, click MODELING > Things, + New.

    11-scda-things.png

     

  2. In the Name field, enter scts_thing.
  3. If Project is not already set, search for and select PTCDefaultProject.
  4. In the Base Thing Template field, search for and select GenericThing.
  5. In the Implemented Shapes field, search for and select StatisticalCalculationThingShape.
  6. In the Value Stream field, search for and select scts_valuestream.

    03-scts-thing.png

     

  7. 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.

 

    1. At the top, click Properties and Alerts.

      14-scda-properties.png

       

    2. Click + Add.
    3. On the right slide-out, in the Name field, enter numbers.
    4. Change the Base Type to NUMBER.
    5. Click Persistent.
    6. Click Logged.

      15-scda-numbers-property.png

       

    7. At the top-right, click the "check with a +" icon for Done and Add.
    8. 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 TypeData Shape Persistent  Logged
        start_timeDATETIMEN/ACheckedNOT checked
        end_timeDATETIMEN/ACheckedNOT checked
        timed_valuesINFOTABLEscts_timed_values_datashapeCheckedNOT checked
        mean_resultNUMBERN/ACheckedNOT checked
        median_resultNUMBERN/ACheckedNOT checked
        mode_resultINFOTABLEnone, i.e. leave it blankCheckedNOT checked
        standarddev_resultNUMBERN/ACheckedNOT checked
         

         

        16-scda-more-properties.png

    9. At the top-right, click the "check" icon for DONE.

      17-scda-properties-finalized.png

    10. At the top, click Save.

      18-scda-thing-saved.png

 

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

 

  1. Under the Value column and on the numbers property row, click the "pencil" icon for Set value of property.

    19-scda-set-value-of-property.png

     

  2. On the right slide-out, enter 1.

    20-scda-set-1.png

     

  3. At the top-right, click the "check" icon for Done.
  4. At the top, click Save.

    21-scda-save-1.png

     

  5. Repeat steps 1-4 above, changing the value each time according to the table below:


    Value Change Count Entered Value
    2nd5
    3rd9
    4th5
    5th9
    6th1
    7th9

 

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

 

  1. Under the Value column and on the start_time Property row, click the "pencil" icon for Set value of property.

    22-scda-set-start-time.png

     

  2. On the right slide-out, search for and select the previous day.

    23-scda-set-yesterday.png

     

  3. At the top-right, click the "check" icon for Done.
  4. At the top, click Save.

 

Set end_time

 

  1. Under the Value column and on the end_time property row, click the "pencil" icon for Set value of property.

    24-scda-set-end-time.png

     

  2. On the right slide-out, search for and select the following day.
  3. At the top-right, click the "check" icon for Done.
  4. At the top, click Save.

 

 

Click here to view Part 2 of this guide.

Version history
Last update:
‎Mar 07, 2023 02:29 PM
Updated by:
Labels (2)
Contributors