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

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

Methods for Data Storage Part 1

No ratings

 

 

Explore the Value Stream, Stream, Data Table, and Info Table storage methods.

 

 

GUIDE CONCEPT

 

This guide will introduce Values Streams, Streams, Data Tables, and Info Tables.

 

Value Streams and Streams are methods of storage for time-series data, while Data Tables and Info Tables are methods of storage for non-time-series data.

 

You will learn how to create and utilize these mass data storage methods.

 

YOU'LL LEARN HOW TO

 

  • Differentiate between data storage methods
  • Create a Data Shape to format a Stream, Data Table, and Info Table
  • Create a Value Stream and Stream to store Time-Series Data
  • Create a Data Table and Info Table to store non-Time-Series Data
  • Use built-in methods to log data to a Value Stream or Info Table
  • Create custom Services which log data to a Stream or Data Table
  • Confirm data storage value changes via a built-in Service or Grid Widget

 

NOTE The estimated time to complete this guide is 60 minutes.

 

 

Step 1: Choosing Storage

 

If your data is largely composed of current values of remote IoT devices (and historical values are unimportant), then the simplest solution is most likely to store them as Properties of Things.

 

However, as opposed to instantaneous current values, there is also “mass data”. Mass data can include large datasets composed of historical records or spreadsheet-like grids.

 

Properties (at least by themselves) aren’t really appropriate in that case, as they typically only store the most recent value.

 

When it comes to mass data, different storage methods are good for different types.

 

At an extremely high level, ThingWorx divides mass data into roughly two categories:

  • Time-Series - The Timestamp of the data is one of the most important elements.
  • Non-Time-Series - The Timestamp of data changes is relatively insignificant.

 

In addition, ThingWorx also subdivides these two categories into either 1) tied to a Thing or 2) independent of any one Thing. Mass data storage that is tied to a Thing will logically only accept information from that one Thing, while independent storage may be used to aggregate information from many Things into a single location.

 

 Storage Solution      Time-Series        Tied to a single Thing
Value StreamsYESYES
StreamsYESNO
Data TablesNONO
Info TablesNOYES

 

The following pages will address these storage types in-depth.

 

 

Step 2: Value Streams

 

In this step, we'll create a Value Stream to be used as a storage location.

 

Value Streams by themselves do nothing. Instead, they must be tied to a Thing.

 

Create Value Stream

  1. On the ThingWorx Composer Browse tab, click Data Storage > Value Streams, + New.
     

    Data1.png

  2. In the Choose Template pop-up, select ValueSteam and click OK.

    Data2.png
     
  3. In the Name field, enter Test_Value_Stream

    Data3.png.
  4. If Project is not already set, search for and select PTCDefaultProject.

  5. At the top, click Save.

Create Thing

Since Value Streams must be tied to a Thing, we'll create one now and then attach the previously-created Value Stream.

  1. On the ThingWorx Composer Browse tab, click MODELING > Things, + New
    .Data4.png
     
  2. In the Name field, enter Value_Stream_Test_Thing.

  3. If Project is not already set, search for and select PTCDefaultProject.

  4. In the Thing Template field, search for and select GenericThing.

  5. In the Value Stream field, search for and select Test_Value_Stream.

    Data5.png
     
  6. At the top, click Save.

 

Create Property

 

Now that we have a Thing with an attached Value Stream, we'll create a Property of that Thing and set it to be Logged.

 

If a Value Stream is attached to a Thing, value-changes of all Logged Properties will get automatically recorded along with a timestamp.

 

  1. At the top, click Properties and Alerts.

    Data6.png
     
  2. Click + Add.

  3. In the Name field, enter Value_Property.

  4. Change the Base Type to Number.

  5. Check the Persistent checkbox.

    • This causes the value of the Property to persist through system reboots.

  6. Check the Logged checkbox.

    • This causes all value changes to be logged to the attached Value Stream.

      Data7.png

     
  7. At the top-right, click the "Check" button for Done.

  8. At the top, click Save.

Set Property Values

In a real-world application, Property value changes would likely occur through a connection to a remote IoT device.

For simplicity, we'll instead manually change the values.

Because the Property is Logged and there is a connected Value Stream, each change will be recorded and timestamped.

  1. Under the Value column for Value_Property, click the "pencil icon" for Set value of property.

    Data8.png
     
  2. At the top-right in the Set value of property field, enter 1.

    Data9.png
     
  3. At the top-right, click the "Check" button for Done.

  4. Again, click the "pencil icon" for Set value of property.

  5. At the top-right in the Set value of property field, enter 2.

    Data10.png
     
  6. At the top-right, click the "Check" button for Done.

  7. Again, click the "pencil icon" for Set value of property.

  8. At the top-right in the Set value of property field, enter 3.

    Data11.png
     
  9. At the top-right, click the "Check" button for Done.

  10. At the top, click Save.

Retrieve Logged Values

One of the most common ways to retrieve time-series information is with the built-in QueryPropertyHistory Service.

QueryPropertyHistory may be used to retrieve logged value-changes for usage in a different, custom Service which could manipulate the data, as well as in Mashups for Widgets like a Grid or Line Chart.

  1. At the top, click Services.

    Data12.png
     
  2. Expand the Generic section.

    Data13.png
     
  3. Scroll down and find the QueryPropertyHistory Service.

    Data14.png
     
  4. Click the "Play" button for Execute service.

    Data15.png
     
  5. In the bottom-right of the Execute Service: QueryPropertyHistory pop-up, click Execute.

    • Note the previously entered values of 1, 2, and 3, as well as their associated timestamps.

      Data16.png
     
  6. At the bottom-right, click Done.

 

A Value Stream is a simple and easy way to record all time-series changes of a particular Thing Property's values.

 

The QueryPropertyHistory built-in Service may be used both in a custom Service to extract the value changes and Timestamps from a Value Stream, as well as in a Mashup to display how values change over time (in a Line Chart, for instance).

 

 

Click here to view Part 2 of this guide.

 
Version history
Last update:
‎Mar 07, 2023 01:44 PM
Updated by:
Labels (1)
Contributors