Skip to main content
1-Visitor
Jan 28, 2016 1:56 PM UTC
Solved

How to get the last result from Data Table

Hi Guys,

I am trying to achieve a trend evaluation. I am receiving my properties from a EMS thing. I am saving those values in DataTable Upon data change (I need to use Datatable because I need to have a full row-by-row control over the results).

I have added few properties like: trendAccCh1, trendSpeedCh1 and so on. These values are type of boolean. Now I would like to change them by comparing the current result and result before (of certain property). Something like that:

If (my.CurrentPropertyValue > my.LastPropertyValue) {my.Trend = false}

else my.Trend = true

my.CurrentProperty would be the last record in DataTable nad my.LastProperty would be the result before that. Does anyone have a clue how to achieve this?

How to easily access last result and result before that?

Or any other best-practice when it comes to trend evaluation.

Thanks

PaiChungAnswer
22-Sapphire I
Jan 28, 2016 5:04 PM UTC

The easiest way would be to use the Property's DataChange event, Thingworx DataChange event provides new and old VTQ so new value, time and quality plus old value, time and quality.

With your use of a DataTable, I'm not quite sure, you may have to retrieve the data, sort it and grab the previous record. Sounds rather complicated to do.

6 replies

PaiChung22-Sapphire IAnswer
22-Sapphire I
Jan 28, 2016 5:04 PM UTC

The easiest way would be to use the Property's DataChange event, Thingworx DataChange event provides new and old VTQ so new value, time and quality plus old value, time and quality.

With your use of a DataTable, I'm not quite sure, you may have to retrieve the data, sort it and grab the previous record. Sounds rather complicated to do.

Translate
tcoufal1-VisitorAuthor
1-Visitor
Jan 29, 2016 9:02 AM UTC

Hi Pai,

I would like to test your suggestion, could you elaborate on that bit more? Shoudl I create an subscription, one for one propety's DataChange event.? What is the name of that service, how can I get the VTQ values. Thanks a lot.

Tomas

Translate
22-Sapphire I
Jan 29, 2016 1:50 PM UTC

Properties have a built-in event called DataChange

When you create a subscription, you select DataChange and then the property you are interested in.

then on the Input/Output tab you'll see eventData which holds the new and old VTQ

Translate
12-Amethyst
Jan 29, 2016 8:08 AM UTC

Did you consider using Streams instead of DataTables? Streams provide full access to the content (not like ValueStreams) but work time-indexed so that you can query a stream more easily for your purpose: just specify maxItems to 1 and it'll return the latest entry. This is performance better as well - if you can't follow Pai's proposal which is even better as it doesn't require any data query.

Translate
tcoufal1-VisitorAuthor
1-Visitor
Jan 29, 2016 9:03 AM UTC

I will try those for a future project, it would be very difficult to do that for this one.

Thanks anyway.

Tomas

Translate