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

Best practice to store set of XY values

SOLVED
Highlighted
Level 1

Best practice to store set of XY values

Hi,

Every 10 minutes, my sensor uploads a set of XY values, for example: [4,2],[3,1],[2,1]. In this example my sensor uploaded 3 sets in one POST. But the amount of sets that is uploaded is not fixed, it can change in every upload. What is the best approach to store these sets, so that later I can query them, for example, retrieving the sets that were uploaded at an specific time?

InfoTable? if so,  can i create historic data of infotables using a value stream? or shall this be written to a data table? I am confused with these two options.

Thanks a lot in advance

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Best practice to store set of XY values

Luis,

I would store it as a string value in the value stream and then you can just parse to array when you want to use it.

var a = "[[1,2],[3,5]]";  -- would come from string value in value stream

var array = JSON.parse(a);

logger.debug("array length = " + array.length);

logger.debug("Array vAlue 0 = " + array[0]);

logger.debug("Array vAlue 1 = " + array[1]);

4 REPLIES 4

Re: Best practice to store set of XY values

H Luis,

but there are Streams, ValueStreams and DataTables

From the Digital Guide:

A ThingWorx stream is a list of activities from things or data associated with things. Data associated with things includes time series data and event-driven data.

ValueStreams are also like streams, but they will store the data 'flat', because it does it in an automated fashion, while you have to script how to store the information into a regular stream.

Streams also work in an asynchronous way and are more suited for large number of entries.

A ThingWorx data table is similar to a Relational Database (RDBMS) Table. A ThingWorx data shape defines the columns or fields of the data table. To use a data shape to define a data table, at least one of the fields in the data shape must be set as a primary key. This enables the update and delete functionality, as well as efficient querying of data.

DataTables are synchronous and support primary keys and indexing and are more suited for reference/lookup.

So generally anytime you are storing information over time, historical information, think Stream/ValueStream.

If you need a more static reference table, think DataTable.

Based on the above, I would suggest creating a property on your sensor thing that is populated with your XY values and having this automatically stored in a value stream on data change.

Re: Best practice to store set of XY values

Hi Keri,

I have used before value streams and they work good for punctual values like, temperature, light intensity etc.

But my data looks like this:

TimeArray
19:01[[1,2],[3,5]]
19:11[[1,2],[3,5],[1,2],[3,5]]
19:21[[1,2],[1,2],[3,5]]
19:31[[1,2],[1,2],[3,5]]
19:41[[1,2],[1,2],[3,5],[1,2],[1,2],[3,5]]

The problem is that i dont know which data structure to use to store these arrays and how to store its historical information.

Thanks a lot.

Re: Best practice to store set of XY values

Luis,

I would store it as a string value in the value stream and then you can just parse to array when you want to use it.

var a = "[[1,2],[3,5]]";  -- would come from string value in value stream

var array = JSON.parse(a);

logger.debug("array length = " + array.length);

logger.debug("Array vAlue 0 = " + array[0]);

logger.debug("Array vAlue 1 = " + array[1]);

Re: Best practice to store set of XY values

That would work indeed, my last goal it to plot this data in an XY chart.Do you think storing it as a string is a good approach if i want to plot it ?