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

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

How to get the last result from Data Table

tcoufal
13-Aquamarine

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

ACCEPTED SOLUTION

Accepted Solutions
PaiChung
22-Sapphire I
(To:tcoufal)

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.

View solution in original post

6 REPLIES 6
PaiChung
22-Sapphire I
(To:tcoufal)

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.

tcoufal
13-Aquamarine
(To:PaiChung)

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

PaiChung
22-Sapphire I
(To:tcoufal)

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

tcoufal
13-Aquamarine
(To:PaiChung)

Thanks, that have done it :)

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.

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

Thanks anyway.

Tomas

Announcements


Top Tags